@r01al/array-polyfills 1.0.5 → 1.0.7

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.
Files changed (48) hide show
  1. package/README.md +474 -2
  2. package/dist/auto.cjs +262 -0
  3. package/dist/auto.cjs.map +1 -1
  4. package/dist/auto.mjs +262 -0
  5. package/dist/auto.mjs.map +1 -1
  6. package/dist/auto.umd.js +530 -0
  7. package/dist/auto.umd.js.map +1 -0
  8. package/dist/functions/compact.d.ts +7 -0
  9. package/dist/functions/compact.js +7 -0
  10. package/dist/functions/compactMap.d.ts +6 -0
  11. package/dist/functions/compactMap.js +15 -0
  12. package/dist/functions/countBy.d.ts +6 -0
  13. package/dist/functions/countBy.js +17 -0
  14. package/dist/functions/difference.d.ts +6 -0
  15. package/dist/functions/difference.js +15 -0
  16. package/dist/functions/flatten.d.ts +5 -0
  17. package/dist/functions/flatten.js +14 -0
  18. package/dist/functions/groupBy.d.ts +6 -0
  19. package/dist/functions/groupBy.js +19 -0
  20. package/dist/functions/intersection.d.ts +6 -0
  21. package/dist/functions/intersection.js +11 -0
  22. package/dist/functions/pad.d.ts +7 -0
  23. package/dist/functions/pad.js +15 -0
  24. package/dist/functions/partition.d.ts +6 -0
  25. package/dist/functions/partition.js +17 -0
  26. package/dist/functions/pluck.d.ts +6 -0
  27. package/dist/functions/pluck.js +8 -0
  28. package/dist/functions/sample.d.ts +6 -0
  29. package/dist/functions/sample.js +16 -0
  30. package/dist/functions/sortBy.d.ts +6 -0
  31. package/dist/functions/sortBy.js +20 -0
  32. package/dist/functions/union.d.ts +6 -0
  33. package/dist/functions/union.js +22 -0
  34. package/dist/functions/uniqBy.d.ts +6 -0
  35. package/dist/functions/uniqBy.js +21 -0
  36. package/dist/functions/zip.d.ts +6 -0
  37. package/dist/functions/zip.js +15 -0
  38. package/dist/index.cjs +289 -11
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.ts +30 -0
  41. package/dist/index.js +42 -11
  42. package/dist/index.mjs +275 -12
  43. package/dist/index.mjs.map +1 -1
  44. package/dist/index.umd.js +580 -0
  45. package/dist/index.umd.js.map +1 -0
  46. package/dist/polyfills/array.d.ts +15 -0
  47. package/dist/polyfills/array.js +30 -0
  48. package/package.json +2 -1
package/dist/auto.cjs CHANGED
@@ -69,6 +69,30 @@ function unique () {
69
69
  return result;
70
70
  }
71
71
 
72
+ /**
73
+ * Removes falsy values from the array.
74
+ * @returns A new array without falsy values.
75
+ */
76
+ function compact () {
77
+ return this.filter((value) => Boolean(value));
78
+ }
79
+
80
+ /**
81
+ * Maps items and removes null/undefined results.
82
+ * @param mapper Function to map items.
83
+ * @returns A new array of mapped values without null/undefined.
84
+ */
85
+ function compactMap (mapper) {
86
+ const out = [];
87
+ for (let index = 0; index < this.length; index++) {
88
+ const value = mapper(this[index], index, this);
89
+ if (value !== null && value !== undefined) {
90
+ out.push(value);
91
+ }
92
+ }
93
+ return out;
94
+ }
95
+
72
96
  /**
73
97
  * Creates an object mapping each value of the given key to the corresponding value from the array of objects.
74
98
  * @param key The property name to use as keys in the result object.
@@ -169,6 +193,229 @@ function shuffle() {
169
193
  return this;
170
194
  }
171
195
 
196
+ /**
197
+ * Groups array items by a key or mapper function.
198
+ * @param key The property name or mapper function to group by.
199
+ * @returns An object where keys are group identifiers and values are arrays of items.
200
+ */
201
+ function groupBy (key) {
202
+ const result = {};
203
+ const getKey = typeof key === "function"
204
+ ? key
205
+ : (item) => item[key];
206
+ for (let index = 0; index < this.length; index++) {
207
+ const item = this[index];
208
+ const groupKey = getKey(item, index, this);
209
+ if (!result[groupKey])
210
+ result[groupKey] = [];
211
+ result[groupKey].push(item);
212
+ }
213
+ return result;
214
+ }
215
+
216
+ /**
217
+ * Flattens the array by one level.
218
+ * @returns A new flattened array.
219
+ */
220
+ function flatten () {
221
+ const out = [];
222
+ for (const item of this) {
223
+ if (Array.isArray(item))
224
+ out.push(...item);
225
+ else
226
+ out.push(item);
227
+ }
228
+ return out;
229
+ }
230
+
231
+ /**
232
+ * Zips the array with other arrays.
233
+ * @param arrays Arrays to zip with.
234
+ * @returns An array of tuples, truncated to the shortest length.
235
+ */
236
+ function zip (...arrays) {
237
+ if (arrays.length === 0)
238
+ return this.map(item => [item]);
239
+ const minLength = Math.min(this.length, ...arrays.map(arr => arr.length));
240
+ const out = [];
241
+ for (let index = 0; index < minLength; index++) {
242
+ out.push([this[index], ...arrays.map(arr => arr[index])]);
243
+ }
244
+ return out;
245
+ }
246
+
247
+ /**
248
+ * Splits the array into two arrays based on a predicate.
249
+ * @param predicate Function to test each element.
250
+ * @returns A tuple: [items that pass, items that fail].
251
+ */
252
+ function partition (predicate) {
253
+ const pass = [];
254
+ const fail = [];
255
+ for (let index = 0; index < this.length; index++) {
256
+ const item = this[index];
257
+ if (predicate(item, index, this))
258
+ pass.push(item);
259
+ else
260
+ fail.push(item);
261
+ }
262
+ return [pass, fail];
263
+ }
264
+
265
+ /**
266
+ * Plucks a property from each item in the array.
267
+ * @param key Property name to pluck.
268
+ * @returns A new array of property values.
269
+ */
270
+ function pluck (key) {
271
+ return this.map(item => item[key]);
272
+ }
273
+
274
+ /**
275
+ * Counts items by a key or mapper function.
276
+ * @param key The property name or mapper function to count by.
277
+ * @returns An object where keys are group identifiers and values are counts.
278
+ */
279
+ function countBy (key) {
280
+ const result = {};
281
+ const getKey = typeof key === "function"
282
+ ? key
283
+ : (item) => item[key];
284
+ for (let index = 0; index < this.length; index++) {
285
+ const item = this[index];
286
+ const groupKey = getKey(item, index, this);
287
+ result[groupKey] = (result[groupKey] ?? 0) + 1;
288
+ }
289
+ return result;
290
+ }
291
+
292
+ /**
293
+ * Returns items that are not present in the other arrays.
294
+ * @param arrays Arrays to exclude.
295
+ * @returns A new array of values not found in other arrays.
296
+ */
297
+ function difference (...arrays) {
298
+ if (arrays.length === 0)
299
+ return this.slice();
300
+ const other = new Set();
301
+ for (const arr of arrays) {
302
+ for (const item of arr)
303
+ other.add(item);
304
+ }
305
+ return this.filter(item => !other.has(item));
306
+ }
307
+
308
+ /**
309
+ * Returns items present in all arrays.
310
+ * @param arrays Arrays to intersect with.
311
+ * @returns A new array of items found in every array.
312
+ */
313
+ function intersection (...arrays) {
314
+ if (arrays.length === 0)
315
+ return this.slice();
316
+ const sets = arrays.map(arr => new Set(arr));
317
+ return this.filter(item => sets.every(set => set.has(item)));
318
+ }
319
+
320
+ /**
321
+ * Returns a unique merge of the array and the other arrays.
322
+ * @param arrays Arrays to merge.
323
+ * @returns A new array with unique values.
324
+ */
325
+ function union (...arrays) {
326
+ const out = [];
327
+ const seen = new Set();
328
+ const push = (item) => {
329
+ if (seen.has(item))
330
+ return;
331
+ seen.add(item);
332
+ out.push(item);
333
+ };
334
+ for (const item of this)
335
+ push(item);
336
+ for (const arr of arrays) {
337
+ for (const item of arr)
338
+ push(item);
339
+ }
340
+ return out;
341
+ }
342
+
343
+ /**
344
+ * Returns unique items by a key or mapper function.
345
+ * @param key The property name or mapper function to determine uniqueness.
346
+ * @returns A new array with unique items.
347
+ */
348
+ function uniqBy (key) {
349
+ const result = [];
350
+ const seen = new Set();
351
+ const getKey = typeof key === "function"
352
+ ? key
353
+ : (item) => item[key];
354
+ for (let index = 0; index < this.length; index++) {
355
+ const item = this[index];
356
+ const keyValue = getKey(item, index, this);
357
+ if (!seen.has(keyValue)) {
358
+ seen.add(keyValue);
359
+ result.push(item);
360
+ }
361
+ }
362
+ return result;
363
+ }
364
+
365
+ /**
366
+ * Sorts items by a key or mapper function (stable).
367
+ * @param key The property name or mapper function to sort by.
368
+ * @returns A new array sorted by the key.
369
+ */
370
+ function sortBy (key) {
371
+ const getKey = typeof key === "function"
372
+ ? key
373
+ : (item) => item[key];
374
+ return this
375
+ .map((item, index) => ({ item, index, key: getKey(item, index, this) }))
376
+ .sort((a, b) => {
377
+ if (a.key < b.key)
378
+ return -1;
379
+ if (a.key > b.key)
380
+ return 1;
381
+ return a.index - b.index;
382
+ })
383
+ .map(entry => entry.item);
384
+ }
385
+
386
+ /**
387
+ * Returns a random sample of items without replacement.
388
+ * @param count Number of items to sample.
389
+ * @returns A new array containing sampled items.
390
+ */
391
+ function sample (count) {
392
+ if (!Number.isInteger(count) || count <= 0) {
393
+ throw new Error("count must be a positive integer");
394
+ }
395
+ const out = this.slice();
396
+ for (let i = out.length - 1; i > 0; i--) {
397
+ const j = Math.floor(Math.random() * (i + 1));
398
+ [out[i], out[j]] = [out[j], out[i]];
399
+ }
400
+ return out.slice(0, Math.min(count, out.length));
401
+ }
402
+
403
+ /**
404
+ * Pads the array to the given length with the provided value.
405
+ * @param length Target length.
406
+ * @param value Value to pad with.
407
+ * @returns A new padded array.
408
+ */
409
+ function pad (length, value) {
410
+ if (!Number.isInteger(length) || length < 0) {
411
+ throw new Error("length must be a non-negative integer");
412
+ }
413
+ const out = this.slice();
414
+ while (out.length < length)
415
+ out.push(value);
416
+ return out;
417
+ }
418
+
172
419
  function defineArrayMethod(name, fn) {
173
420
  if (!Array.prototype[name]) {
174
421
  Object.defineProperty(Array.prototype, name, {
@@ -182,6 +429,8 @@ defineArrayMethod("first", first);
182
429
  defineArrayMethod("last", last);
183
430
  defineArrayMethod("unique", unique);
184
431
  defineArrayMethod("chunk", chunk);
432
+ defineArrayMethod("compact", compact);
433
+ defineArrayMethod("compactMap", compactMap);
185
434
  defineArrayMethod("random", random);
186
435
  defineArrayMethod("keyValueMap", keyValueMap);
187
436
  defineArrayMethod("sum", sum);
@@ -189,4 +438,17 @@ defineArrayMethod("avg", avg);
189
438
  defineArrayMethod("max", max);
190
439
  defineArrayMethod("min", min);
191
440
  defineArrayMethod("shuffle", shuffle);
441
+ defineArrayMethod("groupBy", groupBy);
442
+ defineArrayMethod("flatten", flatten);
443
+ defineArrayMethod("zip", zip);
444
+ defineArrayMethod("partition", partition);
445
+ defineArrayMethod("pluck", pluck);
446
+ defineArrayMethod("countBy", countBy);
447
+ defineArrayMethod("difference", difference);
448
+ defineArrayMethod("intersection", intersection);
449
+ defineArrayMethod("union", union);
450
+ defineArrayMethod("uniqBy", uniqBy);
451
+ defineArrayMethod("sortBy", sortBy);
452
+ defineArrayMethod("sample", sample);
453
+ defineArrayMethod("pad", pad);
192
454
  //# sourceMappingURL=auto.cjs.map
package/dist/auto.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"auto.cjs","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);\ndefineArrayMethod(\"max\", max);\ndefineArrayMethod(\"min\", min);\ndefineArrayMethod(\"shuffle\", shuffle);\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,EAA2B,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;;ACHjG;;AAEG;AACW,eAAA,IAAA;IACb,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS;AAC/E;;ACLA;;;;AAIG;AACH,SAAS,SAAS,CAAC,CAAM,EAAE,CAAM,EAAA;IAC7B,IAAI,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI;AACxB,IAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,C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CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,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.cjs","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,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AAiB,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;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.mjs CHANGED
@@ -67,6 +67,30 @@ function unique () {
67
67
  return result;
68
68
  }
69
69
 
70
+ /**
71
+ * Removes falsy values from the array.
72
+ * @returns A new array without falsy values.
73
+ */
74
+ function compact () {
75
+ return this.filter((value) => Boolean(value));
76
+ }
77
+
78
+ /**
79
+ * Maps items and removes null/undefined results.
80
+ * @param mapper Function to map items.
81
+ * @returns A new array of mapped values without null/undefined.
82
+ */
83
+ function compactMap (mapper) {
84
+ const out = [];
85
+ for (let index = 0; index < this.length; index++) {
86
+ const value = mapper(this[index], index, this);
87
+ if (value !== null && value !== undefined) {
88
+ out.push(value);
89
+ }
90
+ }
91
+ return out;
92
+ }
93
+
70
94
  /**
71
95
  * Creates an object mapping each value of the given key to the corresponding value from the array of objects.
72
96
  * @param key The property name to use as keys in the result object.
@@ -167,6 +191,229 @@ function shuffle() {
167
191
  return this;
168
192
  }
169
193
 
194
+ /**
195
+ * Groups array items by a key or mapper function.
196
+ * @param key The property name or mapper function to group by.
197
+ * @returns An object where keys are group identifiers and values are arrays of items.
198
+ */
199
+ function groupBy (key) {
200
+ const result = {};
201
+ const getKey = typeof key === "function"
202
+ ? key
203
+ : (item) => item[key];
204
+ for (let index = 0; index < this.length; index++) {
205
+ const item = this[index];
206
+ const groupKey = getKey(item, index, this);
207
+ if (!result[groupKey])
208
+ result[groupKey] = [];
209
+ result[groupKey].push(item);
210
+ }
211
+ return result;
212
+ }
213
+
214
+ /**
215
+ * Flattens the array by one level.
216
+ * @returns A new flattened array.
217
+ */
218
+ function flatten () {
219
+ const out = [];
220
+ for (const item of this) {
221
+ if (Array.isArray(item))
222
+ out.push(...item);
223
+ else
224
+ out.push(item);
225
+ }
226
+ return out;
227
+ }
228
+
229
+ /**
230
+ * Zips the array with other arrays.
231
+ * @param arrays Arrays to zip with.
232
+ * @returns An array of tuples, truncated to the shortest length.
233
+ */
234
+ function zip (...arrays) {
235
+ if (arrays.length === 0)
236
+ return this.map(item => [item]);
237
+ const minLength = Math.min(this.length, ...arrays.map(arr => arr.length));
238
+ const out = [];
239
+ for (let index = 0; index < minLength; index++) {
240
+ out.push([this[index], ...arrays.map(arr => arr[index])]);
241
+ }
242
+ return out;
243
+ }
244
+
245
+ /**
246
+ * Splits the array into two arrays based on a predicate.
247
+ * @param predicate Function to test each element.
248
+ * @returns A tuple: [items that pass, items that fail].
249
+ */
250
+ function partition (predicate) {
251
+ const pass = [];
252
+ const fail = [];
253
+ for (let index = 0; index < this.length; index++) {
254
+ const item = this[index];
255
+ if (predicate(item, index, this))
256
+ pass.push(item);
257
+ else
258
+ fail.push(item);
259
+ }
260
+ return [pass, fail];
261
+ }
262
+
263
+ /**
264
+ * Plucks a property from each item in the array.
265
+ * @param key Property name to pluck.
266
+ * @returns A new array of property values.
267
+ */
268
+ function pluck (key) {
269
+ return this.map(item => item[key]);
270
+ }
271
+
272
+ /**
273
+ * Counts items by a key or mapper function.
274
+ * @param key The property name or mapper function to count by.
275
+ * @returns An object where keys are group identifiers and values are counts.
276
+ */
277
+ function countBy (key) {
278
+ const result = {};
279
+ const getKey = typeof key === "function"
280
+ ? key
281
+ : (item) => item[key];
282
+ for (let index = 0; index < this.length; index++) {
283
+ const item = this[index];
284
+ const groupKey = getKey(item, index, this);
285
+ result[groupKey] = (result[groupKey] ?? 0) + 1;
286
+ }
287
+ return result;
288
+ }
289
+
290
+ /**
291
+ * Returns items that are not present in the other arrays.
292
+ * @param arrays Arrays to exclude.
293
+ * @returns A new array of values not found in other arrays.
294
+ */
295
+ function difference (...arrays) {
296
+ if (arrays.length === 0)
297
+ return this.slice();
298
+ const other = new Set();
299
+ for (const arr of arrays) {
300
+ for (const item of arr)
301
+ other.add(item);
302
+ }
303
+ return this.filter(item => !other.has(item));
304
+ }
305
+
306
+ /**
307
+ * Returns items present in all arrays.
308
+ * @param arrays Arrays to intersect with.
309
+ * @returns A new array of items found in every array.
310
+ */
311
+ function intersection (...arrays) {
312
+ if (arrays.length === 0)
313
+ return this.slice();
314
+ const sets = arrays.map(arr => new Set(arr));
315
+ return this.filter(item => sets.every(set => set.has(item)));
316
+ }
317
+
318
+ /**
319
+ * Returns a unique merge of the array and the other arrays.
320
+ * @param arrays Arrays to merge.
321
+ * @returns A new array with unique values.
322
+ */
323
+ function union (...arrays) {
324
+ const out = [];
325
+ const seen = new Set();
326
+ const push = (item) => {
327
+ if (seen.has(item))
328
+ return;
329
+ seen.add(item);
330
+ out.push(item);
331
+ };
332
+ for (const item of this)
333
+ push(item);
334
+ for (const arr of arrays) {
335
+ for (const item of arr)
336
+ push(item);
337
+ }
338
+ return out;
339
+ }
340
+
341
+ /**
342
+ * Returns unique items by a key or mapper function.
343
+ * @param key The property name or mapper function to determine uniqueness.
344
+ * @returns A new array with unique items.
345
+ */
346
+ function uniqBy (key) {
347
+ const result = [];
348
+ const seen = new Set();
349
+ const getKey = typeof key === "function"
350
+ ? key
351
+ : (item) => item[key];
352
+ for (let index = 0; index < this.length; index++) {
353
+ const item = this[index];
354
+ const keyValue = getKey(item, index, this);
355
+ if (!seen.has(keyValue)) {
356
+ seen.add(keyValue);
357
+ result.push(item);
358
+ }
359
+ }
360
+ return result;
361
+ }
362
+
363
+ /**
364
+ * Sorts items by a key or mapper function (stable).
365
+ * @param key The property name or mapper function to sort by.
366
+ * @returns A new array sorted by the key.
367
+ */
368
+ function sortBy (key) {
369
+ const getKey = typeof key === "function"
370
+ ? key
371
+ : (item) => item[key];
372
+ return this
373
+ .map((item, index) => ({ item, index, key: getKey(item, index, this) }))
374
+ .sort((a, b) => {
375
+ if (a.key < b.key)
376
+ return -1;
377
+ if (a.key > b.key)
378
+ return 1;
379
+ return a.index - b.index;
380
+ })
381
+ .map(entry => entry.item);
382
+ }
383
+
384
+ /**
385
+ * Returns a random sample of items without replacement.
386
+ * @param count Number of items to sample.
387
+ * @returns A new array containing sampled items.
388
+ */
389
+ function sample (count) {
390
+ if (!Number.isInteger(count) || count <= 0) {
391
+ throw new Error("count must be a positive integer");
392
+ }
393
+ const out = this.slice();
394
+ for (let i = out.length - 1; i > 0; i--) {
395
+ const j = Math.floor(Math.random() * (i + 1));
396
+ [out[i], out[j]] = [out[j], out[i]];
397
+ }
398
+ return out.slice(0, Math.min(count, out.length));
399
+ }
400
+
401
+ /**
402
+ * Pads the array to the given length with the provided value.
403
+ * @param length Target length.
404
+ * @param value Value to pad with.
405
+ * @returns A new padded array.
406
+ */
407
+ function pad (length, value) {
408
+ if (!Number.isInteger(length) || length < 0) {
409
+ throw new Error("length must be a non-negative integer");
410
+ }
411
+ const out = this.slice();
412
+ while (out.length < length)
413
+ out.push(value);
414
+ return out;
415
+ }
416
+
170
417
  function defineArrayMethod(name, fn) {
171
418
  if (!Array.prototype[name]) {
172
419
  Object.defineProperty(Array.prototype, name, {
@@ -180,6 +427,8 @@ defineArrayMethod("first", first);
180
427
  defineArrayMethod("last", last);
181
428
  defineArrayMethod("unique", unique);
182
429
  defineArrayMethod("chunk", chunk);
430
+ defineArrayMethod("compact", compact);
431
+ defineArrayMethod("compactMap", compactMap);
183
432
  defineArrayMethod("random", random);
184
433
  defineArrayMethod("keyValueMap", keyValueMap);
185
434
  defineArrayMethod("sum", sum);
@@ -187,4 +436,17 @@ defineArrayMethod("avg", avg);
187
436
  defineArrayMethod("max", max);
188
437
  defineArrayMethod("min", min);
189
438
  defineArrayMethod("shuffle", shuffle);
439
+ defineArrayMethod("groupBy", groupBy);
440
+ defineArrayMethod("flatten", flatten);
441
+ defineArrayMethod("zip", zip);
442
+ defineArrayMethod("partition", partition);
443
+ defineArrayMethod("pluck", pluck);
444
+ defineArrayMethod("countBy", countBy);
445
+ defineArrayMethod("difference", difference);
446
+ defineArrayMethod("intersection", intersection);
447
+ defineArrayMethod("union", union);
448
+ defineArrayMethod("uniqBy", uniqBy);
449
+ defineArrayMethod("sortBy", sortBy);
450
+ defineArrayMethod("sample", sample);
451
+ defineArrayMethod("pad", pad);
190
452
  //# sourceMappingURL=auto.mjs.map