1 line
23 KiB
Plaintext
1 line
23 KiB
Plaintext
|
|
{"version":3,"file":"index.mjs","sources":["../src/constants.ts","../src/utils/check.ts","../src/utils/array.ts","../src/utils/clone.ts","../src/utils/object.ts","../src/utils/options.ts","../src/module.ts","../src/presets.ts"],"sourcesContent":["export enum PriorityName {\n LEFT = 'left',\n RIGHT = 'right',\n}\n","export function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n\nexport function isSafeKey(key: string) : boolean {\n return key !== '__proto__' &&\n key !== 'prototype' &&\n key !== 'constructor';\n}\n\nexport function isEqual(x: any, y: any): boolean {\n if (Object.is(x, y)) return true;\n\n if (x instanceof Date && y instanceof Date) {\n return x.getTime() === y.getTime();\n }\n\n if (x instanceof RegExp && y instanceof RegExp) {\n return x.toString() === y.toString();\n }\n\n if (\n isObject(x) &&\n isObject(y)\n ) {\n const keysX = Reflect.ownKeys(x) as string[];\n const keysY = Reflect.ownKeys(y) as string[];\n if (keysX.length !== keysY.length) {\n return false;\n }\n\n for (let i = 0; i < keysX.length; i++) {\n const key = keysX[i];\n if (!Reflect.has(y, key) || !isEqual(x[key], y[key])) {\n return false;\n }\n }\n\n return true;\n }\n\n if (\n Array.isArray(x) &&\n Array.isArray(y)\n ) {\n if (x.length !== y.length) {\n return false;\n }\n\n for (let i = 0; i < x.length; i++) {\n if (!isEqual(x[i], y[i])) {\n return false;\n }\n }\n\n return true;\n }\n\n return false;\n}\n","import { isEqual } from './check';\n\nexport function distinctArray<T = any>(arr: T[]) : T[] {\n for (let i = 0; i < arr.length; i++) {\n for (let j = arr.length - 1; j > i; j--) {\n if (isEqual(arr[i], arr[j])) {\n arr.splice(j, 1);\n }\n }\n }\n\n return arr;\n}\n","import { isObject } from './check';\n\n/* istanbul ignore next */\nconst gT = (() => {\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n\n // eslint-disable-next-line no-restricted-globals\n if (typeof self !== 'undefined') {\n // eslint-disable-next-line no-restricted-globals\n return self;\n }\n\n if (typeof window !== 'undefined') {\n return window;\n }\n\n if (typeof global !== 'undefined') {\n return global;\n }\n\n throw new Error('unable to locate global object');\n})();\n\nexport function polyfillClone<T>(input: T) {\n const map = new WeakMap();\n\n const fn = <A>(value: A) : A => {\n if (Array.isArray(value)) {\n if (map.has(value)) {\n return map.get(value);\n }\n\n const cloned = [] as A;\n map.set(value, cloned);\n\n value.map((el) => (cloned as any[]).push(fn(el)));\n\n return cloned;\n }\n\n if (isObject(value)) {\n if (map.has(value)) {\n return map.get(value);\n }\n\n const output = {} as A;\n const keys = Object.keys(value);\n\n map.set(value, output);\n for (let i = 0; i < keys.length; i++) {\n output[keys[i] as keyof A] = fn(value[keys[i]]);\n }\n\n return output;\n }\n\n return value;\n };\n\n return fn(input);\n}\n\n/* istanbul ignore next */\nexport function clone<T>(value: T) : T {\n if (gT.structuredClone) {\n return gT.structuredClone(value);\n }\n\n /* istanbul ignore next */\n return polyfillClone(value);\n}\n","// eslint-disable-next-line @typescript-eslint/ban-types\nexport function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.cal
|