es-toolkit 1.23.0 → 1.24.0-dev.764

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 (135) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +1 -1
  3. package/dist/_chunk/{isWeakSet-BAMm2l.js → isWeakSet-Bd6nry.js} +59 -46
  4. package/dist/_chunk/{range-BXlMmn.js → sumBy-BkErWJ.js} +25 -5
  5. package/dist/_chunk/{isObjectLike-aywuSF.js → toMerged-DDLv0D.js} +88 -86
  6. package/dist/_chunk/{flowRight-Dv8J0U.js → unary-BZ5Ixo.js} +27 -64
  7. package/dist/_chunk/{zipWith-EOU_KZ.js → zipWith-wpjySR.js} +8 -17
  8. package/dist/array/dropRightWhile.d.mts +2 -2
  9. package/dist/array/dropRightWhile.d.ts +2 -2
  10. package/dist/array/dropRightWhile.mjs +1 -1
  11. package/dist/array/dropWhile.d.mts +1 -1
  12. package/dist/array/dropWhile.d.ts +1 -1
  13. package/dist/array/index.js +1 -1
  14. package/dist/array/unionBy.mjs +3 -10
  15. package/dist/browser.global.js +1 -1
  16. package/dist/browser.global.js.map +1 -1
  17. package/dist/compat/_internal/MAX_ARRAY_LENGTH.mjs +3 -0
  18. package/dist/compat/_internal/isIterateeCall.mjs +17 -0
  19. package/dist/compat/array/difference.d.mts +9 -3
  20. package/dist/compat/array/difference.d.ts +9 -3
  21. package/dist/compat/array/difference.mjs +12 -3
  22. package/dist/compat/array/dropRightWhile.d.mts +60 -0
  23. package/dist/compat/array/dropRightWhile.d.ts +60 -0
  24. package/dist/compat/array/dropRightWhile.mjs +27 -0
  25. package/dist/compat/array/every.mjs +4 -5
  26. package/dist/compat/array/filter.mjs +4 -5
  27. package/dist/compat/array/find.mjs +4 -5
  28. package/dist/compat/array/includes.mjs +2 -1
  29. package/dist/compat/array/slice.d.mts +18 -0
  30. package/dist/compat/array/slice.d.ts +18 -0
  31. package/dist/compat/array/slice.mjs +38 -0
  32. package/dist/compat/array/take.d.mts +25 -0
  33. package/dist/compat/array/take.d.ts +25 -0
  34. package/dist/compat/array/take.mjs +10 -0
  35. package/dist/compat/function/before.d.mts +26 -0
  36. package/dist/compat/function/before.d.ts +26 -0
  37. package/dist/compat/function/before.mjs +20 -0
  38. package/dist/compat/function/curryRight.d.mts +50 -0
  39. package/dist/compat/function/curryRight.d.ts +50 -0
  40. package/dist/compat/function/curryRight.mjs +64 -0
  41. package/dist/compat/index.d.mts +86 -75
  42. package/dist/compat/index.d.ts +86 -75
  43. package/dist/compat/index.js +779 -496
  44. package/dist/compat/index.mjs +86 -75
  45. package/dist/compat/object/defaults.d.mts +120 -0
  46. package/dist/compat/object/defaults.d.ts +120 -0
  47. package/dist/compat/object/defaults.mjs +21 -0
  48. package/dist/compat/object/invertBy.d.mts +27 -0
  49. package/dist/compat/object/invertBy.d.ts +27 -0
  50. package/dist/compat/object/invertBy.mjs +27 -0
  51. package/dist/compat/object/omit.d.mts +1 -1
  52. package/dist/compat/object/omit.d.ts +1 -1
  53. package/dist/compat/object/pick.d.mts +1 -1
  54. package/dist/compat/object/pick.d.ts +1 -1
  55. package/dist/compat/object/toDefaulted.d.mts +122 -0
  56. package/dist/compat/object/toDefaulted.d.ts +122 -0
  57. package/dist/compat/object/toDefaulted.mjs +9 -0
  58. package/dist/compat/predicate/isArrayBuffer.d.mts +20 -0
  59. package/dist/compat/predicate/isArrayBuffer.d.ts +20 -0
  60. package/dist/compat/predicate/isArrayBuffer.mjs +7 -0
  61. package/dist/compat/predicate/isDate.d.mts +16 -0
  62. package/dist/compat/predicate/isDate.d.ts +16 -0
  63. package/dist/compat/predicate/isDate.mjs +7 -0
  64. package/dist/compat/predicate/isEqualWith.d.mts +38 -0
  65. package/dist/compat/predicate/isEqualWith.d.ts +38 -0
  66. package/dist/compat/predicate/isEqualWith.mjs +23 -0
  67. package/dist/compat/predicate/isMap.d.mts +20 -0
  68. package/dist/compat/predicate/isMap.d.ts +20 -0
  69. package/dist/compat/predicate/isMap.mjs +7 -0
  70. package/dist/compat/predicate/isMatch.mjs +2 -1
  71. package/dist/compat/predicate/isSet.d.mts +20 -0
  72. package/dist/compat/predicate/isSet.d.ts +20 -0
  73. package/dist/compat/predicate/isSet.mjs +7 -0
  74. package/dist/compat/string/upperCase.mjs +0 -1
  75. package/dist/compat/util/constant.d.mts +16 -0
  76. package/dist/compat/util/constant.d.ts +16 -0
  77. package/dist/compat/util/constant.mjs +5 -0
  78. package/dist/compat/util/defaultTo.d.mts +17 -0
  79. package/dist/compat/util/defaultTo.d.ts +17 -0
  80. package/dist/compat/util/defaultTo.mjs +8 -0
  81. package/dist/compat/util/eq.d.mts +16 -0
  82. package/dist/compat/util/eq.d.ts +16 -0
  83. package/dist/compat/util/eq.mjs +5 -0
  84. package/dist/compat/util/times.d.mts +14 -0
  85. package/dist/compat/util/times.d.ts +14 -0
  86. package/dist/compat/util/times.mjs +15 -0
  87. package/dist/compat/util/toLength.d.mts +18 -0
  88. package/dist/compat/util/toLength.d.ts +18 -0
  89. package/dist/compat/util/toLength.mjs +12 -0
  90. package/dist/function/before.d.mts +2 -2
  91. package/dist/function/before.d.ts +2 -2
  92. package/dist/function/before.mjs +2 -2
  93. package/dist/function/index.d.mts +10 -10
  94. package/dist/function/index.d.ts +10 -10
  95. package/dist/function/index.js +65 -32
  96. package/dist/function/index.mjs +10 -10
  97. package/dist/function/once.d.mts +16 -1
  98. package/dist/function/once.d.ts +16 -1
  99. package/dist/function/once.mjs +5 -7
  100. package/dist/index.d.mts +43 -41
  101. package/dist/index.d.ts +43 -41
  102. package/dist/index.js +59 -57
  103. package/dist/index.mjs +43 -41
  104. package/dist/math/index.d.mts +2 -1
  105. package/dist/math/index.d.ts +2 -1
  106. package/dist/math/index.js +9 -8
  107. package/dist/math/index.mjs +2 -1
  108. package/dist/math/rangeRight.d.mts +38 -0
  109. package/dist/math/rangeRight.d.ts +38 -0
  110. package/dist/math/rangeRight.mjs +20 -0
  111. package/dist/object/index.d.mts +7 -7
  112. package/dist/object/index.d.ts +7 -7
  113. package/dist/object/index.js +32 -32
  114. package/dist/object/index.mjs +7 -7
  115. package/dist/object/omitBy.d.mts +1 -1
  116. package/dist/object/omitBy.d.ts +1 -1
  117. package/dist/object/omitBy.mjs +4 -3
  118. package/dist/object/pickBy.mjs +4 -3
  119. package/dist/predicate/index.d.mts +11 -10
  120. package/dist/predicate/index.d.ts +11 -10
  121. package/dist/predicate/index.js +8 -7
  122. package/dist/predicate/index.mjs +11 -10
  123. package/dist/predicate/isBlob.d.mts +19 -0
  124. package/dist/predicate/isBlob.d.ts +19 -0
  125. package/dist/predicate/isBlob.mjs +8 -0
  126. package/dist/predicate/isEqualWith.mjs +2 -1
  127. package/dist/promise/index.d.mts +1 -1
  128. package/dist/promise/index.d.ts +1 -1
  129. package/dist/promise/index.mjs +1 -1
  130. package/dist/string/index.d.mts +12 -12
  131. package/dist/string/index.d.ts +12 -12
  132. package/dist/string/index.js +20 -20
  133. package/dist/string/index.mjs +12 -12
  134. package/package.json +10 -6
  135. package/dist/_chunk/{pad-BWiShN.js → upperFirst-BUECmK.js} +84 -84
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # es-toolkit Changelog
2
2
 
3
+ ## Version v1.24.0
4
+
5
+ Released on October 7th, 2024.
6
+
7
+ - Added support for [isBlob](https://es-toolkit.slash.page/reference/predicate/isBlob.html) and [isDate](https://es-toolkit.slash.page/reference/predicate/isDate.html).
8
+ - Added compatibility functions for [invertBy](https://es-toolkit.slash.page/reference/compat/object/invertBy.html), [times](https://es-toolkit.slash.page/reference/compat/util/times.html), [constant](https://es-toolkit.slash.page/reference/compat/util/constant.html), [slice](https://es-toolkit.slash.page/reference/compat/array/slice.html), [toLength](https://es-toolkit.slash.page/reference/compat/util/toLength.html), [defaultTo](https://es-toolkit.slash.page/reference/compat/util/defaultTo.html), [dropRightWhile](https://es-toolkit.slash.page/reference/array/dropRightWhile.html), [curryRight](https://es-toolkit.slash.page/reference/function/curryRight.html), [rangeRight](https://es-toolkit.slash.page/reference/math/rangeRight.html), [before](https://es-toolkit.slash.page/reference/function/before.html), [eq](https://es-toolkit.slash.page/reference/compat/util/eq.html), [defaults](https://es-toolkit.slash.page/reference/compat/object/defaults.html), [toDefaulted](https://es-toolkit.slash.page/reference/compat/object/toDefaulted.html), [isArrayBuffer](https://es-toolkit.slash.page/reference/predicate/isArrayBuffer.html), [isSet](https://es-toolkit.slash.page/reference/predicate/isSet.html), and [isMap](https://es-toolkit.slash.page/reference/predicate/isMap.html).
9
+ - Enhanced [difference](https://es-toolkit.slash.page/reference/array/difference.html) to work with Array-like objects, aligning its functionality with lodash's behavior.
10
+ - Improved performance for [pickBy](https://es-toolkit.slash.page/reference/object/pickBy.html) and [omitBy](https://es-toolkit.slash.page/reference/object/omitBy.html).
11
+
3
12
  ## Version v1.23.0
4
13
 
5
14
  Released on October 1st, 2024.
package/README.md CHANGED
@@ -16,7 +16,7 @@ es-toolkit is a state-of-the-art, high-performance JavaScript utility library wi
16
16
 
17
17
  ```tsx
18
18
  // import from '@es-toolkit/es-toolkit' in jsr.
19
- import { debounce, chunk } from 'es-toolkit';
19
+ import { chunk, debounce } from 'es-toolkit';
20
20
 
21
21
  const debouncedLog = debounce(message => {
22
22
  console.log(message);
@@ -7,6 +7,13 @@ function isArrayBuffer(value) {
7
7
  return value instanceof ArrayBuffer;
8
8
  }
9
9
 
10
+ function isBlob(x) {
11
+ if (typeof Blob === 'undefined') {
12
+ return false;
13
+ }
14
+ return x instanceof Blob;
15
+ }
16
+
10
17
  function isDate(value) {
11
18
  return value instanceof Date;
12
19
  }
@@ -49,6 +56,10 @@ const bigInt64ArrayTag = '[object BigInt64Array]';
49
56
  const float32ArrayTag = '[object Float32Array]';
50
57
  const float64ArrayTag = '[object Float64Array]';
51
58
 
59
+ function eq(value, other) {
60
+ return value === other || (Number.isNaN(value) && Number.isNaN(other));
61
+ }
62
+
52
63
  function isEqualWith(a, b, areValuesEqual) {
53
64
  return isEqualWithImpl(a, b, undefined, undefined, undefined, undefined, areValuesEqual);
54
65
  }
@@ -100,7 +111,7 @@ function areObjectsEqual(a, b, stack, areValuesEqual) {
100
111
  case numberTag: {
101
112
  const x = a.valueOf();
102
113
  const y = b.valueOf();
103
- return x === y || (Number.isNaN(x) && Number.isNaN(y));
114
+ return eq(x, y);
104
115
  }
105
116
  case booleanTag:
106
117
  case dateTag:
@@ -231,43 +242,26 @@ function isEqual(a, b) {
231
242
  return isEqualWith(a, b, noop.noop);
232
243
  }
233
244
 
234
- function isMap(value) {
235
- return value instanceof Map;
236
- }
237
-
238
- function isNil(x) {
239
- return x == null;
240
- }
241
-
242
- function isNotNil(x) {
243
- return x != null;
244
- }
245
-
246
- function isNull(x) {
247
- return x === null;
248
- }
249
-
250
- function isUndefined(x) {
251
- return x === undefined;
252
- }
253
-
254
- function isLength(value) {
255
- return Number.isSafeInteger(value) && value >= 0;
256
- }
257
-
258
245
  function isFunction(value) {
259
246
  return typeof value === 'function';
260
247
  }
261
248
 
262
- function isRegExp(value) {
263
- return value instanceof RegExp;
264
- }
265
-
266
- function isJSONArray(value) {
267
- if (!Array.isArray(value)) {
249
+ function isJSONObject(obj) {
250
+ if (!isPlainObject.isPlainObject(obj)) {
268
251
  return false;
269
252
  }
270
- return value.every(item => isJSONValue(item));
253
+ const keys = Reflect.ownKeys(obj);
254
+ for (let i = 0; i < keys.length; i++) {
255
+ const key = keys[i];
256
+ const value = obj[key];
257
+ if (typeof key !== 'string') {
258
+ return false;
259
+ }
260
+ if (!isJSONValue(value)) {
261
+ return false;
262
+ }
263
+ }
264
+ return true;
271
265
  }
272
266
 
273
267
  function isJSONValue(value) {
@@ -286,28 +280,45 @@ function isJSONValue(value) {
286
280
  }
287
281
  }
288
282
 
289
- function isJSONObject(obj) {
290
- if (!isPlainObject.isPlainObject(obj)) {
283
+ function isJSONArray(value) {
284
+ if (!Array.isArray(value)) {
291
285
  return false;
292
286
  }
293
- const keys = Reflect.ownKeys(obj);
294
- for (let i = 0; i < keys.length; i++) {
295
- const key = keys[i];
296
- const value = obj[key];
297
- if (typeof key !== 'string') {
298
- return false;
299
- }
300
- if (!isJSONValue(value)) {
301
- return false;
302
- }
303
- }
304
- return true;
287
+ return value.every(item => isJSONValue(item));
288
+ }
289
+
290
+ function isLength(value) {
291
+ return Number.isSafeInteger(value) && value >= 0;
292
+ }
293
+
294
+ function isMap(value) {
295
+ return value instanceof Map;
296
+ }
297
+
298
+ function isNil(x) {
299
+ return x == null;
300
+ }
301
+
302
+ function isNotNil(x) {
303
+ return x != null;
304
+ }
305
+
306
+ function isNull(x) {
307
+ return x === null;
308
+ }
309
+
310
+ function isRegExp(value) {
311
+ return value instanceof RegExp;
305
312
  }
306
313
 
307
314
  function isSet(value) {
308
315
  return value instanceof Set;
309
316
  }
310
317
 
318
+ function isUndefined(x) {
319
+ return x === undefined;
320
+ }
321
+
311
322
  function isWeakMap(value) {
312
323
  return value instanceof WeakMap;
313
324
  }
@@ -318,9 +329,11 @@ function isWeakSet(value) {
318
329
 
319
330
  exports.argumentsTag = argumentsTag;
320
331
  exports.booleanTag = booleanTag;
332
+ exports.eq = eq;
321
333
  exports.getSymbols = getSymbols;
322
334
  exports.getTag = getTag;
323
335
  exports.isArrayBuffer = isArrayBuffer;
336
+ exports.isBlob = isBlob;
324
337
  exports.isDate = isDate;
325
338
  exports.isEqual = isEqual;
326
339
  exports.isEqualWith = isEqualWith;
@@ -35,11 +35,6 @@ function meanBy(items, getValue) {
35
35
  return mean(nums);
36
36
  }
37
37
 
38
- function sumBy(items, getValue) {
39
- const nums = items.map(x => getValue(x));
40
- return sum(nums);
41
- }
42
-
43
38
  function range(start, end, step) {
44
39
  if (end == null) {
45
40
  end = start;
@@ -59,10 +54,35 @@ function range(start, end, step) {
59
54
  return result;
60
55
  }
61
56
 
57
+ function rangeRight(start, end, step) {
58
+ if (end == null) {
59
+ end = start;
60
+ start = 0;
61
+ }
62
+ if (step == null) {
63
+ step = 1;
64
+ }
65
+ if (!Number.isInteger(step) || step === 0) {
66
+ throw new Error(`The step value must be a non-zero integer.`);
67
+ }
68
+ const length = Math.max(Math.ceil((end - start) / step), 0);
69
+ const result = new Array(length);
70
+ for (let i = 0; i < length; i++) {
71
+ result[i] = start + (length - i - 1) * step;
72
+ }
73
+ return result;
74
+ }
75
+
76
+ function sumBy(items, getValue) {
77
+ const nums = items.map(x => getValue(x));
78
+ return sum(nums);
79
+ }
80
+
62
81
  exports.clamp = clamp;
63
82
  exports.inRange = inRange;
64
83
  exports.mean = mean;
65
84
  exports.meanBy = meanBy;
66
85
  exports.range = range;
86
+ exports.rangeRight = rangeRight;
67
87
  exports.sum = sum;
68
88
  exports.sumBy = sumBy;
@@ -2,41 +2,6 @@
2
2
 
3
3
  const isPlainObject = require('./isPlainObject-DgrsU7.js');
4
4
 
5
- function omitBy(obj, shouldOmit) {
6
- const result = {};
7
- const objEntries = Object.entries(obj);
8
- for (let i = 0; i < objEntries.length; i++) {
9
- const [key, value] = objEntries[i];
10
- if (!shouldOmit(value, key)) {
11
- result[key] = value;
12
- }
13
- }
14
- return result;
15
- }
16
-
17
- function pickBy(obj, shouldPick) {
18
- const result = {};
19
- const objEntries = Object.entries(obj);
20
- for (let i = 0; i < objEntries.length; i++) {
21
- const [key, value] = objEntries[i];
22
- if (shouldPick(value, key)) {
23
- result[key] = value;
24
- }
25
- }
26
- return result;
27
- }
28
-
29
- function invert(obj) {
30
- const result = {};
31
- const keys = Object.keys(obj);
32
- for (let i = 0; i < keys.length; i++) {
33
- const key = keys[i];
34
- const value = obj[key];
35
- result[value] = key;
36
- }
37
- return result;
38
- }
39
-
40
5
  function clone(obj) {
41
6
  if (isPlainObject.isPrimitive(obj)) {
42
7
  return obj;
@@ -78,53 +43,6 @@ function clone(obj) {
78
43
  return obj;
79
44
  }
80
45
 
81
- function flattenObject(object) {
82
- return flattenObjectImpl(object);
83
- }
84
- function flattenObjectImpl(object, prefix = '') {
85
- const result = {};
86
- const keys = Object.keys(object);
87
- for (let i = 0; i < keys.length; i++) {
88
- const key = keys[i];
89
- const value = object[key];
90
- const prefixedKey = prefix ? `${prefix}.${key}` : key;
91
- if (isPlainObject.isPlainObject(value) && Object.keys(value).length > 0) {
92
- Object.assign(result, flattenObjectImpl(value, prefixedKey));
93
- continue;
94
- }
95
- if (Array.isArray(value)) {
96
- for (let index = 0; index < value.length; index++) {
97
- result[`${prefixedKey}.${index}`] = value[index];
98
- }
99
- continue;
100
- }
101
- result[prefixedKey] = value;
102
- }
103
- return result;
104
- }
105
-
106
- function mapKeys(object, getNewKey) {
107
- const result = {};
108
- const keys = Object.keys(object);
109
- for (let i = 0; i < keys.length; i++) {
110
- const key = keys[i];
111
- const value = object[key];
112
- result[getNewKey(value, key, object)] = value;
113
- }
114
- return result;
115
- }
116
-
117
- function mapValues(object, getNewValue) {
118
- const result = {};
119
- const keys = Object.keys(object);
120
- for (let i = 0; i < keys.length; i++) {
121
- const key = keys[i];
122
- const value = object[key];
123
- result[key] = getNewValue(value, key, object);
124
- }
125
- return result;
126
- }
127
-
128
46
  function cloneDeep(obj) {
129
47
  return cloneDeepImpl(obj);
130
48
  }
@@ -234,6 +152,64 @@ function copyProperties(target, source, stack) {
234
152
  }
235
153
  }
236
154
 
155
+ function flattenObject(object) {
156
+ return flattenObjectImpl(object);
157
+ }
158
+ function flattenObjectImpl(object, prefix = '') {
159
+ const result = {};
160
+ const keys = Object.keys(object);
161
+ for (let i = 0; i < keys.length; i++) {
162
+ const key = keys[i];
163
+ const value = object[key];
164
+ const prefixedKey = prefix ? `${prefix}.${key}` : key;
165
+ if (isPlainObject.isPlainObject(value) && Object.keys(value).length > 0) {
166
+ Object.assign(result, flattenObjectImpl(value, prefixedKey));
167
+ continue;
168
+ }
169
+ if (Array.isArray(value)) {
170
+ for (let index = 0; index < value.length; index++) {
171
+ result[`${prefixedKey}.${index}`] = value[index];
172
+ }
173
+ continue;
174
+ }
175
+ result[prefixedKey] = value;
176
+ }
177
+ return result;
178
+ }
179
+
180
+ function invert(obj) {
181
+ const result = {};
182
+ const keys = Object.keys(obj);
183
+ for (let i = 0; i < keys.length; i++) {
184
+ const key = keys[i];
185
+ const value = obj[key];
186
+ result[value] = key;
187
+ }
188
+ return result;
189
+ }
190
+
191
+ function mapKeys(object, getNewKey) {
192
+ const result = {};
193
+ const keys = Object.keys(object);
194
+ for (let i = 0; i < keys.length; i++) {
195
+ const key = keys[i];
196
+ const value = object[key];
197
+ result[getNewKey(value, key, object)] = value;
198
+ }
199
+ return result;
200
+ }
201
+
202
+ function mapValues(object, getNewValue) {
203
+ const result = {};
204
+ const keys = Object.keys(object);
205
+ for (let i = 0; i < keys.length; i++) {
206
+ const key = keys[i];
207
+ const value = object[key];
208
+ result[key] = getNewValue(value, key, object);
209
+ }
210
+ return result;
211
+ }
212
+
237
213
  function merge(target, source) {
238
214
  const sourceKeys = Object.keys(source);
239
215
  for (let i = 0; i < sourceKeys.length; i++) {
@@ -263,14 +239,40 @@ function merge(target, source) {
263
239
  return target;
264
240
  }
265
241
 
266
- function toMerged(target, source) {
267
- return merge(cloneDeep(target), source);
268
- }
269
-
270
242
  function isObjectLike(value) {
271
243
  return typeof value === 'object' && value !== null;
272
244
  }
273
245
 
246
+ function omitBy(obj, shouldOmit) {
247
+ const result = {};
248
+ const keys = Object.keys(obj);
249
+ for (let i = 0; i < keys.length; i++) {
250
+ const key = keys[i];
251
+ const value = obj[key];
252
+ if (!shouldOmit(value, key)) {
253
+ result[key] = value;
254
+ }
255
+ }
256
+ return result;
257
+ }
258
+
259
+ function pickBy(obj, shouldPick) {
260
+ const result = {};
261
+ const keys = Object.keys(obj);
262
+ for (let i = 0; i < keys.length; i++) {
263
+ const key = keys[i];
264
+ const value = obj[key];
265
+ if (shouldPick(value, key)) {
266
+ result[key] = value;
267
+ }
268
+ }
269
+ return result;
270
+ }
271
+
272
+ function toMerged(target, source) {
273
+ return merge(cloneDeep(target), source);
274
+ }
275
+
274
276
  exports.clone = clone;
275
277
  exports.cloneDeep = cloneDeep;
276
278
  exports.copyProperties = copyProperties;
@@ -1,18 +1,5 @@
1
1
  'use strict';
2
2
 
3
- function before(n, func) {
4
- if (!Number.isInteger(n) || n < 0) {
5
- throw new Error('n must be a non-negative integer.');
6
- }
7
- let counter = 0;
8
- return ((...args) => {
9
- if (++counter < n) {
10
- return func(...args);
11
- }
12
- return undefined;
13
- });
14
- }
15
-
16
3
  function after(n, func) {
17
4
  if (!Number.isInteger(n) || n < 0) {
18
5
  throw new Error(`n must be a non-negative integer.`);
@@ -26,6 +13,12 @@ function after(n, func) {
26
13
  });
27
14
  }
28
15
 
16
+ function ary(func, n) {
17
+ return function (...args) {
18
+ return func.apply(this, args.slice(0, n));
19
+ };
20
+ }
21
+
29
22
  function debounce(func, debounceMs, { signal, edges } = {}) {
30
23
  let pendingThis = undefined;
31
24
  let pendingArgs = null;
@@ -88,22 +81,18 @@ function debounce(func, debounceMs, { signal, edges } = {}) {
88
81
  return debounced;
89
82
  }
90
83
 
91
- function once(func) {
92
- let called = false;
93
- let cache;
94
- return function () {
95
- if (called) {
96
- return cache;
84
+ function flow(...funcs) {
85
+ return function (...args) {
86
+ let result = funcs.length ? funcs[0].apply(this, args) : args[0];
87
+ for (let i = 1; i < funcs.length; i++) {
88
+ result = funcs[i].call(this, result);
97
89
  }
98
- const result = func();
99
- called = true;
100
- cache = result;
101
90
  return result;
102
91
  };
103
92
  }
104
93
 
105
- function negate(func) {
106
- return ((...args) => !func(...args));
94
+ function flowRight(...funcs) {
95
+ return flow(...funcs.reverse());
107
96
  }
108
97
 
109
98
  function memoize(fn, options = {}) {
@@ -121,14 +110,20 @@ function memoize(fn, options = {}) {
121
110
  return memoizedFn;
122
111
  }
123
112
 
124
- function ary(func, n) {
125
- return function (...args) {
126
- return func.apply(this, args.slice(0, n));
127
- };
113
+ function negate(func) {
114
+ return ((...args) => !func(...args));
128
115
  }
129
116
 
130
- function unary(func) {
131
- return ary(func, 1);
117
+ function once(func) {
118
+ let called = false;
119
+ let cache;
120
+ return function (...args) {
121
+ if (!called) {
122
+ called = true;
123
+ cache = func(...args);
124
+ }
125
+ return cache;
126
+ };
132
127
  }
133
128
 
134
129
  function partial(func, ...partialArgs) {
@@ -188,44 +183,12 @@ function rest(func, startIndex = func.length - 1) {
188
183
  };
189
184
  }
190
185
 
191
- function curryRight(func) {
192
- if (func.length === 0 || func.length === 1) {
193
- return func;
194
- }
195
- return function (arg) {
196
- return makeCurryRight(func, func.length, [arg]);
197
- };
198
- }
199
- function makeCurryRight(origin, argsLength, args) {
200
- if (args.length === argsLength) {
201
- return origin(...args);
202
- }
203
- else {
204
- const next = function (arg) {
205
- return makeCurryRight(origin, argsLength, [arg, ...args]);
206
- };
207
- return next;
208
- }
209
- }
210
-
211
- function flow(...funcs) {
212
- return function (...args) {
213
- let result = funcs.length ? funcs[0].apply(this, args) : args[0];
214
- for (let i = 1; i < funcs.length; i++) {
215
- result = funcs[i].call(this, result);
216
- }
217
- return result;
218
- };
219
- }
220
-
221
- function flowRight(...funcs) {
222
- return flow(...funcs.reverse());
186
+ function unary(func) {
187
+ return ary(func, 1);
223
188
  }
224
189
 
225
190
  exports.after = after;
226
191
  exports.ary = ary;
227
- exports.before = before;
228
- exports.curryRight = curryRight;
229
192
  exports.debounce = debounce;
230
193
  exports.flow = flow;
231
194
  exports.flowRight = flowRight;
@@ -76,7 +76,7 @@ function dropRight(arr, itemsCount) {
76
76
 
77
77
  function dropRightWhile(arr, canContinueDropping) {
78
78
  for (let i = arr.length - 1; i >= 0; i--) {
79
- if (!canContinueDropping(arr[i])) {
79
+ if (!canContinueDropping(arr[i], i, arr)) {
80
80
  return arr.slice(0, i + 1);
81
81
  }
82
82
  }
@@ -335,11 +335,10 @@ function union(arr1, arr2) {
335
335
  return uniq(arr1.concat(arr2));
336
336
  }
337
337
 
338
- function unionBy(arr1, arr2, mapper) {
338
+ function uniqBy(arr, mapper) {
339
339
  const map = new Map();
340
- const items = [...arr1, ...arr2];
341
- for (let i = 0; i < items.length; i++) {
342
- const item = items[i];
340
+ for (let i = 0; i < arr.length; i++) {
341
+ const item = arr[i];
343
342
  const key = mapper(item);
344
343
  if (!map.has(key)) {
345
344
  map.set(key, item);
@@ -348,6 +347,10 @@ function unionBy(arr1, arr2, mapper) {
348
347
  return Array.from(map.values());
349
348
  }
350
349
 
350
+ function unionBy(arr1, arr2, mapper) {
351
+ return uniqBy(arr1.concat(arr2), mapper);
352
+ }
353
+
351
354
  function uniqWith(arr, areItemsEqual) {
352
355
  const result = [];
353
356
  for (let i = 0; i < arr.length; i++) {
@@ -364,18 +367,6 @@ function unionWith(arr1, arr2, areItemsEqual) {
364
367
  return uniqWith(arr1.concat(arr2), areItemsEqual);
365
368
  }
366
369
 
367
- function uniqBy(arr, mapper) {
368
- const map = new Map();
369
- for (let i = 0; i < arr.length; i++) {
370
- const item = arr[i];
371
- const key = mapper(item);
372
- if (!map.has(key)) {
373
- map.set(key, item);
374
- }
375
- }
376
- return Array.from(map.values());
377
- }
378
-
379
370
  function unzip(zipped) {
380
371
  let maxLen = 0;
381
372
  for (let i = 0; i < zipped.length; i++) {
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @template T - The type of elements in the array.
8
8
  * @param {T[]} arr - The array from which to drop elements.
9
- * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines
9
+ * @param {(item: T, index: number, arr: T[]) => boolean} canContinueDropping - A predicate function that determines
10
10
  * whether to continue dropping elements. The function is called with each element from the end,
11
11
  * and dropping continues as long as it returns true.
12
12
  * @returns {T[]} A new array with the elements remaining after the predicate returns false.
@@ -16,6 +16,6 @@
16
16
  * const result = dropRightWhile(array, x => x > 3);
17
17
  * // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.
18
18
  */
19
- declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[];
19
+ declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T, index: number, arr: readonly T[]) => boolean): T[];
20
20
 
21
21
  export { dropRightWhile };
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @template T - The type of elements in the array.
8
8
  * @param {T[]} arr - The array from which to drop elements.
9
- * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines
9
+ * @param {(item: T, index: number, arr: T[]) => boolean} canContinueDropping - A predicate function that determines
10
10
  * whether to continue dropping elements. The function is called with each element from the end,
11
11
  * and dropping continues as long as it returns true.
12
12
  * @returns {T[]} A new array with the elements remaining after the predicate returns false.
@@ -16,6 +16,6 @@
16
16
  * const result = dropRightWhile(array, x => x > 3);
17
17
  * // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.
18
18
  */
19
- declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[];
19
+ declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T, index: number, arr: readonly T[]) => boolean): T[];
20
20
 
21
21
  export { dropRightWhile };
@@ -1,6 +1,6 @@
1
1
  function dropRightWhile(arr, canContinueDropping) {
2
2
  for (let i = arr.length - 1; i >= 0; i--) {
3
- if (!canContinueDropping(arr[i])) {
3
+ if (!canContinueDropping(arr[i], i, arr)) {
4
4
  return arr.slice(0, i + 1);
5
5
  }
6
6
  }
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @template T - The type of elements in the array.
8
8
  * @param {T[]} arr - The array from which to drop elements.
9
- * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines
9
+ * @param {(item: T, index: number, arr: T[]) => boolean} canContinueDropping - A predicate function that determines
10
10
  * whether to continue dropping elements. The function is called with each element, and dropping
11
11
  * continues as long as it returns true.
12
12
  * @returns {T[]} A new array with the elements remaining after the predicate returns false.
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @template T - The type of elements in the array.
8
8
  * @param {T[]} arr - The array from which to drop elements.
9
- * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines
9
+ * @param {(item: T, index: number, arr: T[]) => boolean} canContinueDropping - A predicate function that determines
10
10
  * whether to continue dropping elements. The function is called with each element, and dropping
11
11
  * continues as long as it returns true.
12
12
  * @returns {T[]} A new array with the elements remaining after the predicate returns false.