@r01al/array-polyfills 1.0.5 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +484 -2
- package/dist/auto.cjs +262 -0
- package/dist/auto.cjs.map +1 -1
- package/dist/auto.mjs +262 -0
- package/dist/auto.mjs.map +1 -1
- package/dist/auto.umd.js +530 -0
- package/dist/auto.umd.js.map +1 -0
- package/dist/functions/compact.d.ts +7 -0
- package/dist/functions/compact.js +7 -0
- package/dist/functions/compactMap.d.ts +6 -0
- package/dist/functions/compactMap.js +15 -0
- package/dist/functions/countBy.d.ts +6 -0
- package/dist/functions/countBy.js +17 -0
- package/dist/functions/difference.d.ts +6 -0
- package/dist/functions/difference.js +15 -0
- package/dist/functions/flatten.d.ts +5 -0
- package/dist/functions/flatten.js +14 -0
- package/dist/functions/groupBy.d.ts +6 -0
- package/dist/functions/groupBy.js +19 -0
- package/dist/functions/intersection.d.ts +6 -0
- package/dist/functions/intersection.js +11 -0
- package/dist/functions/pad.d.ts +7 -0
- package/dist/functions/pad.js +15 -0
- package/dist/functions/partition.d.ts +6 -0
- package/dist/functions/partition.js +17 -0
- package/dist/functions/pluck.d.ts +6 -0
- package/dist/functions/pluck.js +8 -0
- package/dist/functions/sample.d.ts +6 -0
- package/dist/functions/sample.js +16 -0
- package/dist/functions/sortBy.d.ts +6 -0
- package/dist/functions/sortBy.js +20 -0
- package/dist/functions/union.d.ts +6 -0
- package/dist/functions/union.js +22 -0
- package/dist/functions/uniqBy.d.ts +6 -0
- package/dist/functions/uniqBy.js +21 -0
- package/dist/functions/zip.d.ts +6 -0
- package/dist/functions/zip.js +15 -0
- package/dist/index.cjs +289 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +30 -0
- package/dist/index.js +42 -11
- package/dist/index.mjs +275 -12
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +580 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/polyfills/array.d.ts +15 -0
- package/dist/polyfills/array.js +30 -0
- package/package.json +2 -1
package/dist/auto.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto.mjs","sources":["../src/functions/chunk.ts","../src/functions/first.ts","../src/functions/last.ts","../src/functions/random.ts","../src/functions/unique.ts","../src/functions/keyValueMap.ts","../src/functions/sum.ts","../src/functions/avg.ts","../src/functions/max.ts","../src/functions/min.ts","../src/functions/shuffle.ts","../src/polyfills/array.ts"],"sourcesContent":["/**\n* Splits the array into smaller arrays of the given size.\n* @param size Number of items per chunk\n* @returns Array of chunks\n*/\n\nexport default function <T>(this: T[], size: number) {\n\tif (!Number.isInteger(size) || size <= 0) throw new Error(\"size must be a positive integer\");\n\tconst out: T[][] = [];\n\tfor (let i = 0; i < this.length; i += size) out.push(this.slice(i, i + size));\n\treturn out;\n}","/**\n* @returns the first element of the array, or undefined if the array is empty.\n*/\nexport default function <T>(this: T[]) { return this.length ? this[0] : undefined; }","/**\n* @returns the last element of the array, or undefined if the array is empty.\n*/\nexport default function <T>(this: T[]) { return this.length ? this[this.length - 1] : undefined; }","/**\n * @returns a random element from the array, or undefined if the array is empty.\n */\nexport default function <T>(this: T[]) {\n\treturn this.length ? this[Math.floor(Math.random() * this.length)] : undefined;\n}","/**\n * @returns a new array with only unique elements from the original array.\n * Supports deep comparison for objects.\n * Uses a map for improved performance with primitives.\n */\nfunction deepEqual(a: any, b: any): boolean {\n if (a === b) return true;\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n const keysA = Object.keys(a), keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n for (const key of keysA) {\n if (!keysB.includes(key) || !deepEqual(a[key], b[key])) return false;\n }\n return true;\n}\n\nexport default function <T>(this: T[]): T[] {\n const result: T[] = [];\n const primitiveMap = new Map<any, boolean>();\n\n for (const item of this) {\n if (item === null || typeof item !== \"object\") {\n if (!primitiveMap.has(item)) {\n primitiveMap.set(item, true);\n result.push(item);\n }\n } else {\n if (!result.some(existing => deepEqual(existing, item))) {\n result.push(item);\n }\n }\n }\n return result;\n}","/**\n * Creates an object mapping each value of the given key to the corresponding value from the array of objects.\n * @param key The property name to use as keys in the result object.\n * @param value The property name to use as values in the result object.\n * @returns An object mapping key values to value values.\n */\nexport default function (this: KeyValueMap[], key: string, value: string) {\n\tif (!key) {\n\t\tthrow new Error('keyValueMap: key is required');\n\t}\n\n\tif (!value) {\n\t\tthrow new Error(\"keyValueMap: value is required\");\n\t}\n\n\tif (this.some(el => !el)) {\n\t\tthrow new Error('keyValueMap: Array contains falsy values');\n\t}\n\n\tif (this.some(el => typeof el !== 'object')) {\n\t\tthrow new Error('keyValueMap: Array contains non-object values');\n\t}\n\n\tif (this.some(el => !el.hasOwnProperty(key))) {\n\t\tthrow new Error(`keyValueMap: key \"${key}\" does not exist on all objects`);\n\t}\n\n\tvar map : KeyValueMap = {};\n\n\tfor (let index = 0; index < this.length; index++) {\n\t\tvar element: KeyValueMap = this[index];\n\n\t\tmap[element[key]] = element[value];\n\t}\n\t\n\treturn map;\n}","/**\n * Calculates the sum of all numbers in an array.\n * @returns The sum of all numbers in the array.\n * @throws Will throw an error if any element in the array is not a number.\n * @example\n * [1, 2, 3].sum() // returns 6\n * [10, -2, 5].sum() // returns 13\n * [1, '2', 3].sum() // throws Error\n */\n\nexport default function <T>(this: T[]) { \n if (this.some(el => typeof el !== 'number')) {\n throw new Error('All elements must be numbers');\n }\n\n let sum = 0;\n\n for (const num of this as unknown as number[]) {\n sum += num;\n }\n\n return sum\n}","/**\n * Calculates the average of all numbers in an array.\n * @returns The average value.\n * @throws If any element is not a number.\n */\nexport default function(this: number[]) {\n if (this.length === 0) return undefined;\n if (this.some(el => typeof el !== 'number')) {\n throw new Error('All elements must be numbers');\n }\n return this.reduce((a, b) => a + b, 0) / this.length;\n}","/**\n * Returns the maximum number in the array.\n * @returns The maximum value.\n * @throws If any element is not a number.\n */\nexport default function(this: number[]) {\n if (this.length === 0) return undefined;\n if (this.some(el => typeof el !== 'number')) {\n throw new Error('All elements must be numbers');\n }\n return Math.max(...this);\n}","/**\n * Returns the minimum number in the array.\n * @returns The minimum value.\n * @throws If any element is not a number.\n */\nexport default function(this: number[]) {\n if (this.length === 0) return undefined;\n if (this.some(el => typeof el !== 'number')) {\n throw new Error('All elements must be numbers');\n }\n return Math.min(...this);\n}","export default function shuffle<T>(this: T[]): T[] {\n for (let i = this.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [this[i], this[j]] = [this[j], this[i]];\n }\n \n return this;\n}","import chunk from \"../functions/chunk\";\nimport first from \"../functions/first\";\nimport last from \"../functions/last\";\nimport random from \"../functions/random\";\nimport unique from \"../functions/unique\";\nimport keyValueMap from \"../functions/keyValueMap\";\nimport sum from \"../functions/sum\";\nimport avg from \"../functions/avg\";\nimport max from \"../functions/max\";\nimport min from \"../functions/min\";\nimport shuffle from \"../functions/shuffle\";\n\ndeclare global {\n\tinterface Array<T> {\n\t\tfirst(): T | undefined;\n\t\tlast(): T | undefined;\n\t\tunique(): T[];\n\t\tchunk(size: number): T[][];\n\t\trandom(): T | undefined;\n\t\tkeyValueMap(key: string, value: string): Record<string, any>[];\n\t\tsum(this: number[]): number;\n\t\tavg(this: number[]): number | undefined;\n\t\tmax(this: number[]): number | undefined;\n\t\tmin(this: number[]): number | undefined;\n\t\tshuffle(): T[];\t\n\t}\n}\n\nfunction defineArrayMethod (name: string, fn: Function) {\n\tif (!(Array.prototype as any)[name]) {\n\t\tObject.defineProperty(Array.prototype, name, {\n\t\t\tvalue: fn,\n\t\t\twritable: false,\n\t\t\tconfigurable: false\n\t\t});\n\t}\n}\n\ndefineArrayMethod(\"first\", first);\ndefineArrayMethod(\"last\", last);\ndefineArrayMethod(\"unique\", unique);\ndefineArrayMethod(\"chunk\", chunk);\ndefineArrayMethod(\"random\", random);\ndefineArrayMethod(\"keyValueMap\", keyValueMap);\ndefineArrayMethod(\"sum\", sum);\ndefineArrayMethod(\"avg\", avg);\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,CAAC;QAC7C,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3C;AAEA,IAAA,OAAO,IAAI;AACf;;ACqBA,SAAS,iBAAiB,CAAE,IAAY,EAAE,EAAY,EAAA;IACrD,IAAI,CAAE,KAAK,CAAC,SAAiB,CAAC,IAAI,CAAC,EAAE;QACpC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE;AAC5C,YAAA,KAAK,EAAE,EAAE;AACT,YAAA,QAAQ,EAAE,KAAK;AACf,YAAA,YAAY,EAAE;AACd,SAAA,CAAC;IACH;AACD;AAEA,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC;AACjC,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC;AAC/B,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC;AACnC,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC;AACjC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC;AACnC,iBAAiB,CAAC,aAAa,EAAE,WAAW,CAAC;AAC7C,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC;AAC7B,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC;AAC7B,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC;AAC7B,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC;AAC7B,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"auto.mjs","sources":["../src/functions/chunk.ts","../src/functions/first.ts","../src/functions/last.ts","../src/functions/random.ts","../src/functions/unique.ts","../src/functions/compact.ts","../src/functions/compactMap.ts","../src/functions/keyValueMap.ts","../src/functions/sum.ts","../src/functions/avg.ts","../src/functions/max.ts","../src/functions/min.ts","../src/functions/shuffle.ts","../src/functions/groupBy.ts","../src/functions/flatten.ts","../src/functions/zip.ts","../src/functions/partition.ts","../src/functions/pluck.ts","../src/functions/countBy.ts","../src/functions/difference.ts","../src/functions/intersection.ts","../src/functions/union.ts","../src/functions/uniqBy.ts","../src/functions/sortBy.ts","../src/functions/sample.ts","../src/functions/pad.ts","../src/polyfills/array.ts"],"sourcesContent":["/**\n* Splits the array into smaller arrays of the given size.\n* @param size Number of items per chunk\n* @returns Array of chunks\n*/\n\nexport default function <T>(this: T[], size: number) {\n\tif (!Number.isInteger(size) || size <= 0) throw new Error(\"size must be a positive integer\");\n\tconst out: T[][] = [];\n\tfor (let i = 0; i < this.length; i += size) out.push(this.slice(i, i + size));\n\treturn out;\n}","/**\n* @returns the first element of the array, or undefined if the array is empty.\n*/\nexport default function <T>(this: T[]) { return this.length ? this[0] : undefined; }","/**\n* @returns the last element of the array, or undefined if the array is empty.\n*/\nexport default function <T>(this: T[]) { return this.length ? this[this.length - 1] : undefined; }","/**\n * @returns a random element from the array, or undefined if the array is empty.\n */\nexport default function <T>(this: T[]) {\n\treturn this.length ? this[Math.floor(Math.random() * this.length)] : undefined;\n}","/**\n * @returns a new array with only unique elements from the original array.\n * Supports deep comparison for objects.\n * Uses a map for improved performance with primitives.\n */\nfunction deepEqual(a: any, b: any): boolean {\n if (a === b) return true;\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n const keysA = Object.keys(a), keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n for (const key of keysA) {\n if (!keysB.includes(key) || !deepEqual(a[key], b[key])) return false;\n }\n return true;\n}\n\nexport default function <T>(this: T[]): T[] {\n const result: T[] = [];\n const primitiveMap = new Map<any, boolean>();\n\n for (const item of this) {\n if (item === null || typeof item !== \"object\") {\n if (!primitiveMap.has(item)) {\n primitiveMap.set(item, true);\n result.push(item);\n }\n } else {\n if (!result.some(existing => deepEqual(existing, item))) {\n result.push(item);\n }\n }\n }\n return result;\n}","type Falsy = false | 0 | \"\" | null | undefined;\n\n/**\n * Removes falsy values from the array.\n * @returns A new array without falsy values.\n */\nexport default function <T>(this: T[]) {\n\treturn this.filter((value): value is Exclude<T, Falsy> => Boolean(value));\n}\n","/**\n * Maps items and removes null/undefined results.\n * @param mapper Function to map items.\n * @returns A new array of mapped values without null/undefined.\n */\nexport default function <T, R>(\n\tthis: T[],\n\tmapper: (value: T, index: number, arr: T[]) => R\n) {\n\tconst out: Exclude<R, null | undefined>[] = [];\n\n\tfor (let index = 0; index < this.length; index++) {\n\t\tconst value = mapper(this[index], index, this);\n\t\tif (value !== null && value !== undefined) {\n\t\t\tout.push(value as Exclude<R, null | undefined>);\n\t\t}\n\t}\n\n\treturn out;\n}\n","/**\n * Creates an object mapping each value of the given key to the corresponding value from the array of objects.\n * @param key The property name to use as keys in the result object.\n * @param value The property name to use as values in the result object.\n * @returns An object mapping key values to value values.\n */\nexport default function (this: KeyValueMap[], key: string, value: string) {\n\tif (!key) {\n\t\tthrow new Error('keyValueMap: key is required');\n\t}\n\n\tif (!value) {\n\t\tthrow new Error(\"keyValueMap: value is required\");\n\t}\n\n\tif (this.some(el => !el)) {\n\t\tthrow new Error('keyValueMap: Array contains falsy values');\n\t}\n\n\tif (this.some(el => typeof el !== 'object')) {\n\t\tthrow new Error('keyValueMap: Array contains non-object values');\n\t}\n\n\tif (this.some(el => !el.hasOwnProperty(key))) {\n\t\tthrow new Error(`keyValueMap: key \"${key}\" does not exist on all objects`);\n\t}\n\n\tvar map : KeyValueMap = {};\n\n\tfor (let index = 0; index < this.length; index++) {\n\t\tvar element: KeyValueMap = this[index];\n\n\t\tmap[element[key]] = element[value];\n\t}\n\t\n\treturn map;\n}","/**\n * Calculates the sum of all numbers in an array.\n * @returns The sum of all numbers in the array.\n * @throws Will throw an error if any element in the array is not a number.\n * @example\n * [1, 2, 3].sum() // returns 6\n * [10, -2, 5].sum() // returns 13\n * [1, '2', 3].sum() // throws Error\n */\n\nexport default function <T>(this: T[]) { \n if (this.some(el => typeof el !== 'number')) {\n throw new Error('All elements must be numbers');\n }\n\n let sum = 0;\n\n for (const num of this as unknown as number[]) {\n sum += num;\n }\n\n return sum\n}","/**\n * Calculates the average of all numbers in an array.\n * @returns The average value.\n * @throws If any element is not a number.\n */\nexport default function(this: number[]) {\n if (this.length === 0) return undefined;\n if (this.some(el => typeof el !== 'number')) {\n throw new Error('All elements must be numbers');\n }\n return this.reduce((a, b) => a + b, 0) / this.length;\n}","/**\n * Returns the maximum number in the array.\n * @returns The maximum value.\n * @throws If any element is not a number.\n */\nexport default function(this: number[]) {\n if (this.length === 0) return undefined;\n if (this.some(el => typeof el !== 'number')) {\n throw new Error('All elements must be numbers');\n }\n return Math.max(...this);\n}","/**\n * Returns the minimum number in the array.\n * @returns The minimum value.\n * @throws If any element is not a number.\n */\nexport default function(this: number[]) {\n if (this.length === 0) return undefined;\n if (this.some(el => typeof el !== 'number')) {\n throw new Error('All elements must be numbers');\n }\n return Math.min(...this);\n}","export default function shuffle<T>(this: T[]): T[] {\n for (let i = this.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [this[i], this[j]] = [this[j], this[i]];\n }\n \n return this;\n}","/**\n * Groups array items by a key or mapper function.\n * @param key The property name or mapper function to group by.\n * @returns An object where keys are group identifiers and values are arrays of items.\n */\nexport default function <T, K extends PropertyKey>(\n\tthis: T[],\n\tkey: ((item: T, index: number, arr: T[]) => K) | keyof T\n) {\n\tconst result = {} as Record<K, T[]>;\n\tconst getKey = typeof key === \"function\"\n\t\t? key\n\t\t: (item: T) => item[key] as unknown as K;\n\n\tfor (let index = 0; index < this.length; index++) {\n\t\tconst item = this[index];\n\t\tconst groupKey = getKey(item, index, this);\n\t\tif (!result[groupKey]) result[groupKey] = [];\n\t\tresult[groupKey].push(item);\n\t}\n\n\treturn result;\n}\n","/**\n * Flattens the array by one level.\n * @returns A new flattened array.\n */\nexport default function <T>(this: (T | T[])[]) {\n\tconst out: T[] = [];\n\n\tfor (const item of this) {\n\t\tif (Array.isArray(item)) out.push(...item);\n\t\telse out.push(item);\n\t}\n\n\treturn out;\n}\n","/**\n * Zips the array with other arrays.\n * @param arrays Arrays to zip with.\n * @returns An array of tuples, truncated to the shortest length.\n */\nexport default function <T>(this: T[], ...arrays: any[][]) {\n\tif (arrays.length === 0) return this.map(item => [item]);\n\n\tconst minLength = Math.min(this.length, ...arrays.map(arr => arr.length));\n\tconst out: any[][] = [];\n\n\tfor (let index = 0; index < minLength; index++) {\n\t\tout.push([this[index], ...arrays.map(arr => arr[index])]);\n\t}\n\n\treturn out;\n}\n","/**\n * Splits the array into two arrays based on a predicate.\n * @param predicate Function to test each element.\n * @returns A tuple: [items that pass, items that fail].\n */\nexport default function <T>(\n\tthis: T[],\n\tpredicate: (value: T, index: number, arr: T[]) => boolean\n) {\n\tconst pass: T[] = [];\n\tconst fail: T[] = [];\n\n\tfor (let index = 0; index < this.length; index++) {\n\t\tconst item = this[index];\n\t\tif (predicate(item, index, this)) pass.push(item);\n\t\telse fail.push(item);\n\t}\n\n\treturn [pass, fail] as [T[], T[]];\n}\n","/**\n * Plucks a property from each item in the array.\n * @param key Property name to pluck.\n * @returns A new array of property values.\n */\nexport default function <T, K extends keyof T>(this: T[], key: K) {\n\treturn this.map(item => item[key]);\n}\n","/**\n * Counts items by a key or mapper function.\n * @param key The property name or mapper function to count by.\n * @returns An object where keys are group identifiers and values are counts.\n */\nexport default function <T, K extends PropertyKey>(\n\tthis: T[],\n\tkey: ((item: T, index: number, arr: T[]) => K) | keyof T\n) {\n\tconst result = {} as Record<K, number>;\n\tconst getKey = typeof key === \"function\"\n\t\t? key\n\t\t: (item: T) => item[key] as unknown as K;\n\n\tfor (let index = 0; index < this.length; index++) {\n\t\tconst item = this[index];\n\t\tconst groupKey = getKey(item, index, this);\n\t\tresult[groupKey] = (result[groupKey] ?? 0) + 1;\n\t}\n\n\treturn result;\n}\n","/**\n * Returns items that are not present in the other arrays.\n * @param arrays Arrays to exclude.\n * @returns A new array of values not found in other arrays.\n */\nexport default function <T>(this: T[], ...arrays: T[][]) {\n\tif (arrays.length === 0) return this.slice();\n\n\tconst other = new Set<T>();\n\n\tfor (const arr of arrays) {\n\t\tfor (const item of arr) other.add(item);\n\t}\n\n\treturn this.filter(item => !other.has(item));\n}\n","/**\n * Returns items present in all arrays.\n * @param arrays Arrays to intersect with.\n * @returns A new array of items found in every array.\n */\nexport default function <T>(this: T[], ...arrays: T[][]) {\n\tif (arrays.length === 0) return this.slice();\n\n\tconst sets = arrays.map(arr => new Set(arr));\n\n\treturn this.filter(item => sets.every(set => set.has(item)));\n}\n","/**\n * Returns a unique merge of the array and the other arrays.\n * @param arrays Arrays to merge.\n * @returns A new array with unique values.\n */\nexport default function <T>(this: T[], ...arrays: T[][]) {\n\tconst out: T[] = [];\n\tconst seen = new Set<T>();\n\n\tconst push = (item: T) => {\n\t\tif (seen.has(item)) return;\n\t\tseen.add(item);\n\t\tout.push(item);\n\t};\n\n\tfor (const item of this) push(item);\n\tfor (const arr of arrays) {\n\t\tfor (const item of arr) push(item);\n\t}\n\n\treturn out;\n}\n","/**\n * Returns unique items by a key or mapper function.\n * @param key The property name or mapper function to determine uniqueness.\n * @returns A new array with unique items.\n */\nexport default function <T, K>(\n\tthis: T[],\n\tkey: ((item: T, index: number, arr: T[]) => K) | keyof T\n) {\n\tconst result: T[] = [];\n\tconst seen = new Set<unknown>();\n\tconst getKey = typeof key === \"function\"\n\t\t? key\n\t\t: (item: T) => item[key] as unknown as K;\n\n\tfor (let index = 0; index < this.length; index++) {\n\t\tconst item = this[index];\n\t\tconst keyValue = getKey(item, index, this);\n\t\tif (!seen.has(keyValue)) {\n\t\t\tseen.add(keyValue);\n\t\t\tresult.push(item);\n\t\t}\n\t}\n\n\treturn result;\n}\n","/**\n * Sorts items by a key or mapper function (stable).\n * @param key The property name or mapper function to sort by.\n * @returns A new array sorted by the key.\n */\nexport default function <T, K extends string | number | bigint>(\n\tthis: T[],\n\tkey: ((item: T, index: number, arr: T[]) => K) | keyof T\n) {\n\tconst getKey = typeof key === \"function\"\n\t\t? key\n\t\t: (item: T) => item[key] as unknown as K;\n\n\treturn this\n\t\t.map((item, index) => ({ item, index, key: getKey(item, index, this) }))\n\t\t.sort((a, b) => {\n\t\t\tif (a.key < b.key) return -1;\n\t\t\tif (a.key > b.key) return 1;\n\t\t\treturn a.index - b.index;\n\t\t})\n\t\t.map(entry => entry.item);\n}\n","/**\n * Returns a random sample of items without replacement.\n * @param count Number of items to sample.\n * @returns A new array containing sampled items.\n */\nexport default function <T>(this: T[], count: number) {\n\tif (!Number.isInteger(count) || count <= 0) {\n\t\tthrow new Error(\"count must be a positive integer\");\n\t}\n\n\tconst out = this.slice();\n\n\tfor (let i = out.length - 1; i > 0; i--) {\n\t\tconst j = Math.floor(Math.random() * (i + 1));\n\t\t[out[i], out[j]] = [out[j], out[i]];\n\t}\n\n\treturn out.slice(0, Math.min(count, out.length));\n}\n","/**\n * Pads the array to the given length with the provided value.\n * @param length Target length.\n * @param value Value to pad with.\n * @returns A new padded array.\n */\nexport default function <T>(this: T[], length: number, value: T) {\n\tif (!Number.isInteger(length) || length < 0) {\n\t\tthrow new Error(\"length must be a non-negative integer\");\n\t}\n\n\tconst out = this.slice();\n\n\twhile (out.length < length) out.push(value);\n\n\treturn out;\n}\n","import chunk from \"../functions/chunk\";\nimport first from \"../functions/first\";\nimport last from \"../functions/last\";\nimport random from \"../functions/random\";\nimport unique from \"../functions/unique\";\nimport compact from \"../functions/compact\";\nimport compactMap from \"../functions/compactMap\";\nimport keyValueMap from \"../functions/keyValueMap\";\nimport sum from \"../functions/sum\";\nimport avg from \"../functions/avg\";\nimport max from \"../functions/max\";\nimport min from \"../functions/min\";\nimport shuffle from \"../functions/shuffle\";\nimport groupBy from \"../functions/groupBy\";\nimport flatten from \"../functions/flatten\";\nimport zip from \"../functions/zip\";\nimport partition from \"../functions/partition\";\nimport pluck from \"../functions/pluck\";\nimport countBy from \"../functions/countBy\";\nimport difference from \"../functions/difference\";\nimport intersection from \"../functions/intersection\";\nimport union from \"../functions/union\";\nimport uniqBy from \"../functions/uniqBy\";\nimport sortBy from \"../functions/sortBy\";\nimport sample from \"../functions/sample\";\nimport pad from \"../functions/pad\";\n\ndeclare global {\n\tinterface Array<T> {\n\t\tfirst(): T | undefined;\n\t\tlast(): T | undefined;\n\t\tunique(): T[];\n\t\tchunk(size: number): T[][];\n\t\tcompact(): T[];\n\t\tcompactMap<R>(mapper: (value: T, index: number, arr: T[]) => R): Exclude<R, null | undefined>[];\n\t\trandom(): T | undefined;\n\t\tkeyValueMap(key: string, value: string): Record<string, any>[];\n\t\tsum(this: number[]): number;\n\t\tavg(this: number[]): number | undefined;\n\t\tmax(this: number[]): number | undefined;\n\t\tmin(this: number[]): number | undefined;\n\t\tshuffle(): T[];\t\n\t\tgroupBy<K extends PropertyKey>(key: ((item: T, index: number, arr: T[]) => K) | keyof T): Record<K, T[]>;\n\t\tflatten(this: (T | T[])[]): T[];\n\t\tzip(...arrays: any[][]): any[][];\n\t\tpartition(predicate: (value: T, index: number, arr: T[]) => boolean): [T[], T[]];\n\t\tpluck<K extends keyof T>(key: K): T[K][];\n\t\tcountBy<K extends PropertyKey>(key: ((item: T, index: number, arr: T[]) => K) | keyof T): Record<K, number>;\n\t\tdifference(...arrays: T[][]): T[];\n\t\tintersection(...arrays: T[][]): T[];\n\t\tunion(...arrays: T[][]): T[];\n\t\tuniqBy<K>(key: ((item: T, index: number, arr: T[]) => K) | keyof T): T[];\n\t\tsortBy<K extends string | number | bigint>(key: ((item: T, index: number, arr: T[]) => K) | keyof T): T[];\n\t\tsample(count: number): T[];\n\t\tpad(length: number, value: T): T[];\n\t}\n}\n\nfunction defineArrayMethod (name: string, fn: Function) {\n\tif (!(Array.prototype as any)[name]) {\n\t\tObject.defineProperty(Array.prototype, name, {\n\t\t\tvalue: fn,\n\t\t\twritable: false,\n\t\t\tconfigurable: false\n\t\t});\n\t}\n}\n\ndefineArrayMethod(\"first\", first);\ndefineArrayMethod(\"last\", last);\ndefineArrayMethod(\"unique\", unique);\ndefineArrayMethod(\"chunk\", chunk);\ndefineArrayMethod(\"compact\", compact);\ndefineArrayMethod(\"compactMap\", compactMap);\ndefineArrayMethod(\"random\", random);\ndefineArrayMethod(\"keyValueMap\", keyValueMap);\ndefineArrayMethod(\"sum\", sum);\ndefineArrayMethod(\"avg\", avg);\ndefineArrayMethod(\"max\", max);\ndefineArrayMethod(\"min\", min);\ndefineArrayMethod(\"shuffle\", shuffle);\ndefineArrayMethod(\"groupBy\", groupBy);\ndefineArrayMethod(\"flatten\", flatten);\ndefineArrayMethod(\"zip\", zip);\ndefineArrayMethod(\"partition\", partition);\ndefineArrayMethod(\"pluck\", pluck);\ndefineArrayMethod(\"countBy\", countBy);\ndefineArrayMethod(\"difference\", difference);\ndefineArrayMethod(\"intersection\", intersection);\ndefineArrayMethod(\"union\", union);\ndefineArrayMethod(\"uniqBy\", uniqBy);\ndefineArrayMethod(\"sortBy\", sortBy);\ndefineArrayMethod(\"sample\", sample);\ndefineArrayMethod(\"pad\", pad);\n\nexport {};\n"],"names":[],"mappings":"AAAA;;;;AAIE;AAEY,cAAA,EAAyB,IAAY,EAAA;IAClD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC;IAC5F,MAAM,GAAG,GAAU,EAAE;AACrB,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI;AAAE,QAAA,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;AAC7E,IAAA,OAAO,GAAG;AACX;;ACXA;;AAEE;AACY,cAAA,IAAA,EAA2B,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;;ACHnF;;AAEE;AACY,aAAA,IAAA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E,GAAG,CAAC;AAC7B,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC;AAC7B,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC;AAC7B,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC;AAC7B,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC;AACrC,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC;AACrC,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC;AACrC,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC;AAC7B,iBAAiB,CAAC,WAAW,EAAE,SAAS,CAAC;AACzC,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC;AACjC,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC;AACrC,iBAAiB,CAAC,YAAY,EAAE,UAAU,CAAC;AAC3C,iBAAiB,CAAC,cAAc,EAAE,YAAY,CAAC;AAC/C,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC;AACjC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC;AACnC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC;AACnC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC;AACnC,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC"}
|
package/dist/auto.umd.js
ADDED
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
3
|
+
factory();
|
|
4
|
+
})((function () { 'use strict';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Splits the array into smaller arrays of the given size.
|
|
8
|
+
* @param size Number of items per chunk
|
|
9
|
+
* @returns Array of chunks
|
|
10
|
+
*/
|
|
11
|
+
function chunk (size) {
|
|
12
|
+
if (!Number.isInteger(size) || size <= 0)
|
|
13
|
+
throw new Error("size must be a positive integer");
|
|
14
|
+
var out = [];
|
|
15
|
+
for (var i = 0; i < this.length; i += size)
|
|
16
|
+
out.push(this.slice(i, i + size));
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @returns the first element of the array, or undefined if the array is empty.
|
|
22
|
+
*/
|
|
23
|
+
function first () { return this.length ? this[0] : undefined; }
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @returns the last element of the array, or undefined if the array is empty.
|
|
27
|
+
*/
|
|
28
|
+
function last () { return this.length ? this[this.length - 1] : undefined; }
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @returns a random element from the array, or undefined if the array is empty.
|
|
32
|
+
*/
|
|
33
|
+
function random () {
|
|
34
|
+
return this.length ? this[Math.floor(Math.random() * this.length)] : undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @returns a new array with only unique elements from the original array.
|
|
39
|
+
* Supports deep comparison for objects.
|
|
40
|
+
* Uses a map for improved performance with primitives.
|
|
41
|
+
*/
|
|
42
|
+
function deepEqual(a, b) {
|
|
43
|
+
if (a === b)
|
|
44
|
+
return true;
|
|
45
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null)
|
|
46
|
+
return false;
|
|
47
|
+
var keysA = Object.keys(a), keysB = Object.keys(b);
|
|
48
|
+
if (keysA.length !== keysB.length)
|
|
49
|
+
return false;
|
|
50
|
+
for (var _i = 0, keysA_1 = keysA; _i < keysA_1.length; _i++) {
|
|
51
|
+
var key = keysA_1[_i];
|
|
52
|
+
if (!keysB.includes(key) || !deepEqual(a[key], b[key]))
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
function unique () {
|
|
58
|
+
var result = [];
|
|
59
|
+
var primitiveMap = new Map();
|
|
60
|
+
var _loop_1 = function (item) {
|
|
61
|
+
if (item === null || typeof item !== "object") {
|
|
62
|
+
if (!primitiveMap.has(item)) {
|
|
63
|
+
primitiveMap.set(item, true);
|
|
64
|
+
result.push(item);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
if (!result.some(function (existing) { return deepEqual(existing, item); })) {
|
|
69
|
+
result.push(item);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
for (var _i = 0, _a = this; _i < _a.length; _i++) {
|
|
74
|
+
var item = _a[_i];
|
|
75
|
+
_loop_1(item);
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Removes falsy values from the array.
|
|
82
|
+
* @returns A new array without falsy values.
|
|
83
|
+
*/
|
|
84
|
+
function compact () {
|
|
85
|
+
return this.filter(function (value) { return Boolean(value); });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Maps items and removes null/undefined results.
|
|
90
|
+
* @param mapper Function to map items.
|
|
91
|
+
* @returns A new array of mapped values without null/undefined.
|
|
92
|
+
*/
|
|
93
|
+
function compactMap (mapper) {
|
|
94
|
+
var out = [];
|
|
95
|
+
for (var index = 0; index < this.length; index++) {
|
|
96
|
+
var value = mapper(this[index], index, this);
|
|
97
|
+
if (value !== null && value !== undefined) {
|
|
98
|
+
out.push(value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Creates an object mapping each value of the given key to the corresponding value from the array of objects.
|
|
106
|
+
* @param key The property name to use as keys in the result object.
|
|
107
|
+
* @param value The property name to use as values in the result object.
|
|
108
|
+
* @returns An object mapping key values to value values.
|
|
109
|
+
*/
|
|
110
|
+
function keyValueMap (key, value) {
|
|
111
|
+
if (!key) {
|
|
112
|
+
throw new Error('keyValueMap: key is required');
|
|
113
|
+
}
|
|
114
|
+
if (!value) {
|
|
115
|
+
throw new Error("keyValueMap: value is required");
|
|
116
|
+
}
|
|
117
|
+
if (this.some(function (el) { return !el; })) {
|
|
118
|
+
throw new Error('keyValueMap: Array contains falsy values');
|
|
119
|
+
}
|
|
120
|
+
if (this.some(function (el) { return typeof el !== 'object'; })) {
|
|
121
|
+
throw new Error('keyValueMap: Array contains non-object values');
|
|
122
|
+
}
|
|
123
|
+
if (this.some(function (el) { return !el.hasOwnProperty(key); })) {
|
|
124
|
+
throw new Error("keyValueMap: key \"".concat(key, "\" does not exist on all objects"));
|
|
125
|
+
}
|
|
126
|
+
var map = {};
|
|
127
|
+
for (var index = 0; index < this.length; index++) {
|
|
128
|
+
var element = this[index];
|
|
129
|
+
map[element[key]] = element[value];
|
|
130
|
+
}
|
|
131
|
+
return map;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Calculates the sum of all numbers in an array.
|
|
136
|
+
* @returns The sum of all numbers in the array.
|
|
137
|
+
* @throws Will throw an error if any element in the array is not a number.
|
|
138
|
+
* @example
|
|
139
|
+
* [1, 2, 3].sum() // returns 6
|
|
140
|
+
* [10, -2, 5].sum() // returns 13
|
|
141
|
+
* [1, '2', 3].sum() // throws Error
|
|
142
|
+
*/
|
|
143
|
+
function sum () {
|
|
144
|
+
if (this.some(function (el) { return typeof el !== 'number'; })) {
|
|
145
|
+
throw new Error('All elements must be numbers');
|
|
146
|
+
}
|
|
147
|
+
var sum = 0;
|
|
148
|
+
for (var _i = 0, _a = this; _i < _a.length; _i++) {
|
|
149
|
+
var num = _a[_i];
|
|
150
|
+
sum += num;
|
|
151
|
+
}
|
|
152
|
+
return sum;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Calculates the average of all numbers in an array.
|
|
157
|
+
* @returns The average value.
|
|
158
|
+
* @throws If any element is not a number.
|
|
159
|
+
*/
|
|
160
|
+
function avg () {
|
|
161
|
+
if (this.length === 0)
|
|
162
|
+
return undefined;
|
|
163
|
+
if (this.some(function (el) { return typeof el !== 'number'; })) {
|
|
164
|
+
throw new Error('All elements must be numbers');
|
|
165
|
+
}
|
|
166
|
+
return this.reduce(function (a, b) { return a + b; }, 0) / this.length;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Returns the maximum number in the array.
|
|
171
|
+
* @returns The maximum value.
|
|
172
|
+
* @throws If any element is not a number.
|
|
173
|
+
*/
|
|
174
|
+
function max () {
|
|
175
|
+
if (this.length === 0)
|
|
176
|
+
return undefined;
|
|
177
|
+
if (this.some(function (el) { return typeof el !== 'number'; })) {
|
|
178
|
+
throw new Error('All elements must be numbers');
|
|
179
|
+
}
|
|
180
|
+
return Math.max.apply(Math, this);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Returns the minimum number in the array.
|
|
185
|
+
* @returns The minimum value.
|
|
186
|
+
* @throws If any element is not a number.
|
|
187
|
+
*/
|
|
188
|
+
function min () {
|
|
189
|
+
if (this.length === 0)
|
|
190
|
+
return undefined;
|
|
191
|
+
if (this.some(function (el) { return typeof el !== 'number'; })) {
|
|
192
|
+
throw new Error('All elements must be numbers');
|
|
193
|
+
}
|
|
194
|
+
return Math.min.apply(Math, this);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function shuffle() {
|
|
198
|
+
var _a;
|
|
199
|
+
for (var i = this.length - 1; i > 0; i--) {
|
|
200
|
+
var j = Math.floor(Math.random() * (i + 1));
|
|
201
|
+
_a = [this[j], this[i]], this[i] = _a[0], this[j] = _a[1];
|
|
202
|
+
}
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Groups array items by a key or mapper function.
|
|
208
|
+
* @param key The property name or mapper function to group by.
|
|
209
|
+
* @returns An object where keys are group identifiers and values are arrays of items.
|
|
210
|
+
*/
|
|
211
|
+
function groupBy (key) {
|
|
212
|
+
var result = {};
|
|
213
|
+
var getKey = typeof key === "function"
|
|
214
|
+
? key
|
|
215
|
+
: function (item) { return item[key]; };
|
|
216
|
+
for (var index = 0; index < this.length; index++) {
|
|
217
|
+
var item = this[index];
|
|
218
|
+
var groupKey = getKey(item, index, this);
|
|
219
|
+
if (!result[groupKey])
|
|
220
|
+
result[groupKey] = [];
|
|
221
|
+
result[groupKey].push(item);
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Flattens the array by one level.
|
|
228
|
+
* @returns A new flattened array.
|
|
229
|
+
*/
|
|
230
|
+
function flatten () {
|
|
231
|
+
var out = [];
|
|
232
|
+
for (var _i = 0, _a = this; _i < _a.length; _i++) {
|
|
233
|
+
var item = _a[_i];
|
|
234
|
+
if (Array.isArray(item))
|
|
235
|
+
out.push.apply(out, item);
|
|
236
|
+
else
|
|
237
|
+
out.push(item);
|
|
238
|
+
}
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/******************************************************************************
|
|
243
|
+
Copyright (c) Microsoft Corporation.
|
|
244
|
+
|
|
245
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
246
|
+
purpose with or without fee is hereby granted.
|
|
247
|
+
|
|
248
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
249
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
250
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
251
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
252
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
253
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
254
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
255
|
+
***************************************************************************** */
|
|
256
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
function __spreadArray(to, from, pack) {
|
|
260
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
261
|
+
if (ar || !(i in from)) {
|
|
262
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
263
|
+
ar[i] = from[i];
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
270
|
+
var e = new Error(message);
|
|
271
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Zips the array with other arrays.
|
|
276
|
+
* @param arrays Arrays to zip with.
|
|
277
|
+
* @returns An array of tuples, truncated to the shortest length.
|
|
278
|
+
*/
|
|
279
|
+
function zip () {
|
|
280
|
+
var arrays = [];
|
|
281
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
282
|
+
arrays[_i] = arguments[_i];
|
|
283
|
+
}
|
|
284
|
+
if (arrays.length === 0)
|
|
285
|
+
return this.map(function (item) { return [item]; });
|
|
286
|
+
var minLength = Math.min.apply(Math, __spreadArray([this.length], arrays.map(function (arr) { return arr.length; }), false));
|
|
287
|
+
var out = [];
|
|
288
|
+
var _loop_1 = function (index) {
|
|
289
|
+
out.push(__spreadArray([this_1[index]], arrays.map(function (arr) { return arr[index]; }), true));
|
|
290
|
+
};
|
|
291
|
+
var this_1 = this;
|
|
292
|
+
for (var index = 0; index < minLength; index++) {
|
|
293
|
+
_loop_1(index);
|
|
294
|
+
}
|
|
295
|
+
return out;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Splits the array into two arrays based on a predicate.
|
|
300
|
+
* @param predicate Function to test each element.
|
|
301
|
+
* @returns A tuple: [items that pass, items that fail].
|
|
302
|
+
*/
|
|
303
|
+
function partition (predicate) {
|
|
304
|
+
var pass = [];
|
|
305
|
+
var fail = [];
|
|
306
|
+
for (var index = 0; index < this.length; index++) {
|
|
307
|
+
var item = this[index];
|
|
308
|
+
if (predicate(item, index, this))
|
|
309
|
+
pass.push(item);
|
|
310
|
+
else
|
|
311
|
+
fail.push(item);
|
|
312
|
+
}
|
|
313
|
+
return [pass, fail];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Plucks a property from each item in the array.
|
|
318
|
+
* @param key Property name to pluck.
|
|
319
|
+
* @returns A new array of property values.
|
|
320
|
+
*/
|
|
321
|
+
function pluck (key) {
|
|
322
|
+
return this.map(function (item) { return item[key]; });
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Counts items by a key or mapper function.
|
|
327
|
+
* @param key The property name or mapper function to count by.
|
|
328
|
+
* @returns An object where keys are group identifiers and values are counts.
|
|
329
|
+
*/
|
|
330
|
+
function countBy (key) {
|
|
331
|
+
var _a;
|
|
332
|
+
var result = {};
|
|
333
|
+
var getKey = typeof key === "function"
|
|
334
|
+
? key
|
|
335
|
+
: function (item) { return item[key]; };
|
|
336
|
+
for (var index = 0; index < this.length; index++) {
|
|
337
|
+
var item = this[index];
|
|
338
|
+
var groupKey = getKey(item, index, this);
|
|
339
|
+
result[groupKey] = ((_a = result[groupKey]) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Returns items that are not present in the other arrays.
|
|
346
|
+
* @param arrays Arrays to exclude.
|
|
347
|
+
* @returns A new array of values not found in other arrays.
|
|
348
|
+
*/
|
|
349
|
+
function difference () {
|
|
350
|
+
var arrays = [];
|
|
351
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
352
|
+
arrays[_i] = arguments[_i];
|
|
353
|
+
}
|
|
354
|
+
if (arrays.length === 0)
|
|
355
|
+
return this.slice();
|
|
356
|
+
var other = new Set();
|
|
357
|
+
for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
|
|
358
|
+
var arr = arrays_1[_a];
|
|
359
|
+
for (var _b = 0, arr_1 = arr; _b < arr_1.length; _b++) {
|
|
360
|
+
var item = arr_1[_b];
|
|
361
|
+
other.add(item);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return this.filter(function (item) { return !other.has(item); });
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Returns items present in all arrays.
|
|
369
|
+
* @param arrays Arrays to intersect with.
|
|
370
|
+
* @returns A new array of items found in every array.
|
|
371
|
+
*/
|
|
372
|
+
function intersection () {
|
|
373
|
+
var arrays = [];
|
|
374
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
375
|
+
arrays[_i] = arguments[_i];
|
|
376
|
+
}
|
|
377
|
+
if (arrays.length === 0)
|
|
378
|
+
return this.slice();
|
|
379
|
+
var sets = arrays.map(function (arr) { return new Set(arr); });
|
|
380
|
+
return this.filter(function (item) { return sets.every(function (set) { return set.has(item); }); });
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Returns a unique merge of the array and the other arrays.
|
|
385
|
+
* @param arrays Arrays to merge.
|
|
386
|
+
* @returns A new array with unique values.
|
|
387
|
+
*/
|
|
388
|
+
function union () {
|
|
389
|
+
var arrays = [];
|
|
390
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
391
|
+
arrays[_i] = arguments[_i];
|
|
392
|
+
}
|
|
393
|
+
var out = [];
|
|
394
|
+
var seen = new Set();
|
|
395
|
+
var push = function (item) {
|
|
396
|
+
if (seen.has(item))
|
|
397
|
+
return;
|
|
398
|
+
seen.add(item);
|
|
399
|
+
out.push(item);
|
|
400
|
+
};
|
|
401
|
+
for (var _a = 0, _b = this; _a < _b.length; _a++) {
|
|
402
|
+
var item = _b[_a];
|
|
403
|
+
push(item);
|
|
404
|
+
}
|
|
405
|
+
for (var _c = 0, arrays_1 = arrays; _c < arrays_1.length; _c++) {
|
|
406
|
+
var arr = arrays_1[_c];
|
|
407
|
+
for (var _d = 0, arr_1 = arr; _d < arr_1.length; _d++) {
|
|
408
|
+
var item = arr_1[_d];
|
|
409
|
+
push(item);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return out;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Returns unique items by a key or mapper function.
|
|
417
|
+
* @param key The property name or mapper function to determine uniqueness.
|
|
418
|
+
* @returns A new array with unique items.
|
|
419
|
+
*/
|
|
420
|
+
function uniqBy (key) {
|
|
421
|
+
var result = [];
|
|
422
|
+
var seen = new Set();
|
|
423
|
+
var getKey = typeof key === "function"
|
|
424
|
+
? key
|
|
425
|
+
: function (item) { return item[key]; };
|
|
426
|
+
for (var index = 0; index < this.length; index++) {
|
|
427
|
+
var item = this[index];
|
|
428
|
+
var keyValue = getKey(item, index, this);
|
|
429
|
+
if (!seen.has(keyValue)) {
|
|
430
|
+
seen.add(keyValue);
|
|
431
|
+
result.push(item);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return result;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Sorts items by a key or mapper function (stable).
|
|
439
|
+
* @param key The property name or mapper function to sort by.
|
|
440
|
+
* @returns A new array sorted by the key.
|
|
441
|
+
*/
|
|
442
|
+
function sortBy (key) {
|
|
443
|
+
var _this = this;
|
|
444
|
+
var getKey = typeof key === "function"
|
|
445
|
+
? key
|
|
446
|
+
: function (item) { return item[key]; };
|
|
447
|
+
return this
|
|
448
|
+
.map(function (item, index) { return ({ item: item, index: index, key: getKey(item, index, _this) }); })
|
|
449
|
+
.sort(function (a, b) {
|
|
450
|
+
if (a.key < b.key)
|
|
451
|
+
return -1;
|
|
452
|
+
if (a.key > b.key)
|
|
453
|
+
return 1;
|
|
454
|
+
return a.index - b.index;
|
|
455
|
+
})
|
|
456
|
+
.map(function (entry) { return entry.item; });
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Returns a random sample of items without replacement.
|
|
461
|
+
* @param count Number of items to sample.
|
|
462
|
+
* @returns A new array containing sampled items.
|
|
463
|
+
*/
|
|
464
|
+
function sample (count) {
|
|
465
|
+
var _a;
|
|
466
|
+
if (!Number.isInteger(count) || count <= 0) {
|
|
467
|
+
throw new Error("count must be a positive integer");
|
|
468
|
+
}
|
|
469
|
+
var out = this.slice();
|
|
470
|
+
for (var i = out.length - 1; i > 0; i--) {
|
|
471
|
+
var j = Math.floor(Math.random() * (i + 1));
|
|
472
|
+
_a = [out[j], out[i]], out[i] = _a[0], out[j] = _a[1];
|
|
473
|
+
}
|
|
474
|
+
return out.slice(0, Math.min(count, out.length));
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Pads the array to the given length with the provided value.
|
|
479
|
+
* @param length Target length.
|
|
480
|
+
* @param value Value to pad with.
|
|
481
|
+
* @returns A new padded array.
|
|
482
|
+
*/
|
|
483
|
+
function pad (length, value) {
|
|
484
|
+
if (!Number.isInteger(length) || length < 0) {
|
|
485
|
+
throw new Error("length must be a non-negative integer");
|
|
486
|
+
}
|
|
487
|
+
var out = this.slice();
|
|
488
|
+
while (out.length < length)
|
|
489
|
+
out.push(value);
|
|
490
|
+
return out;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function defineArrayMethod(name, fn) {
|
|
494
|
+
if (!Array.prototype[name]) {
|
|
495
|
+
Object.defineProperty(Array.prototype, name, {
|
|
496
|
+
value: fn,
|
|
497
|
+
writable: false,
|
|
498
|
+
configurable: false
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
defineArrayMethod("first", first);
|
|
503
|
+
defineArrayMethod("last", last);
|
|
504
|
+
defineArrayMethod("unique", unique);
|
|
505
|
+
defineArrayMethod("chunk", chunk);
|
|
506
|
+
defineArrayMethod("compact", compact);
|
|
507
|
+
defineArrayMethod("compactMap", compactMap);
|
|
508
|
+
defineArrayMethod("random", random);
|
|
509
|
+
defineArrayMethod("keyValueMap", keyValueMap);
|
|
510
|
+
defineArrayMethod("sum", sum);
|
|
511
|
+
defineArrayMethod("avg", avg);
|
|
512
|
+
defineArrayMethod("max", max);
|
|
513
|
+
defineArrayMethod("min", min);
|
|
514
|
+
defineArrayMethod("shuffle", shuffle);
|
|
515
|
+
defineArrayMethod("groupBy", groupBy);
|
|
516
|
+
defineArrayMethod("flatten", flatten);
|
|
517
|
+
defineArrayMethod("zip", zip);
|
|
518
|
+
defineArrayMethod("partition", partition);
|
|
519
|
+
defineArrayMethod("pluck", pluck);
|
|
520
|
+
defineArrayMethod("countBy", countBy);
|
|
521
|
+
defineArrayMethod("difference", difference);
|
|
522
|
+
defineArrayMethod("intersection", intersection);
|
|
523
|
+
defineArrayMethod("union", union);
|
|
524
|
+
defineArrayMethod("uniqBy", uniqBy);
|
|
525
|
+
defineArrayMethod("sortBy", sortBy);
|
|
526
|
+
defineArrayMethod("sample", sample);
|
|
527
|
+
defineArrayMethod("pad", pad);
|
|
528
|
+
|
|
529
|
+
}));
|
|
530
|
+
//# sourceMappingURL=auto.umd.js.map
|