@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/index.cjs CHANGED
@@ -62,6 +62,30 @@ function _chunk (size) {
62
62
  return out;
63
63
  }
64
64
 
65
+ /**
66
+ * Removes falsy values from the array.
67
+ * @returns A new array without falsy values.
68
+ */
69
+ function _compact () {
70
+ return this.filter((value) => Boolean(value));
71
+ }
72
+
73
+ /**
74
+ * Maps items and removes null/undefined results.
75
+ * @param mapper Function to map items.
76
+ * @returns A new array of mapped values without null/undefined.
77
+ */
78
+ function _compactMap (mapper) {
79
+ const out = [];
80
+ for (let index = 0; index < this.length; index++) {
81
+ const value = mapper(this[index], index, this);
82
+ if (value !== null && value !== undefined) {
83
+ out.push(value);
84
+ }
85
+ }
86
+ return out;
87
+ }
88
+
65
89
  /**
66
90
  * @returns a random element from the array, or undefined if the array is empty.
67
91
  */
@@ -169,27 +193,281 @@ function shuffle$1() {
169
193
  return this;
170
194
  }
171
195
 
172
- const first = (arr) => _first.apply(arr);
173
- const last = (arr) => _last.apply(arr);
174
- const unique = (arr) => _unique.apply(arr);
175
- const chunk = (arr, size) => _chunk.apply(arr, [size]);
176
- const random = (arr) => _random.apply(arr);
177
- const keyValueMap = (arr, key, value) => _keyValueMap.apply(arr, [key, value]);
178
- const sum = (arr) => _sum.apply(arr);
179
- const avg = (arr) => _avg.apply(arr);
180
- const max = (arr) => _max.apply(arr);
181
- const min = (arr) => _min.apply(arr);
182
- const shuffle = (arr) => shuffle$1.apply(arr);
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
+
419
+ const call = (fn, thisArg, ...args) => fn.apply(thisArg, args);
420
+ const first = (arr) => call(_first, arr);
421
+ const last = (arr) => call(_last, arr);
422
+ const unique = (arr) => call(_unique, arr);
423
+ const chunk = (arr, size) => call(_chunk, arr, size);
424
+ const compact = (arr) => call(_compact, arr);
425
+ const compactMap = (arr, mapper) => call(_compactMap, arr, mapper);
426
+ const random = (arr) => call(_random, arr);
427
+ const keyValueMap = (arr, key, value) => call(_keyValueMap, arr, key, value);
428
+ const sum = (arr) => call(_sum, arr);
429
+ const avg = (arr) => call(_avg, arr);
430
+ const max = (arr) => call(_max, arr);
431
+ const min = (arr) => call(_min, arr);
432
+ const shuffle = (arr) => call(shuffle$1, arr);
433
+ const groupBy = (arr, key) => call(_groupBy, arr, key);
434
+ const flatten = (arr) => call(_flatten, arr);
435
+ const zip = (arr, ...arrays) => call(_zip, arr, ...arrays);
436
+ const partition = (arr, predicate) => call(_partition, arr, predicate);
437
+ const pluck = (arr, key) => call(_pluck, arr, key);
438
+ const countBy = (arr, key) => call(_countBy, arr, key);
439
+ const difference = (arr, ...arrays) => call(_difference, arr, ...arrays);
440
+ const intersection = (arr, ...arrays) => call(_intersection, arr, ...arrays);
441
+ const union = (arr, ...arrays) => call(_union, arr, ...arrays);
442
+ const uniqBy = (arr, key) => call(_uniqBy, arr, key);
443
+ const sortBy = (arr, key) => call(_sortBy, arr, key);
444
+ const sample = (arr, count) => call(_sample, arr, count);
445
+ const pad = (arr, length, value) => call(_pad, arr, length, value);
183
446
 
184
447
  exports.avg = avg;
185
448
  exports.chunk = chunk;
449
+ exports.compact = compact;
450
+ exports.compactMap = compactMap;
451
+ exports.countBy = countBy;
452
+ exports.difference = difference;
186
453
  exports.first = first;
454
+ exports.flatten = flatten;
455
+ exports.groupBy = groupBy;
456
+ exports.intersection = intersection;
187
457
  exports.keyValueMap = keyValueMap;
188
458
  exports.last = last;
189
459
  exports.max = max;
190
460
  exports.min = min;
461
+ exports.pad = pad;
462
+ exports.partition = partition;
463
+ exports.pluck = pluck;
191
464
  exports.random = random;
465
+ exports.sample = sample;
192
466
  exports.shuffle = shuffle;
467
+ exports.sortBy = sortBy;
193
468
  exports.sum = sum;
469
+ exports.union = union;
470
+ exports.uniqBy = uniqBy;
194
471
  exports.unique = unique;
472
+ exports.zip = zip;
195
473
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/functions/first.ts","../src/functions/last.ts","../src/functions/unique.ts","../src/functions/chunk.ts","../src/functions/random.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/index.ts"],"sourcesContent":["/**\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 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* 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 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 * 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 _first from \"./functions/first\";\nimport _last from \"./functions/last\";\nimport _unique from \"./functions/unique\";\nimport _chunk from \"./functions/chunk\";\nimport _random from \"./functions/random\";\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\nexport const first = <T>(arr: T[]): ReturnType<typeof _first> => _first.apply(arr);\nexport const last = <T>(arr: T[]): ReturnType<typeof _last> => _last.apply(arr);\nexport const unique = <T>(arr: T[]): ReturnType<typeof _unique> => _unique.apply(arr);\nexport const chunk = <T>(arr: T[], size: number): ReturnType<typeof _chunk> => _chunk.apply(arr, [size]);\nexport const random = <T>(arr: T[]): ReturnType<typeof _random> => _random.apply(arr);\nexport const keyValueMap = <T>(arr: KeyValueMap[], key: string, value: string): KeyValueMap => _keyValueMap.apply(arr, [key, value]);\nexport const sum = (arr: number[]): ReturnType<typeof _sum> => _sum.apply(arr);\nexport const avg = (arr: number[]): ReturnType<typeof _avg> => _avg.apply(arr);\nexport const max = (arr: number[]): ReturnType<typeof _max> => _max.apply(arr);\nexport const min = (arr: number[]): ReturnType<typeof _min> => _min.apply(arr);\nexport const shuffle = <T>(arr: T[]): ReturnType<typeof _shuffle> => _shuffle.apply(arr);"],"names":["shuffle","_shuffle"],"mappings":";;AAAA;;AAEE;AACY,eAAA,IAAA,EAA2B,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;;ACHnF;;AAEE;AACY,cAAA,IAAA,EAA2B,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;;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,GAAG,CAAI,GAAQ,KAAiC,OAAO,CAAC,KAAK,CAAC,GAAG;MACvE,KAAK,GAAG,CAAI,GAAQ,EAAE,IAAY,KAAgC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;AAChG,MAAM,MAAM,GAAG,CAAI,GAAQ,KAAiC,OAAO,CAAC,KAAK,CAAC,GAAG;AAC7E,MAAM,WAAW,GAAG,CAAI,GAAkB,EAAE,GAAW,EAAE,KAAa,KAAkB,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC;AAC5H,MAAM,GAAG,GAAG,CAAC,GAAa,KAA8B,IAAI,CAAC,KAAK,CAAC,GAAG;AACtE,MAAM,GAAG,GAAG,CAAC,GAAa,KAA8B,IAAI,CAAC,KAAK,CAAC,GAAG;AACtE,MAAM,GAAG,GAAG,CAAC,GAAa,KAA8B,IAAI,CAAC,KAAK,CAAC,GAAG;AACtE,MAAM,GAAG,GAAG,CAAC,GAAa,KAA8B,IAAI,CAAC,KAAK,CAAC,GAAG;AACtE,MAAM,OAAO,GAAG,CAAI,GAAQ,KAAkCC,SAAQ,CAAC,KAAK,CAAC,GAAG;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/functions/first.ts","../src/functions/last.ts","../src/functions/unique.ts","../src/functions/chunk.ts","../src/functions/compact.ts","../src/functions/compactMap.ts","../src/functions/random.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/index.ts"],"sourcesContent":["/**\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 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* 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}","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 * @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 * 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 _first from \"./functions/first\";\nimport _last from \"./functions/last\";\nimport _unique from \"./functions/unique\";\nimport _chunk from \"./functions/chunk\";\nimport _compact from \"./functions/compact\";\nimport _compactMap from \"./functions/compactMap\";\nimport _random from \"./functions/random\";\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\nconst call = <T, A extends unknown[], R>(fn: (this: T, ...args: A) => R, thisArg: T, ...args: A): R =>\n\tfn.apply(thisArg, args);\n\nexport const first = <T>(arr: T[]): ReturnType<typeof _first> => call(_first, arr);\nexport const last = <T>(arr: T[]): ReturnType<typeof _last> => call(_last, arr);\nexport const unique = <T>(arr: T[]): ReturnType<typeof _unique> => call(_unique, arr);\nexport const chunk = <T>(arr: T[], size: number): ReturnType<typeof _chunk> => call(_chunk, arr, size);\nexport const compact = <T>(arr: T[]): ReturnType<typeof _compact> => call(_compact, arr);\nexport const compactMap = <T, R>(\n\tarr: T[],\n\tmapper: (value: T, index: number, arr: T[]) => R\n): ReturnType<typeof _compactMap> => call(_compactMap, arr, mapper);\nexport const random = <T>(arr: T[]): ReturnType<typeof _random> => call(_random, arr);\nexport const keyValueMap = <T>(arr: KeyValueMap[], key: string, value: string): KeyValueMap => call(_keyValueMap, arr, key, value);\nexport const sum = (arr: number[]): ReturnType<typeof _sum> => call(_sum, arr);\nexport const avg = (arr: number[]): ReturnType<typeof _avg> => call(_avg, arr);\nexport const max = (arr: number[]): ReturnType<typeof _max> => call(_max, arr);\nexport const min = (arr: number[]): ReturnType<typeof _min> => call(_min, arr);\nexport const shuffle = <T>(arr: T[]): ReturnType<typeof _shuffle> => call(_shuffle, arr);\nexport const groupBy = <T, K extends PropertyKey>(\n\tarr: T[],\n\tkey: ((item: T, index: number, arr: T[]) => K) | keyof T\n): ReturnType<typeof _groupBy> => call(_groupBy, arr, key);\nexport const flatten = <T>(arr: (T | T[])[]): ReturnType<typeof _flatten> => call(_flatten, arr);\nexport const zip = <T>(arr: T[], ...arrays: any[][]): ReturnType<typeof _zip> => call(_zip, arr, ...arrays);\nexport const partition = <T>(\n\tarr: T[],\n\tpredicate: (value: T, index: number, arr: T[]) => boolean\n): ReturnType<typeof _partition> => call(_partition, arr, predicate);\nexport const pluck = <T, K extends keyof T>(arr: T[], key: K): ReturnType<typeof _pluck> => call(_pluck, arr, key);\nexport const countBy = <T, K extends PropertyKey>(\n\tarr: T[],\n\tkey: ((item: T, index: number, arr: T[]) => K) | keyof T\n): ReturnType<typeof _countBy> => call(_countBy, arr, key);\nexport const difference = <T>(arr: T[], ...arrays: T[][]): ReturnType<typeof _difference> => call(_difference, arr, ...arrays);\nexport const intersection = <T>(arr: T[], ...arrays: T[][]): ReturnType<typeof _intersection> => call(_intersection, arr, ...arrays);\nexport const union = <T>(arr: T[], ...arrays: T[][]): ReturnType<typeof _union> => call(_union, arr, ...arrays);\nexport const uniqBy = <T, K>(\n\tarr: T[],\n\tkey: ((item: T, index: number, arr: T[]) => K) | keyof T\n): ReturnType<typeof _uniqBy> => call(_uniqBy, arr, key);\nexport const sortBy = <T, K extends string | number | bigint>(\n\tarr: T[],\n\tkey: ((item: T, index: number, arr: T[]) => K) | keyof T\n): ReturnType<typeof _sortBy> => call(_sortBy, arr, key);\nexport const sample = <T>(arr: T[], count: number): ReturnType<typeof _sample> => call(_sample, arr, count);\nexport const pad = <T>(arr: T[], length: number, value: T): ReturnType<typeof _pad> => call(_pad, arr, length, value);\n"],"names":["shuffle","_shuffle"],"mappings":";;AAAA;;AAEE;AACY,eAAA,IAAA,EAA2B,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;;ACHnF;;AAEE;AACY,cAAA,IAAA,EAA2B,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;;ACHjG;;;;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,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;AAAE,QAAA,OAAO,KAAK;AAC5F,IAAA,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,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EAAE,GAAG,MAAM;MACtH,KAAK,GAAG,CAAI,GAAQ,EAAE,GAAG,MAAa,KAAgC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM;AACvG,MAAM,MAAM,GAAG,CACrB,GAAQ,EACR,GAAwD,KACxB,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG;AAChD,MAAM,MAAM,GAAG,CACrB,GAAQ,EACR,GAAwD,KACxB,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG;AAChD,MAAM,MAAM,GAAG,CAAI,GAAQ,EAAE,KAAa,KAAiC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK;MAC7F,GAAG,GAAG,CAAI,GAAQ,EAAE,MAAc,EAAE,KAAQ,KAA8B,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -2,16 +2,33 @@ import _first from "./functions/first";
2
2
  import _last from "./functions/last";
3
3
  import _unique from "./functions/unique";
4
4
  import _chunk from "./functions/chunk";
5
+ import _compact from "./functions/compact";
6
+ import _compactMap from "./functions/compactMap";
5
7
  import _random from "./functions/random";
6
8
  import _sum from "./functions/sum";
7
9
  import _avg from "./functions/avg";
8
10
  import _max from "./functions/max";
9
11
  import _min from "./functions/min";
10
12
  import _shuffle from "./functions/shuffle";
13
+ import _groupBy from "./functions/groupBy";
14
+ import _flatten from "./functions/flatten";
15
+ import _zip from "./functions/zip";
16
+ import _partition from "./functions/partition";
17
+ import _pluck from "./functions/pluck";
18
+ import _countBy from "./functions/countBy";
19
+ import _difference from "./functions/difference";
20
+ import _intersection from "./functions/intersection";
21
+ import _union from "./functions/union";
22
+ import _uniqBy from "./functions/uniqBy";
23
+ import _sortBy from "./functions/sortBy";
24
+ import _sample from "./functions/sample";
25
+ import _pad from "./functions/pad";
11
26
  export declare const first: <T>(arr: T[]) => ReturnType<typeof _first>;
12
27
  export declare const last: <T>(arr: T[]) => ReturnType<typeof _last>;
13
28
  export declare const unique: <T>(arr: T[]) => ReturnType<typeof _unique>;
14
29
  export declare const chunk: <T>(arr: T[], size: number) => ReturnType<typeof _chunk>;
30
+ export declare const compact: <T>(arr: T[]) => ReturnType<typeof _compact>;
31
+ export declare const compactMap: <T, R>(arr: T[], mapper: (value: T, index: number, arr: T[]) => R) => ReturnType<typeof _compactMap>;
15
32
  export declare const random: <T>(arr: T[]) => ReturnType<typeof _random>;
16
33
  export declare const keyValueMap: <T>(arr: KeyValueMap[], key: string, value: string) => KeyValueMap;
17
34
  export declare const sum: (arr: number[]) => ReturnType<typeof _sum>;
@@ -19,3 +36,16 @@ export declare const avg: (arr: number[]) => ReturnType<typeof _avg>;
19
36
  export declare const max: (arr: number[]) => ReturnType<typeof _max>;
20
37
  export declare const min: (arr: number[]) => ReturnType<typeof _min>;
21
38
  export declare const shuffle: <T>(arr: T[]) => ReturnType<typeof _shuffle>;
39
+ export declare const groupBy: <T, K extends PropertyKey>(arr: T[], key: ((item: T, index: number, arr: T[]) => K) | keyof T) => ReturnType<typeof _groupBy>;
40
+ export declare const flatten: <T>(arr: (T | T[])[]) => ReturnType<typeof _flatten>;
41
+ export declare const zip: <T>(arr: T[], ...arrays: any[][]) => ReturnType<typeof _zip>;
42
+ export declare const partition: <T>(arr: T[], predicate: (value: T, index: number, arr: T[]) => boolean) => ReturnType<typeof _partition>;
43
+ export declare const pluck: <T, K extends keyof T>(arr: T[], key: K) => ReturnType<typeof _pluck>;
44
+ export declare const countBy: <T, K extends PropertyKey>(arr: T[], key: ((item: T, index: number, arr: T[]) => K) | keyof T) => ReturnType<typeof _countBy>;
45
+ export declare const difference: <T>(arr: T[], ...arrays: T[][]) => ReturnType<typeof _difference>;
46
+ export declare const intersection: <T>(arr: T[], ...arrays: T[][]) => ReturnType<typeof _intersection>;
47
+ export declare const union: <T>(arr: T[], ...arrays: T[][]) => ReturnType<typeof _union>;
48
+ export declare const uniqBy: <T, K>(arr: T[], key: ((item: T, index: number, arr: T[]) => K) | keyof T) => ReturnType<typeof _uniqBy>;
49
+ export declare const sortBy: <T, K extends string | number | bigint>(arr: T[], key: ((item: T, index: number, arr: T[]) => K) | keyof T) => ReturnType<typeof _sortBy>;
50
+ export declare const sample: <T>(arr: T[], count: number) => ReturnType<typeof _sample>;
51
+ export declare const pad: <T>(arr: T[], length: number, value: T) => ReturnType<typeof _pad>;
package/dist/index.js CHANGED
@@ -2,6 +2,8 @@ import _first from "./functions/first";
2
2
  import _last from "./functions/last";
3
3
  import _unique from "./functions/unique";
4
4
  import _chunk from "./functions/chunk";
5
+ import _compact from "./functions/compact";
6
+ import _compactMap from "./functions/compactMap";
5
7
  import _random from "./functions/random";
6
8
  import _keyValueMap from "./functions/keyValueMap";
7
9
  import _sum from "./functions/sum";
@@ -9,14 +11,43 @@ import _avg from "./functions/avg";
9
11
  import _max from "./functions/max";
10
12
  import _min from "./functions/min";
11
13
  import _shuffle from "./functions/shuffle";
12
- export const first = (arr) => _first.apply(arr);
13
- export const last = (arr) => _last.apply(arr);
14
- export const unique = (arr) => _unique.apply(arr);
15
- export const chunk = (arr, size) => _chunk.apply(arr, [size]);
16
- export const random = (arr) => _random.apply(arr);
17
- export const keyValueMap = (arr, key, value) => _keyValueMap.apply(arr, [key, value]);
18
- export const sum = (arr) => _sum.apply(arr);
19
- export const avg = (arr) => _avg.apply(arr);
20
- export const max = (arr) => _max.apply(arr);
21
- export const min = (arr) => _min.apply(arr);
22
- export const shuffle = (arr) => _shuffle.apply(arr);
14
+ import _groupBy from "./functions/groupBy";
15
+ import _flatten from "./functions/flatten";
16
+ import _zip from "./functions/zip";
17
+ import _partition from "./functions/partition";
18
+ import _pluck from "./functions/pluck";
19
+ import _countBy from "./functions/countBy";
20
+ import _difference from "./functions/difference";
21
+ import _intersection from "./functions/intersection";
22
+ import _union from "./functions/union";
23
+ import _uniqBy from "./functions/uniqBy";
24
+ import _sortBy from "./functions/sortBy";
25
+ import _sample from "./functions/sample";
26
+ import _pad from "./functions/pad";
27
+ const call = (fn, thisArg, ...args) => fn.apply(thisArg, args);
28
+ export const first = (arr) => call(_first, arr);
29
+ export const last = (arr) => call(_last, arr);
30
+ export const unique = (arr) => call(_unique, arr);
31
+ export const chunk = (arr, size) => call(_chunk, arr, size);
32
+ export const compact = (arr) => call(_compact, arr);
33
+ export const compactMap = (arr, mapper) => call(_compactMap, arr, mapper);
34
+ export const random = (arr) => call(_random, arr);
35
+ export const keyValueMap = (arr, key, value) => call(_keyValueMap, arr, key, value);
36
+ export const sum = (arr) => call(_sum, arr);
37
+ export const avg = (arr) => call(_avg, arr);
38
+ export const max = (arr) => call(_max, arr);
39
+ export const min = (arr) => call(_min, arr);
40
+ export const shuffle = (arr) => call(_shuffle, arr);
41
+ export const groupBy = (arr, key) => call(_groupBy, arr, key);
42
+ export const flatten = (arr) => call(_flatten, arr);
43
+ export const zip = (arr, ...arrays) => call(_zip, arr, ...arrays);
44
+ export const partition = (arr, predicate) => call(_partition, arr, predicate);
45
+ export const pluck = (arr, key) => call(_pluck, arr, key);
46
+ export const countBy = (arr, key) => call(_countBy, arr, key);
47
+ export const difference = (arr, ...arrays) => call(_difference, arr, ...arrays);
48
+ export const intersection = (arr, ...arrays) => call(_intersection, arr, ...arrays);
49
+ export const union = (arr, ...arrays) => call(_union, arr, ...arrays);
50
+ export const uniqBy = (arr, key) => call(_uniqBy, arr, key);
51
+ export const sortBy = (arr, key) => call(_sortBy, arr, key);
52
+ export const sample = (arr, count) => call(_sample, arr, count);
53
+ export const pad = (arr, length, value) => call(_pad, arr, length, value);