es-toolkit 1.30.1 → 1.31.0-dev.1001

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 (106) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/_chunk/AbortError-Cg4ZQ1.js +10 -0
  3. package/dist/_chunk/delay-_VMfFa.js +25 -0
  4. package/dist/_chunk/isPlainObject-Xaozpc.js +93 -0
  5. package/dist/_chunk/{isWeakSet-CvIdTA.js → isWeakSet-BW79-8.js} +37 -71
  6. package/dist/_chunk/{toMerged-DGFrN7.js → toMerged-BQTfB8.js} +39 -8
  7. package/dist/_chunk/{unary-CcTNuC.js → unary-c1NFA5.js} +38 -0
  8. package/dist/_chunk/{zipWith-nbzldx.js → zipWith-Bdyzuy.js} +47 -4
  9. package/dist/array/at.d.mts +1 -1
  10. package/dist/array/at.d.ts +1 -1
  11. package/dist/array/groupBy.mjs +2 -2
  12. package/dist/array/index.d.mts +2 -0
  13. package/dist/array/index.d.ts +2 -0
  14. package/dist/array/index.js +3 -1
  15. package/dist/array/index.mjs +2 -0
  16. package/dist/array/pull.mjs +9 -2
  17. package/dist/array/pullAt.d.mts +1 -1
  18. package/dist/array/pullAt.d.ts +1 -1
  19. package/dist/array/remove.d.mts +19 -0
  20. package/dist/array/remove.d.ts +19 -0
  21. package/dist/array/remove.mjs +20 -0
  22. package/dist/array/windowed.d.mts +50 -0
  23. package/dist/array/windowed.d.ts +50 -0
  24. package/dist/array/windowed.mjs +16 -0
  25. package/dist/browser.global.js +1 -1
  26. package/dist/browser.global.js.map +1 -1
  27. package/dist/compat/array/find.d.mts +16 -8
  28. package/dist/compat/array/find.d.ts +16 -8
  29. package/dist/compat/array/find.mjs +5 -2
  30. package/dist/compat/array/pull.d.mts +1 -1
  31. package/dist/compat/array/pull.d.ts +1 -1
  32. package/dist/compat/array/pull.mjs +1 -2
  33. package/dist/compat/array/pullAll.d.mts +19 -0
  34. package/dist/compat/array/pullAll.d.ts +19 -0
  35. package/dist/compat/array/pullAll.mjs +7 -0
  36. package/dist/compat/array/remove.d.mts +50 -0
  37. package/dist/compat/array/remove.d.ts +50 -0
  38. package/dist/compat/array/remove.mjs +8 -0
  39. package/dist/compat/array/reverse.d.mts +24 -0
  40. package/dist/compat/array/reverse.d.ts +24 -0
  41. package/dist/compat/array/reverse.mjs +8 -0
  42. package/dist/compat/function/negate.d.mts +16 -0
  43. package/dist/compat/function/negate.d.ts +16 -0
  44. package/dist/compat/function/negate.mjs +10 -0
  45. package/dist/compat/index.d.mts +14 -2
  46. package/dist/compat/index.d.ts +14 -2
  47. package/dist/compat/index.js +114 -41
  48. package/dist/compat/index.mjs +14 -2
  49. package/dist/compat/math/multiply.d.mts +18 -0
  50. package/dist/compat/math/multiply.d.ts +18 -0
  51. package/dist/compat/math/multiply.mjs +21 -0
  52. package/dist/compat/math/subtract.d.mts +17 -0
  53. package/dist/compat/math/subtract.d.ts +17 -0
  54. package/dist/compat/math/subtract.mjs +5 -0
  55. package/dist/compat/object/mergeWith.mjs +6 -2
  56. package/dist/compat/predicate/isBuffer.d.mts +21 -0
  57. package/dist/compat/predicate/isBuffer.d.ts +21 -0
  58. package/dist/compat/predicate/isBuffer.mjs +7 -0
  59. package/dist/compat/predicate/isMatch.mjs +1 -4
  60. package/dist/compat/util/methodOf.d.mts +22 -0
  61. package/dist/compat/util/methodOf.d.ts +22 -0
  62. package/dist/compat/util/methodOf.mjs +9 -0
  63. package/dist/error/index.d.mts +2 -0
  64. package/dist/error/index.d.ts +2 -0
  65. package/dist/error/index.js +15 -0
  66. package/dist/error/index.mjs +2 -0
  67. package/dist/function/asyncNoop.d.mts +12 -0
  68. package/dist/function/asyncNoop.d.ts +12 -0
  69. package/dist/function/asyncNoop.mjs +3 -0
  70. package/dist/function/index.d.mts +2 -0
  71. package/dist/function/index.d.ts +2 -0
  72. package/dist/function/index.js +3 -1
  73. package/dist/function/index.mjs +2 -0
  74. package/dist/function/retry.d.mts +59 -0
  75. package/dist/function/retry.d.ts +59 -0
  76. package/dist/function/retry.mjs +35 -0
  77. package/dist/index.d.mts +7 -0
  78. package/dist/index.d.ts +7 -0
  79. package/dist/index.js +21 -11
  80. package/dist/index.mjs +7 -0
  81. package/dist/object/cloneDeepWith.mjs +34 -1
  82. package/dist/object/flattenObject.d.mts +10 -2
  83. package/dist/object/flattenObject.d.ts +10 -2
  84. package/dist/object/flattenObject.mjs +6 -6
  85. package/dist/object/index.js +1 -1
  86. package/dist/predicate/index.d.mts +1 -0
  87. package/dist/predicate/index.d.ts +1 -0
  88. package/dist/predicate/index.js +3 -2
  89. package/dist/predicate/index.mjs +1 -0
  90. package/dist/predicate/isPromise.d.mts +20 -0
  91. package/dist/predicate/isPromise.d.ts +20 -0
  92. package/dist/predicate/isPromise.mjs +5 -0
  93. package/dist/promise/index.d.mts +2 -0
  94. package/dist/promise/index.d.ts +2 -0
  95. package/dist/promise/index.js +56 -4
  96. package/dist/promise/index.mjs +2 -0
  97. package/dist/promise/mutex.d.mts +64 -0
  98. package/dist/promise/mutex.d.ts +64 -0
  99. package/dist/promise/mutex.mjs +16 -0
  100. package/dist/promise/semaphore.d.mts +81 -0
  101. package/dist/promise/semaphore.d.ts +81 -0
  102. package/dist/promise/semaphore.mjs +30 -0
  103. package/error.d.ts +1 -0
  104. package/package.json +42 -21
  105. package/dist/_chunk/index-BGZDR9.js +0 -50
  106. package/dist/_chunk/isPlainObject-octpoD.js +0 -32
@@ -4,6 +4,7 @@
4
4
  * @template T
5
5
  * @param {ArrayLike<T> | null | undefined} arr - The array to search through.
6
6
  * @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - A function that takes an item, its index, and the array, and returns a truthy value if the item matches the criteria.
7
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
7
8
  * @returns {T | undefined} - The first item that matches the predicate, or `undefined` if no match is found.
8
9
  *
9
10
  * @example
@@ -12,13 +13,14 @@
12
13
  * const result = find(items, (item) => item > 3);
13
14
  * console.log(result); // 4
14
15
  */
15
- declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item: T, index: number, arr: readonly T[]) => unknown): T | undefined;
16
+ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item: T, index: number, arr: readonly T[]) => unknown, fromIndex?: number): T | undefined;
16
17
  /**
17
18
  * Finds the first item in an array that matches the given partial object.
18
19
  *
19
20
  * @template T
20
21
  * @param {ArrayLike<T> | null | undefined} arr - The array to search through.
21
22
  * @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
23
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
22
24
  * @returns {T | undefined} - The first item that matches the partial object, or `undefined` if no match is found.
23
25
  *
24
26
  * @example
@@ -27,13 +29,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item:
27
29
  * const result = find(items, { name: 'Bob' });
28
30
  * console.log(result); // { id: 2, name: 'Bob' }
29
31
  */
30
- declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>): T | undefined;
32
+ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>, fromIndex?: number): T | undefined;
31
33
  /**
32
34
  * Finds the first item in an array that matches a property with a specific value.
33
35
  *
34
36
  * @template T
35
37
  * @param {ArrayLike<T> | null | undefined} arr - The array to search through.
36
38
  * @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
39
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
37
40
  * @returns {T | undefined} - The first item that has the specified property value, or `undefined` if no match is found.
38
41
  *
39
42
  * @example
@@ -42,13 +45,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partia
42
45
  * const result = find(items, ['name', 'Alice']);
43
46
  * console.log(result); // { id: 1, name: 'Alice' }
44
47
  */
45
- declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty: [keyof T, unknown]): T | undefined;
48
+ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty: [keyof T, unknown], fromIndex?: number): T | undefined;
46
49
  /**
47
50
  * Finds the first item in an array that has a specific property, where the property name is provided as a PropertyKey.
48
51
  *
49
52
  * @template T
50
53
  * @param {ArrayLike<T> | null | undefined} arr - The array to search through.
51
54
  * @param {PropertyKey} propertyToCheck - The property name to check.
55
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
52
56
  * @returns {T | undefined} - The first item that has the specified property, or `undefined` if no match is found.
53
57
  *
54
58
  * @example
@@ -57,13 +61,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty
57
61
  * const result = find(items, 'name');
58
62
  * console.log(result); // { id: 1, name: 'Alice' }
59
63
  */
60
- declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: PropertyKey): T | undefined;
64
+ declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: PropertyKey, fromIndex?: number): T | undefined;
61
65
  /**
62
66
  * Finds the first item in an object that matches the given predicate function.
63
67
  *
64
68
  * @template T
65
69
  * @param {T | null | undefined} object - The object to search through.
66
70
  * @param {(item: T[keyof T], index: number, arr: T) => unknown} doesMatch - A function that takes an item, its key, and the object, and returns a truthy value if the item matches the criteria.
71
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
67
72
  * @returns {T | undefined} - The first property value that matches the predicate, or `undefined` if no match is found.
68
73
  *
69
74
  * @example
@@ -72,13 +77,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck:
72
77
  * const result = find(obj, (item) => item > 2);
73
78
  * console.log(result); // 3
74
79
  */
75
- declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown): T | undefined;
80
+ declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown, fromIndex?: number): T | undefined;
76
81
  /**
77
82
  * Finds the first item in an object that matches the given partial value.
78
83
  *
79
84
  * @template T
80
85
  * @param {T | null | undefined} object - The object to search through.
81
86
  * @param {Partial<T[keyof T]>} doesMatch - A partial value to match against the values of the object.
87
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
82
88
  * @returns {T | undefined} - The first property value that matches the partial value, or `undefined` if no match is found.
83
89
  *
84
90
  * @example
@@ -87,13 +93,14 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
87
93
  * const result = find(obj, { name: 'Bob' });
88
94
  * console.log(result); // { id: 2, name: 'Bob' }
89
95
  */
90
- declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>): T | undefined;
96
+ declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>, fromIndex?: number): T | undefined;
91
97
  /**
92
98
  * Finds the first item in an object that matches a property with a specific value.
93
99
  *
94
100
  * @template T
95
101
  * @param {T | null | undefined} object - The object to search through.
96
102
  * @param {[keyof T[keyof T], unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
103
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
97
104
  * @returns {T | undefined} - The first item that has the specified property value, or `undefined` if no match is found.
98
105
  *
99
106
  * @example
@@ -102,13 +109,14 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
102
109
  * const result = find(items, ['name', 'Alice']);
103
110
  * console.log(result); // { id: 1, name: 'Alice' }
104
111
  */
105
- declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown]): T | undefined;
112
+ declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown], fromIndex?: number): T | undefined;
106
113
  /**
107
114
  * Finds the first item in an object that has a specific property, where the property name is provided as a PropertyKey.
108
115
  *
109
116
  * @template T
110
117
  * @param {T | null | undefined} object - The object to search through.
111
118
  * @param {PropertyKey} propertyToCheck - The property name to check.
119
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
112
120
  * @returns {T | undefined} - The first property value that has the specified property, or `undefined` if no match is found.
113
121
  *
114
122
  * @example
@@ -117,6 +125,6 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
117
125
  * const result = find(obj, 'name');
118
126
  * console.log(result); // { id: 1, name: 'Alice' }
119
127
  */
120
- declare function find<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: PropertyKey): T | undefined;
128
+ declare function find<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: PropertyKey, fromIndex?: number): T | undefined;
121
129
 
122
130
  export { find };
@@ -4,6 +4,7 @@
4
4
  * @template T
5
5
  * @param {ArrayLike<T> | null | undefined} arr - The array to search through.
6
6
  * @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - A function that takes an item, its index, and the array, and returns a truthy value if the item matches the criteria.
7
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
7
8
  * @returns {T | undefined} - The first item that matches the predicate, or `undefined` if no match is found.
8
9
  *
9
10
  * @example
@@ -12,13 +13,14 @@
12
13
  * const result = find(items, (item) => item > 3);
13
14
  * console.log(result); // 4
14
15
  */
15
- declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item: T, index: number, arr: readonly T[]) => unknown): T | undefined;
16
+ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item: T, index: number, arr: readonly T[]) => unknown, fromIndex?: number): T | undefined;
16
17
  /**
17
18
  * Finds the first item in an array that matches the given partial object.
18
19
  *
19
20
  * @template T
20
21
  * @param {ArrayLike<T> | null | undefined} arr - The array to search through.
21
22
  * @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
23
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
22
24
  * @returns {T | undefined} - The first item that matches the partial object, or `undefined` if no match is found.
23
25
  *
24
26
  * @example
@@ -27,13 +29,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item:
27
29
  * const result = find(items, { name: 'Bob' });
28
30
  * console.log(result); // { id: 2, name: 'Bob' }
29
31
  */
30
- declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>): T | undefined;
32
+ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>, fromIndex?: number): T | undefined;
31
33
  /**
32
34
  * Finds the first item in an array that matches a property with a specific value.
33
35
  *
34
36
  * @template T
35
37
  * @param {ArrayLike<T> | null | undefined} arr - The array to search through.
36
38
  * @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
39
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
37
40
  * @returns {T | undefined} - The first item that has the specified property value, or `undefined` if no match is found.
38
41
  *
39
42
  * @example
@@ -42,13 +45,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partia
42
45
  * const result = find(items, ['name', 'Alice']);
43
46
  * console.log(result); // { id: 1, name: 'Alice' }
44
47
  */
45
- declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty: [keyof T, unknown]): T | undefined;
48
+ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty: [keyof T, unknown], fromIndex?: number): T | undefined;
46
49
  /**
47
50
  * Finds the first item in an array that has a specific property, where the property name is provided as a PropertyKey.
48
51
  *
49
52
  * @template T
50
53
  * @param {ArrayLike<T> | null | undefined} arr - The array to search through.
51
54
  * @param {PropertyKey} propertyToCheck - The property name to check.
55
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
52
56
  * @returns {T | undefined} - The first item that has the specified property, or `undefined` if no match is found.
53
57
  *
54
58
  * @example
@@ -57,13 +61,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty
57
61
  * const result = find(items, 'name');
58
62
  * console.log(result); // { id: 1, name: 'Alice' }
59
63
  */
60
- declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: PropertyKey): T | undefined;
64
+ declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: PropertyKey, fromIndex?: number): T | undefined;
61
65
  /**
62
66
  * Finds the first item in an object that matches the given predicate function.
63
67
  *
64
68
  * @template T
65
69
  * @param {T | null | undefined} object - The object to search through.
66
70
  * @param {(item: T[keyof T], index: number, arr: T) => unknown} doesMatch - A function that takes an item, its key, and the object, and returns a truthy value if the item matches the criteria.
71
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
67
72
  * @returns {T | undefined} - The first property value that matches the predicate, or `undefined` if no match is found.
68
73
  *
69
74
  * @example
@@ -72,13 +77,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck:
72
77
  * const result = find(obj, (item) => item > 2);
73
78
  * console.log(result); // 3
74
79
  */
75
- declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown): T | undefined;
80
+ declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown, fromIndex?: number): T | undefined;
76
81
  /**
77
82
  * Finds the first item in an object that matches the given partial value.
78
83
  *
79
84
  * @template T
80
85
  * @param {T | null | undefined} object - The object to search through.
81
86
  * @param {Partial<T[keyof T]>} doesMatch - A partial value to match against the values of the object.
87
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
82
88
  * @returns {T | undefined} - The first property value that matches the partial value, or `undefined` if no match is found.
83
89
  *
84
90
  * @example
@@ -87,13 +93,14 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
87
93
  * const result = find(obj, { name: 'Bob' });
88
94
  * console.log(result); // { id: 2, name: 'Bob' }
89
95
  */
90
- declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>): T | undefined;
96
+ declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>, fromIndex?: number): T | undefined;
91
97
  /**
92
98
  * Finds the first item in an object that matches a property with a specific value.
93
99
  *
94
100
  * @template T
95
101
  * @param {T | null | undefined} object - The object to search through.
96
102
  * @param {[keyof T[keyof T], unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
103
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
97
104
  * @returns {T | undefined} - The first item that has the specified property value, or `undefined` if no match is found.
98
105
  *
99
106
  * @example
@@ -102,13 +109,14 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
102
109
  * const result = find(items, ['name', 'Alice']);
103
110
  * console.log(result); // { id: 1, name: 'Alice' }
104
111
  */
105
- declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown]): T | undefined;
112
+ declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown], fromIndex?: number): T | undefined;
106
113
  /**
107
114
  * Finds the first item in an object that has a specific property, where the property name is provided as a PropertyKey.
108
115
  *
109
116
  * @template T
110
117
  * @param {T | null | undefined} object - The object to search through.
111
118
  * @param {PropertyKey} propertyToCheck - The property name to check.
119
+ * @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
112
120
  * @returns {T | undefined} - The first property value that has the specified property, or `undefined` if no match is found.
113
121
  *
114
122
  * @example
@@ -117,6 +125,6 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
117
125
  * const result = find(obj, 'name');
118
126
  * console.log(result); // { id: 1, name: 'Alice' }
119
127
  */
120
- declare function find<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: PropertyKey): T | undefined;
128
+ declare function find<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: PropertyKey, fromIndex?: number): T | undefined;
121
129
 
122
130
  export { find };
@@ -2,11 +2,14 @@ import { property } from '../object/property.mjs';
2
2
  import { matches } from '../predicate/matches.mjs';
3
3
  import { matchesProperty } from '../predicate/matchesProperty.mjs';
4
4
 
5
- function find(source, doesMatch) {
5
+ function find(source, doesMatch, fromIndex = 0) {
6
6
  if (!source) {
7
7
  return undefined;
8
8
  }
9
- const values = Array.isArray(source) ? source : Object.values(source);
9
+ if (fromIndex < 0) {
10
+ fromIndex = Math.max(source.length + fromIndex, 0);
11
+ }
12
+ const values = Array.isArray(source) ? source.slice(fromIndex) : Object.values(source).slice(fromIndex);
10
13
  switch (typeof doesMatch) {
11
14
  case 'function': {
12
15
  if (!Array.isArray(source)) {
@@ -14,6 +14,6 @@
14
14
  * pull(numbers, [2, 4]);
15
15
  * console.log(numbers); // [1, 3, 5]
16
16
  */
17
- declare function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[][]): T[];
17
+ declare function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[]): T[];
18
18
 
19
19
  export { pull };
@@ -14,6 +14,6 @@
14
14
  * pull(numbers, [2, 4]);
15
15
  * console.log(numbers); // [1, 3, 5]
16
16
  */
17
- declare function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[][]): T[];
17
+ declare function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[]): T[];
18
18
 
19
19
  export { pull };
@@ -1,8 +1,7 @@
1
- import { flatten } from './flatten.mjs';
2
1
  import { pull as pull$1 } from '../../array/pull.mjs';
3
2
 
4
3
  function pull(arr, ...valuesToRemove) {
5
- return pull$1(arr, flatten(valuesToRemove));
4
+ return pull$1(arr, valuesToRemove);
6
5
  }
7
6
 
8
7
  export { pull };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Removes all specified values from an array.
3
+ *
4
+ * This function changes `arr` in place.
5
+ * If you want to remove values without modifying the original array, use `difference`.
6
+ *
7
+ * @template T
8
+ * @param {T[]} arr - The array to modify.
9
+ * @param {ArrayLike<T>} valuesToRemove - The values to remove from the array.
10
+ * @returns {T[]} The modified array with the specified values removed.
11
+ *
12
+ * @example
13
+ * const numbers = [1, 2, 3, 4, 5, 2, 4];
14
+ * pullAll(numbers, [2, 4]);
15
+ * console.log(numbers); // [1, 3, 5]
16
+ */
17
+ declare function pullAll<T>(arr: T[], valuesToRemove?: ArrayLike<T>): T[];
18
+
19
+ export { pullAll };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Removes all specified values from an array.
3
+ *
4
+ * This function changes `arr` in place.
5
+ * If you want to remove values without modifying the original array, use `difference`.
6
+ *
7
+ * @template T
8
+ * @param {T[]} arr - The array to modify.
9
+ * @param {ArrayLike<T>} valuesToRemove - The values to remove from the array.
10
+ * @returns {T[]} The modified array with the specified values removed.
11
+ *
12
+ * @example
13
+ * const numbers = [1, 2, 3, 4, 5, 2, 4];
14
+ * pullAll(numbers, [2, 4]);
15
+ * console.log(numbers); // [1, 3, 5]
16
+ */
17
+ declare function pullAll<T>(arr: T[], valuesToRemove?: ArrayLike<T>): T[];
18
+
19
+ export { pullAll };
@@ -0,0 +1,7 @@
1
+ import { pull } from '../../array/pull.mjs';
2
+
3
+ function pullAll(arr, valuesToRemove = []) {
4
+ return pull(arr, Array.from(valuesToRemove));
5
+ }
6
+
7
+ export { pullAll };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Removes elements from an array based on a predicate function.
3
+ *
4
+ * @param {ArrayLike<T>} arr - The array to iterate over.
5
+ * @param {(value: T, index: number, arr: ArrayLike<T>) => boolean} shouldRemoveElement - The function invoked per iteration.
6
+ * @returns {T[]} - Returns the modified array with the specified elements removed.
7
+ *
8
+ * @example
9
+ * const array = [1, 2, 3];
10
+ * remove(array, value => value % 2 === 0); // => [1, 3]
11
+ */
12
+ declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: (value: T, index: number, arr: ArrayLike<T>) => boolean): T[];
13
+ /**
14
+ * Removes elements from an array based on a partial object match.
15
+ *
16
+ * @param {ArrayLike<T>} arr - The array to iterate over.
17
+ * @param {Partial<T>} shouldRemoveElement - The partial object to match against each element.
18
+ * @returns {T[]} - Returns the modified array with the specified elements removed.
19
+ *
20
+ * @example
21
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
22
+ * remove(objects, { a: 1 }); // => [{ a: 2 }, { a: 3 }]
23
+ */
24
+ declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: Partial<T>): T[];
25
+ /**
26
+ * Removes elements from an array based on a property-value pair match.
27
+ *
28
+ * @param {ArrayLike<T>} arr - The array to iterate over.
29
+ * @param {[keyof T, unknown]} shouldRemoveElement - The property-value pair to match against each element.
30
+ * @returns {T[]} - Returns the modified array with the specified elements removed.
31
+ *
32
+ * @example
33
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
34
+ * remove(objects, ['a', 1]); // => [{ a: 2 }, { a: 3 }]
35
+ */
36
+ declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: [keyof T, unknown]): T[];
37
+ /**
38
+ * Removes elements from an array based on a property key.
39
+ *
40
+ * @param {ArrayLike<T>} arr - The array to iterate over.
41
+ * @param {keyof T} shouldRemoveElement - The key of the property to match against each element.
42
+ * @returns {T[]} - Returns the modified array with the specified elements removed.
43
+ *
44
+ * @example
45
+ * const objects = [{ a: 0 }, { a: 1 }];
46
+ * remove(objects, 'a'); // => [{ a: 0 }]
47
+ */
48
+ declare function remove<T, K extends keyof T>(arr: ArrayLike<T>, shouldRemoveElement: K): T[];
49
+
50
+ export { remove };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Removes elements from an array based on a predicate function.
3
+ *
4
+ * @param {ArrayLike<T>} arr - The array to iterate over.
5
+ * @param {(value: T, index: number, arr: ArrayLike<T>) => boolean} shouldRemoveElement - The function invoked per iteration.
6
+ * @returns {T[]} - Returns the modified array with the specified elements removed.
7
+ *
8
+ * @example
9
+ * const array = [1, 2, 3];
10
+ * remove(array, value => value % 2 === 0); // => [1, 3]
11
+ */
12
+ declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: (value: T, index: number, arr: ArrayLike<T>) => boolean): T[];
13
+ /**
14
+ * Removes elements from an array based on a partial object match.
15
+ *
16
+ * @param {ArrayLike<T>} arr - The array to iterate over.
17
+ * @param {Partial<T>} shouldRemoveElement - The partial object to match against each element.
18
+ * @returns {T[]} - Returns the modified array with the specified elements removed.
19
+ *
20
+ * @example
21
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
22
+ * remove(objects, { a: 1 }); // => [{ a: 2 }, { a: 3 }]
23
+ */
24
+ declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: Partial<T>): T[];
25
+ /**
26
+ * Removes elements from an array based on a property-value pair match.
27
+ *
28
+ * @param {ArrayLike<T>} arr - The array to iterate over.
29
+ * @param {[keyof T, unknown]} shouldRemoveElement - The property-value pair to match against each element.
30
+ * @returns {T[]} - Returns the modified array with the specified elements removed.
31
+ *
32
+ * @example
33
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
34
+ * remove(objects, ['a', 1]); // => [{ a: 2 }, { a: 3 }]
35
+ */
36
+ declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: [keyof T, unknown]): T[];
37
+ /**
38
+ * Removes elements from an array based on a property key.
39
+ *
40
+ * @param {ArrayLike<T>} arr - The array to iterate over.
41
+ * @param {keyof T} shouldRemoveElement - The key of the property to match against each element.
42
+ * @returns {T[]} - Returns the modified array with the specified elements removed.
43
+ *
44
+ * @example
45
+ * const objects = [{ a: 0 }, { a: 1 }];
46
+ * remove(objects, 'a'); // => [{ a: 0 }]
47
+ */
48
+ declare function remove<T, K extends keyof T>(arr: ArrayLike<T>, shouldRemoveElement: K): T[];
49
+
50
+ export { remove };
@@ -0,0 +1,8 @@
1
+ import { remove as remove$1 } from '../../array/remove.mjs';
2
+ import { iteratee } from '../util/iteratee.mjs';
3
+
4
+ function remove(arr, shouldRemoveElement) {
5
+ return remove$1(arr, iteratee(shouldRemoveElement));
6
+ }
7
+
8
+ export { remove };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Reverses the elements of an array in place.
3
+ *
4
+ * This function takes an array and reverses its elements in place, modifying the original array.
5
+ * If the input is `null` or `undefined`, it returns the input as is.
6
+ *
7
+ * @template T - The type of elements in the array.
8
+ * @param {T[] | null | undefined} array - The array to reverse. If `null` or `undefined`, the input is returned as is.
9
+ * @returns {T[] | null | undefined} The reversed array, or `null`/`undefined` if the input was `null`/`undefined`.
10
+ *
11
+ * @example
12
+ * const array = [1, 2, 3, 4, 5];
13
+ * const reversedArray = reverse(array);
14
+ * // reversedArray is [5, 4, 3, 2, 1], and array is also modified to [5, 4, 3, 2, 1].
15
+ *
16
+ * const emptyArray = reverse([]);
17
+ * // emptyArray is [].
18
+ *
19
+ * const nullArray = reverse(null);
20
+ * // nullArray is null.
21
+ */
22
+ declare function reverse<T>(array: T[] | null | undefined): T[] | null | undefined;
23
+
24
+ export { reverse };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Reverses the elements of an array in place.
3
+ *
4
+ * This function takes an array and reverses its elements in place, modifying the original array.
5
+ * If the input is `null` or `undefined`, it returns the input as is.
6
+ *
7
+ * @template T - The type of elements in the array.
8
+ * @param {T[] | null | undefined} array - The array to reverse. If `null` or `undefined`, the input is returned as is.
9
+ * @returns {T[] | null | undefined} The reversed array, or `null`/`undefined` if the input was `null`/`undefined`.
10
+ *
11
+ * @example
12
+ * const array = [1, 2, 3, 4, 5];
13
+ * const reversedArray = reverse(array);
14
+ * // reversedArray is [5, 4, 3, 2, 1], and array is also modified to [5, 4, 3, 2, 1].
15
+ *
16
+ * const emptyArray = reverse([]);
17
+ * // emptyArray is [].
18
+ *
19
+ * const nullArray = reverse(null);
20
+ * // nullArray is null.
21
+ */
22
+ declare function reverse<T>(array: T[] | null | undefined): T[] | null | undefined;
23
+
24
+ export { reverse };
@@ -0,0 +1,8 @@
1
+ function reverse(array) {
2
+ if (array == null) {
3
+ return array;
4
+ }
5
+ return array.reverse();
6
+ }
7
+
8
+ export { reverse };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Creates a function that negates the result of the predicate function.
3
+ *
4
+ * @template F - The type of the function to negate.
5
+ * @param {F} func - The function to negate.
6
+ * @returns {F} The new negated function, which negates the boolean result of `func`.
7
+ *
8
+ * @example
9
+ * const array = [1, 2, 3, 4, 5, 6];
10
+ * const isEven = (n: number) => n % 2 === 0;
11
+ * const result = array.filter(negate(isEven));
12
+ * // result will be [1, 3, 5]
13
+ */
14
+ declare function negate<F extends (...args: any[]) => boolean>(func: F): F;
15
+
16
+ export { negate };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Creates a function that negates the result of the predicate function.
3
+ *
4
+ * @template F - The type of the function to negate.
5
+ * @param {F} func - The function to negate.
6
+ * @returns {F} The new negated function, which negates the boolean result of `func`.
7
+ *
8
+ * @example
9
+ * const array = [1, 2, 3, 4, 5, 6];
10
+ * const isEven = (n: number) => n % 2 === 0;
11
+ * const result = array.filter(negate(isEven));
12
+ * // result will be [1, 3, 5]
13
+ */
14
+ declare function negate<F extends (...args: any[]) => boolean>(func: F): F;
15
+
16
+ export { negate };
@@ -0,0 +1,10 @@
1
+ function negate(func) {
2
+ if (typeof func !== 'function') {
3
+ throw new TypeError('Expected a function');
4
+ }
5
+ return function (...args) {
6
+ return !func.apply(this, args);
7
+ };
8
+ }
9
+
10
+ export { negate };