From 7fccd43afe61b38f47496787587fdb1e25e832b9 Mon Sep 17 00:00:00 2001 From: Simon Reinisch Date: Wed, 1 May 2024 15:04:19 +0200 Subject: [PATCH] refactor: move remove utility into array module --- src/app/components/charts/echart/EChart.vue | 4 +--- src/utils/array.ts | 8 ++++++++ src/utils/index.ts | 3 ++- src/utils/remove.ts | 4 ---- 4 files changed, 11 insertions(+), 8 deletions(-) delete mode 100644 src/utils/remove.ts diff --git a/src/app/components/charts/echart/EChart.vue b/src/app/components/charts/echart/EChart.vue index e13f466d..d8f71c45 100644 --- a/src/app/components/charts/echart/EChart.vue +++ b/src/app/components/charts/echart/EChart.vue @@ -7,9 +7,7 @@ import * as echarts from 'echarts/core'; import { EChartsType } from 'echarts/core'; import { computed, onMounted, onUnmounted, ref, shallowRef, watch } from 'vue'; import { useResizeObserver } from '@composables'; -import { ClassNames } from '@utils'; -import { getCssVariables } from '../../../../utils/cssVariables'; -import { svgToPNG } from '../../../../utils/svgToPNG'; +import { ClassNames, getCssVariables, svgToPNG } from '@utils'; /* eslint-disable @typescript-eslint/no-explicit-any */ const props = defineProps<{ diff --git a/src/utils/array.ts b/src/utils/array.ts index 8382548b..d24699d9 100644 --- a/src/utils/array.ts +++ b/src/utils/array.ts @@ -6,6 +6,14 @@ export const add = (...arrays: readonly number[][]) => { return sum; }; +export const remove = (t: T[], v: T | ((v: T) => boolean)): void => { + const index = typeof v === 'function' ? t.findIndex((tv) => (v as (v: T) => boolean)(tv)) : t.indexOf(v); + + if (index !== -1) { + t.splice(index, 1); + } +}; + export const sum = (values: readonly number[]) => values.reduce((a, b) => a + b, 0); export const average = (values: readonly number[]) => sum(values) / values.length; diff --git a/src/utils/index.ts b/src/utils/index.ts index 7cfa6651..3f2ca12c 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -2,8 +2,9 @@ export * from './array'; export * from './debounce'; export * from './logger'; export * from './readFile'; -export * from './remove'; export * from './downloadFile'; export * from './selectFile'; export * from './types'; export * from './uuid'; +export * from './svgToPNG'; +export * from './cssVariables'; diff --git a/src/utils/remove.ts b/src/utils/remove.ts deleted file mode 100644 index f0785a36..00000000 --- a/src/utils/remove.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const remove = (t: T[], v: T | ((v: T) => boolean)): void => { - const index = typeof v === 'function' ? t.findIndex((tv) => (v as (v: T) => boolean)(tv)) : t.indexOf(v); - ~index && t.splice(index, 1); -};