diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index fbc9d0d0b..d490a7cc4 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -1,12 +1,4 @@ -import deepmerge from 'deepmerge'; - -const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray; - -export function merge(obj1: any, obj2: any) { - return deepmerge(obj1, obj2, { - arrayMerge: overwriteMerge, - }); -} - +export * from './merge'; export * from './mixin'; export * from './mixin/AsyncEmitter'; +export * from './uid'; diff --git a/packages/utils/src/merge.ts b/packages/utils/src/merge.ts new file mode 100644 index 000000000..1fc8a3358 --- /dev/null +++ b/packages/utils/src/merge.ts @@ -0,0 +1,9 @@ +import deepmerge from 'deepmerge'; + +const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray; + +export function merge(obj1: any, obj2: any) { + return deepmerge(obj1, obj2, { + arrayMerge: overwriteMerge, + }); +} diff --git a/packages/utils/src/uid.ts b/packages/utils/src/uid.ts new file mode 100644 index 000000000..e3e576fe6 --- /dev/null +++ b/packages/utils/src/uid.ts @@ -0,0 +1,10 @@ +let IDX = 36, + HEX = ''; +while (IDX--) HEX += IDX.toString(36); + +export function uid(len?: number) { + let str = '', + num = len || 11; + while (num--) str += HEX[(Math.random() * 36) | 0]; + return str; +}