From 22201ac086b2aa9694ce23722bca038adb3addfd Mon Sep 17 00:00:00 2001 From: suressk Date: Fri, 1 Jul 2022 15:09:07 +0800 Subject: [PATCH] feat: add `uniqArray` func, remove outdate `hasX.ts` file --- array/index.ts | 25 ++++++++++++++++++++++++- hasChanged.ts | 13 ------------- hasOwnProp.ts | 15 --------------- index.ts | 8 +++++--- scripts/tsconfig.json | 2 +- 5 files changed, 30 insertions(+), 33 deletions(-) delete mode 100644 hasChanged.ts delete mode 100644 hasOwnProp.ts diff --git a/array/index.ts b/array/index.ts index 1b4cd3d..c588c6d 100644 --- a/array/index.ts +++ b/array/index.ts @@ -1,3 +1,5 @@ +import { isFunction } from '../is' + /** * Used to remove an item of the array * @@ -11,6 +13,27 @@ export const removeArrayItem = (arr: T[], el: T) => { } } +/** + * Used to remove the mutiple items (shallow uniq) + * + * @param arr need uniq array + */ +export const uniqArray = (arr: T[]) => { + if (!arr || !arr.length) { + return [] + } + if (Set && isFunction(Set)) { + return Array.from(new Set(arr)) + } + // // 兼容方案,暂时未实现 + // const res = [] + // const usedMap = new Map() || {} + // for (const item of arr) { + // } + return arr +} + export default { - removeArrayItem + removeArrayItem, + uniqArray } diff --git a/hasChanged.ts b/hasChanged.ts deleted file mode 100644 index e999944..0000000 --- a/hasChanged.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Check ths value is changed or not - * - * @param value the new value - * @param oldValue the old value - * @returns boolean - */ -const hasChanged = ( - value: any, - oldValue: any -): boolean => !Object.is(value, oldValue) - -export default hasChanged \ No newline at end of file diff --git a/hasOwnProp.ts b/hasOwnProp.ts deleted file mode 100644 index 84acf41..0000000 --- a/hasOwnProp.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { hasOwnProperty } from './.internal/staticFucs' - -/** - * Check the key is the val own property - * - * @param {object} val the check value - * @param {string | symbol} key the check key - * @returns boolean - */ -const hasOwnProp = ( - val: object, - key: string | symbol -): key is keyof typeof val => hasOwnProperty.call(val, key) - -export default hasOwnProp diff --git a/index.ts b/index.ts index 3704a7e..daed46b 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,5 @@ /* Array funcs */ -import { removeArrayItem } from './array' +import { removeArrayItem, uniqArray } from './array' // is funcs import { @@ -45,7 +45,8 @@ export { hasChanged, getPrototype, debounce, - removeArrayItem + removeArrayItem, + uniqArray } export default { @@ -68,5 +69,6 @@ export default { debounce, - removeArrayItem + removeArrayItem, + uniqArray } diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 3c25c19..e9cb3c8 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -1,5 +1,5 @@ { - "$schema": "https://json.schemastore.org/tsconfig", + // "$schema": "https://json.schemastore.org/tsconfig", "include": ["."], "compilerOptions": { "module": "CommonJS",