es-toolkit 1.29.0 → 1.30.0-dev.963

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 (131) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/_chunk/{rangeRight-w3WrXN.js → range-HnEIT7.js} +0 -17
  3. package/dist/_chunk/{zipWith-Bb2eZI.js → zipWith-nbzldx.js} +11 -10
  4. package/dist/array/index.d.mts +1 -0
  5. package/dist/array/index.d.ts +1 -0
  6. package/dist/array/index.js +12 -2
  7. package/dist/array/index.mjs +1 -0
  8. package/dist/array/pull.d.mts +19 -0
  9. package/dist/array/pull.d.ts +19 -0
  10. package/dist/array/pull.mjs +11 -0
  11. package/dist/browser.global.js +1 -1
  12. package/dist/browser.global.js.map +1 -1
  13. package/dist/compat/_internal/isIndex.mjs +2 -2
  14. package/dist/compat/_internal/isPrototype.mjs +1 -1
  15. package/dist/compat/array/differenceWith.d.mts +91 -0
  16. package/dist/compat/array/differenceWith.d.ts +91 -0
  17. package/dist/compat/array/differenceWith.mjs +19 -0
  18. package/dist/compat/array/map.d.mts +182 -0
  19. package/dist/compat/array/map.d.ts +182 -0
  20. package/dist/compat/array/map.mjs +21 -0
  21. package/dist/compat/array/nth.d.mts +14 -0
  22. package/dist/compat/array/nth.d.ts +14 -0
  23. package/dist/compat/array/nth.mjs +15 -0
  24. package/dist/compat/array/pull.d.mts +19 -0
  25. package/dist/compat/array/pull.d.ts +19 -0
  26. package/dist/compat/array/pull.mjs +8 -0
  27. package/dist/compat/array/takeRightWhile.d.mts +84 -0
  28. package/dist/compat/array/takeRightWhile.d.ts +84 -0
  29. package/dist/compat/array/takeRightWhile.mjs +15 -0
  30. package/dist/compat/function/after.d.mts +31 -0
  31. package/dist/compat/function/after.d.ts +31 -0
  32. package/dist/compat/function/after.mjs +15 -0
  33. package/dist/compat/function/delay.d.mts +29 -0
  34. package/dist/compat/function/delay.d.ts +29 -0
  35. package/dist/compat/function/delay.mjs +10 -0
  36. package/dist/compat/function/nthArg.d.mts +22 -0
  37. package/dist/compat/function/nthArg.d.ts +22 -0
  38. package/dist/compat/function/nthArg.mjs +9 -0
  39. package/dist/compat/index.d.mts +30 -12
  40. package/dist/compat/index.d.ts +30 -12
  41. package/dist/compat/index.js +369 -49
  42. package/dist/compat/index.mjs +31 -12
  43. package/dist/compat/math/range.d.mts +47 -0
  44. package/dist/compat/math/range.d.ts +47 -0
  45. package/dist/compat/math/range.mjs +26 -0
  46. package/dist/compat/math/rangeRight.d.mts +47 -0
  47. package/dist/compat/math/rangeRight.d.ts +47 -0
  48. package/dist/compat/math/rangeRight.mjs +26 -0
  49. package/dist/compat/math/sumBy.d.mts +2 -2
  50. package/dist/compat/math/sumBy.d.ts +2 -2
  51. package/dist/compat/object/findKey.d.mts +58 -0
  52. package/dist/compat/object/findKey.d.ts +58 -0
  53. package/dist/compat/object/findKey.mjs +30 -0
  54. package/dist/compat/object/keys.d.mts +22 -0
  55. package/dist/compat/object/keys.d.ts +22 -0
  56. package/dist/compat/object/keys.mjs +32 -0
  57. package/dist/compat/object/propertyOf.d.mts +22 -0
  58. package/dist/compat/object/propertyOf.d.ts +22 -0
  59. package/dist/compat/object/propertyOf.mjs +9 -0
  60. package/dist/compat/predicate/isArrayLike.d.mts +1 -1
  61. package/dist/compat/predicate/isArrayLike.d.ts +1 -1
  62. package/dist/compat/predicate/isArrayLikeObject.d.mts +1 -1
  63. package/dist/compat/predicate/isArrayLikeObject.d.ts +1 -1
  64. package/dist/compat/predicate/isElement.d.mts +1 -1
  65. package/dist/compat/predicate/isElement.d.ts +1 -1
  66. package/dist/compat/predicate/isFinite.d.mts +1 -1
  67. package/dist/compat/predicate/isFinite.d.ts +1 -1
  68. package/dist/compat/predicate/isNaN.d.mts +1 -1
  69. package/dist/compat/predicate/isNaN.d.ts +1 -1
  70. package/dist/compat/predicate/isObject.d.mts +1 -1
  71. package/dist/compat/predicate/isObject.d.ts +1 -1
  72. package/dist/compat/predicate/isObjectLike.d.mts +1 -1
  73. package/dist/compat/predicate/isObjectLike.d.ts +1 -1
  74. package/dist/compat/string/deburr.d.mts +22 -0
  75. package/dist/compat/string/deburr.d.ts +22 -0
  76. package/dist/compat/string/deburr.mjs +8 -0
  77. package/dist/compat/string/escapeRegExp.d.mts +14 -0
  78. package/dist/compat/string/escapeRegExp.d.ts +14 -0
  79. package/dist/compat/string/escapeRegExp.mjs +8 -0
  80. package/dist/compat/string/lowerFirst.d.mts +14 -0
  81. package/dist/compat/string/lowerFirst.d.ts +14 -0
  82. package/dist/compat/string/lowerFirst.mjs +8 -0
  83. package/dist/compat/string/toLower.d.mts +20 -0
  84. package/dist/compat/string/toLower.d.ts +20 -0
  85. package/dist/compat/string/toLower.mjs +7 -0
  86. package/dist/compat/string/unescape.d.mts +16 -0
  87. package/dist/compat/string/unescape.d.ts +16 -0
  88. package/dist/compat/string/unescape.mjs +8 -0
  89. package/dist/compat/string/upperFirst.d.mts +14 -0
  90. package/dist/compat/string/upperFirst.d.ts +14 -0
  91. package/dist/compat/string/upperFirst.mjs +8 -0
  92. package/dist/compat/util/invoke.d.mts +23 -0
  93. package/dist/compat/util/invoke.d.ts +23 -0
  94. package/dist/compat/util/invoke.mjs +48 -0
  95. package/dist/compat/util/lt.d.mts +15 -0
  96. package/dist/compat/util/lt.d.ts +15 -0
  97. package/dist/compat/util/lt.mjs +10 -0
  98. package/dist/compat/util/lte.d.mts +15 -0
  99. package/dist/compat/util/lte.d.ts +15 -0
  100. package/dist/compat/util/lte.mjs +10 -0
  101. package/dist/compat/util/method.d.mts +22 -0
  102. package/dist/compat/util/method.d.ts +22 -0
  103. package/dist/compat/util/method.mjs +9 -0
  104. package/dist/compat/util/now.d.mts +18 -0
  105. package/dist/compat/util/now.d.ts +18 -0
  106. package/dist/compat/util/now.mjs +5 -0
  107. package/dist/compat/util/stubArray.d.mts +10 -0
  108. package/dist/compat/util/stubArray.d.ts +10 -0
  109. package/dist/compat/util/stubArray.mjs +5 -0
  110. package/dist/compat/util/stubFalse.d.mts +10 -0
  111. package/dist/compat/util/stubFalse.d.ts +10 -0
  112. package/dist/compat/util/stubFalse.mjs +5 -0
  113. package/dist/compat/util/stubObject.d.mts +10 -0
  114. package/dist/compat/util/stubObject.d.ts +10 -0
  115. package/dist/compat/util/stubObject.mjs +5 -0
  116. package/dist/compat/util/stubString.d.mts +10 -0
  117. package/dist/compat/util/stubString.d.ts +10 -0
  118. package/dist/compat/util/stubString.mjs +5 -0
  119. package/dist/compat/util/stubTrue.d.mts +10 -0
  120. package/dist/compat/util/stubTrue.d.ts +10 -0
  121. package/dist/compat/util/stubTrue.mjs +5 -0
  122. package/dist/compat/util/toArray.mjs +0 -3
  123. package/dist/compat/util/toPlainObject.d.mts +16 -0
  124. package/dist/compat/util/toPlainObject.d.ts +16 -0
  125. package/dist/compat/util/toPlainObject.mjs +24 -0
  126. package/dist/index.d.mts +1 -0
  127. package/dist/index.d.ts +1 -0
  128. package/dist/index.js +13 -12
  129. package/dist/index.mjs +1 -0
  130. package/dist/math/index.js +26 -10
  131. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
1
  const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
2
- function isIndex(value) {
2
+ function isIndex(value, length = Number.MAX_SAFE_INTEGER) {
3
3
  switch (typeof value) {
4
4
  case 'number': {
5
- return Number.isInteger(value) && value >= 0 && value < Number.MAX_SAFE_INTEGER;
5
+ return Number.isInteger(value) && value >= 0 && value < length;
6
6
  }
7
7
  case 'symbol': {
8
8
  return false;
@@ -1,5 +1,5 @@
1
1
  function isPrototype(value) {
2
- const constructor = value.constructor;
2
+ const constructor = value?.constructor;
3
3
  const prototype = typeof constructor === 'function' ? constructor.prototype : Object.prototype;
4
4
  return value === prototype;
5
5
  }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Computes the difference between the primary array and another array using a comparator function.
3
+ *
4
+ * @template T1, T2
5
+ * @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
6
+ * @param {ArrayLike<T2>} values - The array containing elements to compare with the primary array.
7
+ * @param {(a: T1, b: T2) => boolean} comparator - A function to determine if two elements are considered equal.
8
+ * @returns {T1[]} A new array containing the elements from the primary array that do not match any elements in `values` based on the comparator.
9
+ *
10
+ * @example
11
+ * const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
12
+ * const values = [{ id: 2 }];
13
+ * const comparator = (a, b) => a.id === b.id;
14
+ *
15
+ * const result = differenceWith(array, values, comparator);
16
+ * // result will be [{ id: 1 }, { id: 3 }]
17
+ */
18
+ declare function differenceWith<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, comparator: (a: T1, b: T2) => boolean): T1[];
19
+ /**
20
+ * Computes the difference between the primary array and two arrays using a comparator function.
21
+ *
22
+ * @template T1, T2, T3
23
+ * @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
24
+ * @param {ArrayLike<T2>} values1 - The first array containing elements to compare with the primary array.
25
+ * @param {ArrayLike<T3>} values2 - The second array containing elements to compare with the primary array.
26
+ * @param {(a: T1, b: T2 | T3) => boolean} comparator - A function to determine if two elements are considered equal.
27
+ * @returns {T1[]} A new array containing the elements from the primary array that do not match any elements in `values1` or `values2` based on the comparator.
28
+ *
29
+ * @example
30
+ * const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
31
+ * const values1 = [{ id: 2 }];
32
+ * const values2 = [{ id: 3 }];
33
+ * const comparator = (a, b) => a.id === b.id;
34
+ *
35
+ * const result = differenceWith(array, values1, values2, comparator);
36
+ * // result will be [{ id: 1 }]
37
+ */
38
+ declare function differenceWith<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, comparator: (a: T1, b: T2 | T3) => boolean): T1[];
39
+ /**
40
+ * Computes the difference between the primary array and multiple arrays using a comparator function.
41
+ *
42
+ * @template T1, T2, T3, T4
43
+ * @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
44
+ * @param {ArrayLike<T2>} values1 - The first array containing elements to compare with the primary array.
45
+ * @param {ArrayLike<T3>} values2 - The second array containing elements to compare with the primary array.
46
+ * @param {...Array<ArrayLike<T4> | ((a: T1, b: T2 | T3 | T4) => boolean)>} values - Additional arrays and an optional comparator function to determine if two elements are considered equal.
47
+ * @returns {T1[]} A new array containing the elements from the primary array that do not match any elements
48
+ * in `values1`, `values2`, or subsequent arrays. If a comparator function is provided, it will be used to compare elements;
49
+ * otherwise, [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero) algorithm will be used.
50
+ *
51
+ * @example
52
+ * // Example with comparator function
53
+ * const array = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
54
+ * const values1 = [{ id: 2 }];
55
+ * const values2 = [{ id: 3 }];
56
+ * const values3 = [{ id: 4 }];
57
+ * const comparator = (a, b) => a.id === b.id;
58
+ *
59
+ * const result = differenceWith(array, values1, values2, values3, comparator);
60
+ * // result will be [{ id: 1 }]
61
+ *
62
+ * @example
63
+ * // Example without comparator function (behaves like `difference`)
64
+ * const array = [1, 2, 3, 4];
65
+ * const values1 = [2];
66
+ * const values2 = [3];
67
+ * const values3 = [4];
68
+ *
69
+ * const result = differenceWith(array, values1, values2, values3);
70
+ * // result will be [1]
71
+ */
72
+ declare function differenceWith<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, ...values: Array<ArrayLike<T4> | ((a: T1, b: T2 | T3 | T4) => boolean)>): T1[];
73
+ /**
74
+ * Computes the difference between the primary array and one or more arrays without using a comparator function.
75
+ *
76
+ * @template T
77
+ * @param {ArrayLike<T> | null | undefined} array - The primary array to compare elements against.
78
+ * @param {...Array<ArrayLike<T>>} values - One or more arrays containing elements to compare with the primary array.
79
+ * @returns {T[]} A new array containing the elements from the primary array that do not match any elements in the provided arrays.
80
+ *
81
+ * @example
82
+ * const array = [1, 2, 3];
83
+ * const values1 = [2];
84
+ * const values2 = [3];
85
+ *
86
+ * const result = differenceWith(array, values1, values2);
87
+ * // result will be [1]
88
+ */
89
+ declare function differenceWith<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
90
+
91
+ export { differenceWith };
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Computes the difference between the primary array and another array using a comparator function.
3
+ *
4
+ * @template T1, T2
5
+ * @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
6
+ * @param {ArrayLike<T2>} values - The array containing elements to compare with the primary array.
7
+ * @param {(a: T1, b: T2) => boolean} comparator - A function to determine if two elements are considered equal.
8
+ * @returns {T1[]} A new array containing the elements from the primary array that do not match any elements in `values` based on the comparator.
9
+ *
10
+ * @example
11
+ * const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
12
+ * const values = [{ id: 2 }];
13
+ * const comparator = (a, b) => a.id === b.id;
14
+ *
15
+ * const result = differenceWith(array, values, comparator);
16
+ * // result will be [{ id: 1 }, { id: 3 }]
17
+ */
18
+ declare function differenceWith<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, comparator: (a: T1, b: T2) => boolean): T1[];
19
+ /**
20
+ * Computes the difference between the primary array and two arrays using a comparator function.
21
+ *
22
+ * @template T1, T2, T3
23
+ * @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
24
+ * @param {ArrayLike<T2>} values1 - The first array containing elements to compare with the primary array.
25
+ * @param {ArrayLike<T3>} values2 - The second array containing elements to compare with the primary array.
26
+ * @param {(a: T1, b: T2 | T3) => boolean} comparator - A function to determine if two elements are considered equal.
27
+ * @returns {T1[]} A new array containing the elements from the primary array that do not match any elements in `values1` or `values2` based on the comparator.
28
+ *
29
+ * @example
30
+ * const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
31
+ * const values1 = [{ id: 2 }];
32
+ * const values2 = [{ id: 3 }];
33
+ * const comparator = (a, b) => a.id === b.id;
34
+ *
35
+ * const result = differenceWith(array, values1, values2, comparator);
36
+ * // result will be [{ id: 1 }]
37
+ */
38
+ declare function differenceWith<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, comparator: (a: T1, b: T2 | T3) => boolean): T1[];
39
+ /**
40
+ * Computes the difference between the primary array and multiple arrays using a comparator function.
41
+ *
42
+ * @template T1, T2, T3, T4
43
+ * @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
44
+ * @param {ArrayLike<T2>} values1 - The first array containing elements to compare with the primary array.
45
+ * @param {ArrayLike<T3>} values2 - The second array containing elements to compare with the primary array.
46
+ * @param {...Array<ArrayLike<T4> | ((a: T1, b: T2 | T3 | T4) => boolean)>} values - Additional arrays and an optional comparator function to determine if two elements are considered equal.
47
+ * @returns {T1[]} A new array containing the elements from the primary array that do not match any elements
48
+ * in `values1`, `values2`, or subsequent arrays. If a comparator function is provided, it will be used to compare elements;
49
+ * otherwise, [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero) algorithm will be used.
50
+ *
51
+ * @example
52
+ * // Example with comparator function
53
+ * const array = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
54
+ * const values1 = [{ id: 2 }];
55
+ * const values2 = [{ id: 3 }];
56
+ * const values3 = [{ id: 4 }];
57
+ * const comparator = (a, b) => a.id === b.id;
58
+ *
59
+ * const result = differenceWith(array, values1, values2, values3, comparator);
60
+ * // result will be [{ id: 1 }]
61
+ *
62
+ * @example
63
+ * // Example without comparator function (behaves like `difference`)
64
+ * const array = [1, 2, 3, 4];
65
+ * const values1 = [2];
66
+ * const values2 = [3];
67
+ * const values3 = [4];
68
+ *
69
+ * const result = differenceWith(array, values1, values2, values3);
70
+ * // result will be [1]
71
+ */
72
+ declare function differenceWith<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, ...values: Array<ArrayLike<T4> | ((a: T1, b: T2 | T3 | T4) => boolean)>): T1[];
73
+ /**
74
+ * Computes the difference between the primary array and one or more arrays without using a comparator function.
75
+ *
76
+ * @template T
77
+ * @param {ArrayLike<T> | null | undefined} array - The primary array to compare elements against.
78
+ * @param {...Array<ArrayLike<T>>} values - One or more arrays containing elements to compare with the primary array.
79
+ * @returns {T[]} A new array containing the elements from the primary array that do not match any elements in the provided arrays.
80
+ *
81
+ * @example
82
+ * const array = [1, 2, 3];
83
+ * const values1 = [2];
84
+ * const values2 = [3];
85
+ *
86
+ * const result = differenceWith(array, values1, values2);
87
+ * // result will be [1]
88
+ */
89
+ declare function differenceWith<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
90
+
91
+ export { differenceWith };
@@ -0,0 +1,19 @@
1
+ import { last } from './last.mjs';
2
+ import { difference } from '../../array/difference.mjs';
3
+ import { differenceWith as differenceWith$1 } from '../../array/differenceWith.mjs';
4
+ import { flattenArrayLike } from '../_internal/flattenArrayLike.mjs';
5
+ import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
6
+
7
+ function differenceWith(array, ...values) {
8
+ if (!isArrayLikeObject(array)) {
9
+ return [];
10
+ }
11
+ const comparator = last(values);
12
+ const flattenedValues = flattenArrayLike(values);
13
+ if (typeof comparator === 'function') {
14
+ return differenceWith$1(Array.from(array), flattenedValues, comparator);
15
+ }
16
+ return difference(Array.from(array), flattenedValues);
17
+ }
18
+
19
+ export { differenceWith };
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Maps each element in a readonly array to a new array of values using an iteratee function.
3
+ *
4
+ * @param {readonly T[]} collection - The collection to iterate over.
5
+ * @param {(value: T, index: number, collection: readonly T[]) => U} iteratee - The function invoked per iteration.
6
+ * @returns {U[]} - Returns the new mapped array.
7
+ *
8
+ * @example
9
+ * const array = [1, 2, 3];
10
+ * map(array, value => value * 2); // => [2, 4, 6]
11
+ */
12
+ declare function map<T, U>(collection: readonly T[], iteratee: (value: T, index: number, collection: readonly T[]) => U): U[];
13
+ /**
14
+ * Maps each element in a readonly array to a boolean array based on a partial object match.
15
+ *
16
+ * @param {readonly T[]} collection - The collection to iterate over.
17
+ * @param {Partial<T>} iteratee - The partial object to match against each element.
18
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
19
+ *
20
+ * @example
21
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
22
+ * map(objects, { a: 1 }); // => [true, false, false]
23
+ */
24
+ declare function map<T>(collection: readonly T[], iteratee: Partial<T>): boolean[];
25
+ /**
26
+ * Maps each element in a readonly array to a boolean array based on a property-value pair match.
27
+ *
28
+ * @param {readonly T[]} collection - The collection to iterate over.
29
+ * @param {[keyof T, unknown]} iteratee - The property-value pair to match against each element.
30
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
31
+ *
32
+ * @example
33
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
34
+ * map(objects, ['a', 1]); // => [true, false, false]
35
+ */
36
+ declare function map<T>(collection: readonly T[], iteratee: [keyof T, unknown]): boolean[];
37
+ /**
38
+ * Maps each element in a readonly array to an array of property values.
39
+ *
40
+ * @param {readonly T[]} collection - The collection to iterate over.
41
+ * @param {K} iteratee - The key of the property to extract from each element.
42
+ * @returns {Array<T[K]>} - Returns an array of property values.
43
+ *
44
+ * @example
45
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
46
+ * map(objects, 'a'); // => [1, 2, 3]
47
+ */
48
+ declare function map<T, K extends keyof T>(collection: readonly T[], iteratee: K): Array<T[K]>;
49
+ /**
50
+ * Maps each element in a readonly array to itself if no iteratee is provided.
51
+ *
52
+ * @param {readonly T[]} collection - The collection to iterate over.
53
+ * @param {null | undefined} [iteratee] - Optional iteratee.
54
+ * @returns {T[]} - Returns the original array.
55
+ *
56
+ * @example
57
+ * const numbers = [1, 2, 3];
58
+ * map(numbers); // => [1, 2, 3]
59
+ */
60
+ declare function map<T>(collection: readonly T[], iteratee?: null | undefined): T[];
61
+ /**
62
+ * Maps each element in an ArrayLike object to a new array of values using an iteratee function.
63
+ *
64
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
65
+ * @param {(value: T, index: number, collection: ArrayLike<T>) => U} iteratee - The function invoked per iteration.
66
+ * @returns {U[]} - Returns the new mapped array.
67
+ *
68
+ * @example
69
+ * const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
70
+ * map(arrayLike, value => value * 2); // => [2, 4, 6]
71
+ */
72
+ declare function map<T, U>(collection: ArrayLike<T>, iteratee: (value: T, index: number, collection: ArrayLike<T>) => U): U[];
73
+ /**
74
+ * Maps each element in an ArrayLike object to a boolean array based on a partial object match.
75
+ *
76
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
77
+ * @param {Partial<T>} iteratee - The partial object to match against each element.
78
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
79
+ *
80
+ * @example
81
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
82
+ * map(arrayLike, { a: 1 }); // => [true, false, false]
83
+ */
84
+ declare function map<T>(collection: ArrayLike<T>, iteratee: Partial<T>): boolean[];
85
+ /**
86
+ * Maps each element in an ArrayLike object to a boolean array based on a property-value pair match.
87
+ *
88
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
89
+ * @param {[keyof T, unknown]} iteratee - The property-value pair to match against each element.
90
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
91
+ *
92
+ * @example
93
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
94
+ * map(arrayLike, ['a', 1]); // => [true, false, false]
95
+ */
96
+ declare function map<T>(collection: ArrayLike<T>, iteratee: [keyof T, unknown]): boolean[];
97
+ /**
98
+ * Maps each element in an ArrayLike object to an array of property values.
99
+ *
100
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
101
+ * @param {K} iteratee - The key of the property to extract from each element.
102
+ * @returns {Array<T[K]>} - Returns an array of property values.
103
+ *
104
+ * @example
105
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
106
+ * map(arrayLike, 'a'); // => [1, 2, 3]
107
+ */
108
+ declare function map<T, K extends keyof T>(collection: ArrayLike<T>, iteratee: K): Array<T[K]>;
109
+ /**
110
+ * Maps each element in an ArrayLike object to itself if no iteratee is provided.
111
+ *
112
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
113
+ * @param {null | undefined} [iteratee] - Optional iteratee.
114
+ * @returns {ArrayLike<T>} - Returns the original ArrayLike object.
115
+ *
116
+ * @example
117
+ * const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
118
+ * map(arrayLike); // => {0: 1, 1: 2, 2: 3, length: 3}
119
+ */
120
+ declare function map<T, U>(collection: ArrayLike<T>, iteratee?: null | undefined): ArrayLike<T>;
121
+ /**
122
+ * Maps each value in an object to a new array of values using an iteratee function.
123
+ *
124
+ * @param {T} collection - The object to iterate over.
125
+ * @param {(value: T[keyof T], key: string, collection: T) => U} iteratee - The function invoked per iteration.
126
+ * @returns {U[]} - Returns the new mapped array.
127
+ *
128
+ * @example
129
+ * const obj = { a: 1, b: 2, c: 3 };
130
+ * map(obj, (value, key) => `${key}: ${value}`); // => ['a: 1', 'b: 2', 'c: 3']
131
+ */
132
+ declare function map<T extends object, U>(collection: T, iteratee: (value: T[keyof T], key: string, collection: T) => U): U[];
133
+ /**
134
+ * Maps each value in an object to a boolean array based on a partial object match.
135
+ *
136
+ * @param {T} object - The object to iterate over.
137
+ * @param {Partial<T[keyof T]>} iteratee - The partial object to match against each value.
138
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
139
+ *
140
+ * @example
141
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
142
+ * map(obj, { x: 1 }); // => [true, false, false]
143
+ */
144
+ declare function map<T>(object: T, iteratee: Partial<T[keyof T]>): boolean[];
145
+ /**
146
+ * Maps each value in an object to a boolean array based on a property-value pair match.
147
+ *
148
+ * @param {T} object - The object to iterate over.
149
+ * @param {[keyof T[keyof T], unknown]} iteratee - The property-value pair to match against each value.
150
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
151
+ *
152
+ * @example
153
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
154
+ * map(obj, ['x', 1]); // => [true, false, false]
155
+ */
156
+ declare function map<T>(object: T, iteratee: [keyof T[keyof T], unknown]): boolean[];
157
+ /**
158
+ * Maps each value in an object to an array of property values.
159
+ *
160
+ * @param {T} object - The object to iterate over.
161
+ * @param {K} iteratee - The key of the property to extract from each value.
162
+ * @returns {Array<T[keyof T][K]>} - Returns an array of property values.
163
+ *
164
+ * @example
165
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
166
+ * map(obj, 'x'); // => [1, 2, 3]
167
+ */
168
+ declare function map<T, K extends keyof T[keyof T]>(object: T, iteratee: K): Array<T[keyof T][K]>;
169
+ /**
170
+ * Maps each value in an object to itself if no iteratee is provided.
171
+ *
172
+ * @param {T} object - The object to iterate over.
173
+ * @param {null | undefined} [iteratee] - Optional iteratee.
174
+ * @returns {U[]} - Returns the original object values as an array.
175
+ *
176
+ * @example
177
+ * const obj = { a: 1, b: 2, c: 3 };
178
+ * map(obj); // => [1, 2, 3]
179
+ */
180
+ declare function map<T extends object, U>(object: T, iteratee?: null | undefined): U[];
181
+
182
+ export { map };
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Maps each element in a readonly array to a new array of values using an iteratee function.
3
+ *
4
+ * @param {readonly T[]} collection - The collection to iterate over.
5
+ * @param {(value: T, index: number, collection: readonly T[]) => U} iteratee - The function invoked per iteration.
6
+ * @returns {U[]} - Returns the new mapped array.
7
+ *
8
+ * @example
9
+ * const array = [1, 2, 3];
10
+ * map(array, value => value * 2); // => [2, 4, 6]
11
+ */
12
+ declare function map<T, U>(collection: readonly T[], iteratee: (value: T, index: number, collection: readonly T[]) => U): U[];
13
+ /**
14
+ * Maps each element in a readonly array to a boolean array based on a partial object match.
15
+ *
16
+ * @param {readonly T[]} collection - The collection to iterate over.
17
+ * @param {Partial<T>} iteratee - The partial object to match against each element.
18
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
19
+ *
20
+ * @example
21
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
22
+ * map(objects, { a: 1 }); // => [true, false, false]
23
+ */
24
+ declare function map<T>(collection: readonly T[], iteratee: Partial<T>): boolean[];
25
+ /**
26
+ * Maps each element in a readonly array to a boolean array based on a property-value pair match.
27
+ *
28
+ * @param {readonly T[]} collection - The collection to iterate over.
29
+ * @param {[keyof T, unknown]} iteratee - The property-value pair to match against each element.
30
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
31
+ *
32
+ * @example
33
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
34
+ * map(objects, ['a', 1]); // => [true, false, false]
35
+ */
36
+ declare function map<T>(collection: readonly T[], iteratee: [keyof T, unknown]): boolean[];
37
+ /**
38
+ * Maps each element in a readonly array to an array of property values.
39
+ *
40
+ * @param {readonly T[]} collection - The collection to iterate over.
41
+ * @param {K} iteratee - The key of the property to extract from each element.
42
+ * @returns {Array<T[K]>} - Returns an array of property values.
43
+ *
44
+ * @example
45
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
46
+ * map(objects, 'a'); // => [1, 2, 3]
47
+ */
48
+ declare function map<T, K extends keyof T>(collection: readonly T[], iteratee: K): Array<T[K]>;
49
+ /**
50
+ * Maps each element in a readonly array to itself if no iteratee is provided.
51
+ *
52
+ * @param {readonly T[]} collection - The collection to iterate over.
53
+ * @param {null | undefined} [iteratee] - Optional iteratee.
54
+ * @returns {T[]} - Returns the original array.
55
+ *
56
+ * @example
57
+ * const numbers = [1, 2, 3];
58
+ * map(numbers); // => [1, 2, 3]
59
+ */
60
+ declare function map<T>(collection: readonly T[], iteratee?: null | undefined): T[];
61
+ /**
62
+ * Maps each element in an ArrayLike object to a new array of values using an iteratee function.
63
+ *
64
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
65
+ * @param {(value: T, index: number, collection: ArrayLike<T>) => U} iteratee - The function invoked per iteration.
66
+ * @returns {U[]} - Returns the new mapped array.
67
+ *
68
+ * @example
69
+ * const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
70
+ * map(arrayLike, value => value * 2); // => [2, 4, 6]
71
+ */
72
+ declare function map<T, U>(collection: ArrayLike<T>, iteratee: (value: T, index: number, collection: ArrayLike<T>) => U): U[];
73
+ /**
74
+ * Maps each element in an ArrayLike object to a boolean array based on a partial object match.
75
+ *
76
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
77
+ * @param {Partial<T>} iteratee - The partial object to match against each element.
78
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
79
+ *
80
+ * @example
81
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
82
+ * map(arrayLike, { a: 1 }); // => [true, false, false]
83
+ */
84
+ declare function map<T>(collection: ArrayLike<T>, iteratee: Partial<T>): boolean[];
85
+ /**
86
+ * Maps each element in an ArrayLike object to a boolean array based on a property-value pair match.
87
+ *
88
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
89
+ * @param {[keyof T, unknown]} iteratee - The property-value pair to match against each element.
90
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
91
+ *
92
+ * @example
93
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
94
+ * map(arrayLike, ['a', 1]); // => [true, false, false]
95
+ */
96
+ declare function map<T>(collection: ArrayLike<T>, iteratee: [keyof T, unknown]): boolean[];
97
+ /**
98
+ * Maps each element in an ArrayLike object to an array of property values.
99
+ *
100
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
101
+ * @param {K} iteratee - The key of the property to extract from each element.
102
+ * @returns {Array<T[K]>} - Returns an array of property values.
103
+ *
104
+ * @example
105
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
106
+ * map(arrayLike, 'a'); // => [1, 2, 3]
107
+ */
108
+ declare function map<T, K extends keyof T>(collection: ArrayLike<T>, iteratee: K): Array<T[K]>;
109
+ /**
110
+ * Maps each element in an ArrayLike object to itself if no iteratee is provided.
111
+ *
112
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
113
+ * @param {null | undefined} [iteratee] - Optional iteratee.
114
+ * @returns {ArrayLike<T>} - Returns the original ArrayLike object.
115
+ *
116
+ * @example
117
+ * const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
118
+ * map(arrayLike); // => {0: 1, 1: 2, 2: 3, length: 3}
119
+ */
120
+ declare function map<T, U>(collection: ArrayLike<T>, iteratee?: null | undefined): ArrayLike<T>;
121
+ /**
122
+ * Maps each value in an object to a new array of values using an iteratee function.
123
+ *
124
+ * @param {T} collection - The object to iterate over.
125
+ * @param {(value: T[keyof T], key: string, collection: T) => U} iteratee - The function invoked per iteration.
126
+ * @returns {U[]} - Returns the new mapped array.
127
+ *
128
+ * @example
129
+ * const obj = { a: 1, b: 2, c: 3 };
130
+ * map(obj, (value, key) => `${key}: ${value}`); // => ['a: 1', 'b: 2', 'c: 3']
131
+ */
132
+ declare function map<T extends object, U>(collection: T, iteratee: (value: T[keyof T], key: string, collection: T) => U): U[];
133
+ /**
134
+ * Maps each value in an object to a boolean array based on a partial object match.
135
+ *
136
+ * @param {T} object - The object to iterate over.
137
+ * @param {Partial<T[keyof T]>} iteratee - The partial object to match against each value.
138
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
139
+ *
140
+ * @example
141
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
142
+ * map(obj, { x: 1 }); // => [true, false, false]
143
+ */
144
+ declare function map<T>(object: T, iteratee: Partial<T[keyof T]>): boolean[];
145
+ /**
146
+ * Maps each value in an object to a boolean array based on a property-value pair match.
147
+ *
148
+ * @param {T} object - The object to iterate over.
149
+ * @param {[keyof T[keyof T], unknown]} iteratee - The property-value pair to match against each value.
150
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
151
+ *
152
+ * @example
153
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
154
+ * map(obj, ['x', 1]); // => [true, false, false]
155
+ */
156
+ declare function map<T>(object: T, iteratee: [keyof T[keyof T], unknown]): boolean[];
157
+ /**
158
+ * Maps each value in an object to an array of property values.
159
+ *
160
+ * @param {T} object - The object to iterate over.
161
+ * @param {K} iteratee - The key of the property to extract from each value.
162
+ * @returns {Array<T[keyof T][K]>} - Returns an array of property values.
163
+ *
164
+ * @example
165
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
166
+ * map(obj, 'x'); // => [1, 2, 3]
167
+ */
168
+ declare function map<T, K extends keyof T[keyof T]>(object: T, iteratee: K): Array<T[keyof T][K]>;
169
+ /**
170
+ * Maps each value in an object to itself if no iteratee is provided.
171
+ *
172
+ * @param {T} object - The object to iterate over.
173
+ * @param {null | undefined} [iteratee] - Optional iteratee.
174
+ * @returns {U[]} - Returns the original object values as an array.
175
+ *
176
+ * @example
177
+ * const obj = { a: 1, b: 2, c: 3 };
178
+ * map(obj); // => [1, 2, 3]
179
+ */
180
+ declare function map<T extends object, U>(object: T, iteratee?: null | undefined): U[];
181
+
182
+ export { map };
@@ -0,0 +1,21 @@
1
+ import { identity } from '../../function/identity.mjs';
2
+ import { range } from '../../math/range.mjs';
3
+ import { isArrayLike } from '../predicate/isArrayLike.mjs';
4
+ import { iteratee } from '../util/iteratee.mjs';
5
+
6
+ function map(collection, _iteratee) {
7
+ if (!collection) {
8
+ return [];
9
+ }
10
+ const keys = isArrayLike(collection) || Array.isArray(collection) ? range(0, collection.length) : Object.keys(collection);
11
+ const iteratee$1 = iteratee(_iteratee ?? identity);
12
+ const result = new Array(keys.length);
13
+ for (let i = 0; i < keys.length; i++) {
14
+ const key = keys[i];
15
+ const value = collection[key];
16
+ result[i] = iteratee$1(value, key, collection);
17
+ }
18
+ return result;
19
+ }
20
+
21
+ export { map };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Gets the element at index `n` of `array`. If `n` is negative, the nth element from the end is returned.
3
+ *
4
+ * @param {ArrayLike<T> | null | undefined} array - The array to query.
5
+ * @param {number} [n=0] - The index of the element to return.
6
+ * @return {T | undefined} Returns the nth element of `array`.
7
+ *
8
+ * @example
9
+ * nth([1, 2, 3], 1); // => 2
10
+ * nth([1, 2, 3], -1); // => 3
11
+ */
12
+ declare function nth<T>(array: ArrayLike<T> | null | undefined, n?: number): T | undefined;
13
+
14
+ export { nth };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Gets the element at index `n` of `array`. If `n` is negative, the nth element from the end is returned.
3
+ *
4
+ * @param {ArrayLike<T> | null | undefined} array - The array to query.
5
+ * @param {number} [n=0] - The index of the element to return.
6
+ * @return {T | undefined} Returns the nth element of `array`.
7
+ *
8
+ * @example
9
+ * nth([1, 2, 3], 1); // => 2
10
+ * nth([1, 2, 3], -1); // => 3
11
+ */
12
+ declare function nth<T>(array: ArrayLike<T> | null | undefined, n?: number): T | undefined;
13
+
14
+ export { nth };
@@ -0,0 +1,15 @@
1
+ import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
2
+ import { toInteger } from '../util/toInteger.mjs';
3
+
4
+ function nth(array, n = 0) {
5
+ if (!isArrayLikeObject(array) || array.length === 0) {
6
+ return undefined;
7
+ }
8
+ n = toInteger(n);
9
+ if (n < 0) {
10
+ n += array.length;
11
+ }
12
+ return array[n];
13
+ }
14
+
15
+ export { nth };