es-toolkit 1.26.1-dev.834 → 1.26.1-dev.836

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.
@@ -0,0 +1,8 @@
1
+ type Iteratee<T> = PropertyKey | Partial<T> | ((value: T) => unknown);
2
+ declare function differenceBy<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, iteratee: Iteratee<T1 | T2>): T1[];
3
+ declare function differenceBy<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, iteratee: Iteratee<T1 | T2 | T3>): T1[];
4
+ declare function differenceBy<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, values3: ArrayLike<T4>, iteratee: Iteratee<T1 | T2 | T3 | T4>): T1[];
5
+ declare function differenceBy<T1, T2, T3, T4, T5>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, values3: ArrayLike<T4>, values4: ArrayLike<T5>, iteratee: Iteratee<T1 | T2 | T3 | T4 | T5>): T1[];
6
+ declare function differenceBy<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
7
+
8
+ export { differenceBy };
@@ -0,0 +1,8 @@
1
+ type Iteratee<T> = PropertyKey | Partial<T> | ((value: T) => unknown);
2
+ declare function differenceBy<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, iteratee: Iteratee<T1 | T2>): T1[];
3
+ declare function differenceBy<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, iteratee: Iteratee<T1 | T2 | T3>): T1[];
4
+ declare function differenceBy<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, values3: ArrayLike<T4>, iteratee: Iteratee<T1 | T2 | T3 | T4>): T1[];
5
+ declare function differenceBy<T1, T2, T3, T4, T5>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, values3: ArrayLike<T4>, values4: ArrayLike<T5>, iteratee: Iteratee<T1 | T2 | T3 | T4 | T5>): T1[];
6
+ declare function differenceBy<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
7
+
8
+ export { differenceBy };
@@ -0,0 +1,19 @@
1
+ import { flatten } from './flatten.mjs';
2
+ import { last } from './last.mjs';
3
+ import { difference } from '../../array/difference.mjs';
4
+ import { differenceBy as differenceBy$1 } from '../../array/differenceBy.mjs';
5
+ import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
6
+ import { iteratee } from '../util/iteratee.mjs';
7
+
8
+ function differenceBy(arr, ...values) {
9
+ if (!isArrayLikeObject(arr)) {
10
+ return [];
11
+ }
12
+ const iteratee$1 = last(values);
13
+ if (isArrayLikeObject(iteratee$1)) {
14
+ return difference(Array.from(arr), flatten(values));
15
+ }
16
+ return differenceBy$1(Array.from(arr), flatten(values.slice(0, -1)), iteratee(iteratee$1));
17
+ }
18
+
19
+ export { differenceBy };
@@ -1,6 +1,5 @@
1
1
  export { at } from '../array/at.mjs';
2
2
  export { countBy } from '../array/countBy.mjs';
3
- export { differenceBy } from '../array/differenceBy.mjs';
4
3
  export { differenceWith } from '../array/differenceWith.mjs';
5
4
  export { flatMap } from '../array/flatMap.mjs';
6
5
  export { flatMapDeep } from '../array/flatMapDeep.mjs';
@@ -85,6 +84,7 @@ export { chunk } from './array/chunk.mjs';
85
84
  export { compact } from './array/compact.mjs';
86
85
  export { concat } from './array/concat.mjs';
87
86
  export { difference } from './array/difference.mjs';
87
+ export { differenceBy } from './array/differenceBy.mjs';
88
88
  export { drop } from './array/drop.mjs';
89
89
  export { dropRight } from './array/dropRight.mjs';
90
90
  export { dropRightWhile } from './array/dropRightWhile.mjs';
@@ -210,6 +210,7 @@ export { upperCase } from './string/upperCase.mjs';
210
210
  export { constant } from './util/constant.mjs';
211
211
  export { defaultTo } from './util/defaultTo.mjs';
212
212
  export { eq } from './util/eq.mjs';
213
+ export { iteratee } from './util/iteratee.mjs';
213
214
  export { times } from './util/times.mjs';
214
215
  export { toFinite } from './util/toFinite.mjs';
215
216
  export { toInteger } from './util/toInteger.mjs';
@@ -1,6 +1,5 @@
1
1
  export { at } from '../array/at.js';
2
2
  export { countBy } from '../array/countBy.js';
3
- export { differenceBy } from '../array/differenceBy.js';
4
3
  export { differenceWith } from '../array/differenceWith.js';
5
4
  export { flatMap } from '../array/flatMap.js';
6
5
  export { flatMapDeep } from '../array/flatMapDeep.js';
@@ -85,6 +84,7 @@ export { chunk } from './array/chunk.js';
85
84
  export { compact } from './array/compact.js';
86
85
  export { concat } from './array/concat.js';
87
86
  export { difference } from './array/difference.js';
87
+ export { differenceBy } from './array/differenceBy.js';
88
88
  export { drop } from './array/drop.js';
89
89
  export { dropRight } from './array/dropRight.js';
90
90
  export { dropRightWhile } from './array/dropRightWhile.js';
@@ -210,6 +210,7 @@ export { upperCase } from './string/upperCase.js';
210
210
  export { constant } from './util/constant.js';
211
211
  export { defaultTo } from './util/defaultTo.js';
212
212
  export { eq } from './util/eq.js';
213
+ export { iteratee } from './util/iteratee.js';
213
214
  export { times } from './util/times.js';
214
215
  export { toFinite } from './util/toFinite.js';
215
216
  export { toInteger } from './util/toInteger.js';
@@ -63,49 +63,40 @@ function difference(arr, ...values) {
63
63
  return zipWith.difference(arr1, arr2);
64
64
  }
65
65
 
66
- function isSymbol(value) {
67
- return typeof value === 'symbol' || value instanceof Symbol;
68
- }
69
-
70
- function toNumber(value) {
71
- if (isSymbol(value)) {
72
- return NaN;
73
- }
74
- return Number(value);
75
- }
76
-
77
- function toFinite(value) {
78
- if (!value) {
79
- return value === 0 ? value : 0;
80
- }
81
- value = toNumber(value);
82
- if (value === Infinity || value === -Infinity) {
83
- const sign = value < 0 ? -1 : 1;
84
- return sign * Number.MAX_VALUE;
85
- }
86
- return value === value ? value : 0;
87
- }
88
-
89
- function toInteger(value) {
90
- const finite = toFinite(value);
91
- const remainder = finite % 1;
92
- return remainder ? finite - remainder : finite;
93
- }
94
-
95
- function drop(collection, itemsCount = 1, guard) {
96
- if (!isArrayLike(collection)) {
97
- return [];
66
+ function flatten(value, depth = 1) {
67
+ const result = [];
68
+ const flooredDepth = Math.floor(depth);
69
+ if (!isArrayLike(value)) {
70
+ return result;
98
71
  }
99
- itemsCount = guard ? 1 : toInteger(itemsCount);
100
- return zipWith.drop(Array.from(collection), itemsCount);
72
+ const recursive = (arr, currentDepth) => {
73
+ for (let i = 0; i < arr.length; i++) {
74
+ const item = arr[i];
75
+ if (currentDepth < flooredDepth &&
76
+ (Array.isArray(item) ||
77
+ Boolean(item?.[Symbol.isConcatSpreadable]) ||
78
+ (item !== null && typeof item === 'object' && Object.prototype.toString.call(item) === '[object Arguments]'))) {
79
+ if (Array.isArray(item)) {
80
+ recursive(item, currentDepth + 1);
81
+ }
82
+ else {
83
+ recursive(Array.from(item), currentDepth + 1);
84
+ }
85
+ }
86
+ else {
87
+ result.push(item);
88
+ }
89
+ }
90
+ };
91
+ recursive(Array.from(value), 0);
92
+ return result;
101
93
  }
102
94
 
103
- function dropRight(collection, itemsCount = 1, guard) {
104
- if (!isArrayLike(collection)) {
105
- return [];
95
+ function last(array) {
96
+ if (!isArrayLike(array)) {
97
+ return undefined;
106
98
  }
107
- itemsCount = guard ? 1 : toInteger(itemsCount);
108
- return zipWith.dropRight(Array.from(collection), itemsCount);
99
+ return zipWith.last(Array.from(array));
109
100
  }
110
101
 
111
102
  function isDeepKey(key) {
@@ -441,6 +432,77 @@ function matchesProperty(property, source) {
441
432
  };
442
433
  }
443
434
 
435
+ function iteratee(value) {
436
+ if (value == null) {
437
+ return unary.identity;
438
+ }
439
+ switch (typeof value) {
440
+ case 'function': {
441
+ return value;
442
+ }
443
+ case 'object': {
444
+ return Array.isArray(value) ? matchesProperty(value[0], value[1]) : matches(value);
445
+ }
446
+ }
447
+ return property(value);
448
+ }
449
+
450
+ function differenceBy(arr, ...values) {
451
+ if (!isArrayLikeObject(arr)) {
452
+ return [];
453
+ }
454
+ const iteratee$1 = last(values);
455
+ if (isArrayLikeObject(iteratee$1)) {
456
+ return zipWith.difference(Array.from(arr), flatten(values));
457
+ }
458
+ return zipWith.differenceBy(Array.from(arr), flatten(values.slice(0, -1)), iteratee(iteratee$1));
459
+ }
460
+
461
+ function isSymbol(value) {
462
+ return typeof value === 'symbol' || value instanceof Symbol;
463
+ }
464
+
465
+ function toNumber(value) {
466
+ if (isSymbol(value)) {
467
+ return NaN;
468
+ }
469
+ return Number(value);
470
+ }
471
+
472
+ function toFinite(value) {
473
+ if (!value) {
474
+ return value === 0 ? value : 0;
475
+ }
476
+ value = toNumber(value);
477
+ if (value === Infinity || value === -Infinity) {
478
+ const sign = value < 0 ? -1 : 1;
479
+ return sign * Number.MAX_VALUE;
480
+ }
481
+ return value === value ? value : 0;
482
+ }
483
+
484
+ function toInteger(value) {
485
+ const finite = toFinite(value);
486
+ const remainder = finite % 1;
487
+ return remainder ? finite - remainder : finite;
488
+ }
489
+
490
+ function drop(collection, itemsCount = 1, guard) {
491
+ if (!isArrayLike(collection)) {
492
+ return [];
493
+ }
494
+ itemsCount = guard ? 1 : toInteger(itemsCount);
495
+ return zipWith.drop(Array.from(collection), itemsCount);
496
+ }
497
+
498
+ function dropRight(collection, itemsCount = 1, guard) {
499
+ if (!isArrayLike(collection)) {
500
+ return [];
501
+ }
502
+ itemsCount = guard ? 1 : toInteger(itemsCount);
503
+ return zipWith.dropRight(Array.from(collection), itemsCount);
504
+ }
505
+
444
506
  function dropRightWhile(arr, predicate) {
445
507
  if (!isArrayLike(arr)) {
446
508
  return [];
@@ -708,35 +770,6 @@ function findLastIndex(arr, doesMatch, fromIndex = arr ? arr.length - 1 : 0) {
708
770
  }
709
771
  }
710
772
 
711
- function flatten(value, depth = 1) {
712
- const result = [];
713
- const flooredDepth = Math.floor(depth);
714
- if (!isArrayLike(value)) {
715
- return result;
716
- }
717
- const recursive = (arr, currentDepth) => {
718
- for (let i = 0; i < arr.length; i++) {
719
- const item = arr[i];
720
- if (currentDepth < flooredDepth &&
721
- (Array.isArray(item) ||
722
- Boolean(item?.[Symbol.isConcatSpreadable]) ||
723
- (item !== null && typeof item === 'object' && Object.prototype.toString.call(item) === '[object Arguments]'))) {
724
- if (Array.isArray(item)) {
725
- recursive(item, currentDepth + 1);
726
- }
727
- else {
728
- recursive(Array.from(item), currentDepth + 1);
729
- }
730
- }
731
- else {
732
- result.push(item);
733
- }
734
- }
735
- };
736
- recursive(Array.from(value), 0);
737
- return result;
738
- }
739
-
740
773
  function flattenDeep(value) {
741
774
  return flatten(value, Infinity);
742
775
  }
@@ -859,13 +892,6 @@ function join(array, separator = ',') {
859
892
  return Array.from(array).join(separator);
860
893
  }
861
894
 
862
- function last(array) {
863
- if (!isArrayLike(array)) {
864
- return undefined;
865
- }
866
- return zipWith.last(Array.from(array));
867
- }
868
-
869
895
  function getPriority(a) {
870
896
  if (typeof a === 'symbol') {
871
897
  return 1;
@@ -2368,7 +2394,6 @@ function uniqueId(prefix = '') {
2368
2394
 
2369
2395
  exports.at = zipWith.at;
2370
2396
  exports.countBy = zipWith.countBy;
2371
- exports.differenceBy = zipWith.differenceBy;
2372
2397
  exports.differenceWith = zipWith.differenceWith;
2373
2398
  exports.flatMap = zipWith.flatMap;
2374
2399
  exports.flatMapDeep = zipWith.flatMapDeep;
@@ -2475,6 +2500,7 @@ exports.defaultTo = defaultTo;
2475
2500
  exports.defaults = defaults;
2476
2501
  exports.defer = defer;
2477
2502
  exports.difference = difference;
2503
+ exports.differenceBy = differenceBy;
2478
2504
  exports.drop = drop;
2479
2505
  exports.dropRight = dropRight;
2480
2506
  exports.dropRightWhile = dropRightWhile;
@@ -2531,6 +2557,7 @@ exports.isSymbol = isSymbol;
2531
2557
  exports.isTypedArray = isTypedArray;
2532
2558
  exports.isWeakMap = isWeakMap;
2533
2559
  exports.isWeakSet = isWeakSet;
2560
+ exports.iteratee = iteratee;
2534
2561
  exports.join = join;
2535
2562
  exports.kebabCase = kebabCase;
2536
2563
  exports.last = last;
@@ -1,6 +1,5 @@
1
1
  export { at } from '../array/at.mjs';
2
2
  export { countBy } from '../array/countBy.mjs';
3
- export { differenceBy } from '../array/differenceBy.mjs';
4
3
  export { differenceWith } from '../array/differenceWith.mjs';
5
4
  export { flatMap } from '../array/flatMap.mjs';
6
5
  export { flatMapDeep } from '../array/flatMapDeep.mjs';
@@ -87,6 +86,7 @@ export { chunk } from './array/chunk.mjs';
87
86
  export { compact } from './array/compact.mjs';
88
87
  export { concat } from './array/concat.mjs';
89
88
  export { difference } from './array/difference.mjs';
89
+ export { differenceBy } from './array/differenceBy.mjs';
90
90
  export { drop } from './array/drop.mjs';
91
91
  export { dropRight } from './array/dropRight.mjs';
92
92
  export { dropRightWhile } from './array/dropRightWhile.mjs';
@@ -210,6 +210,7 @@ export { trimStart } from './string/trimStart.mjs';
210
210
  export { upperCase } from './string/upperCase.mjs';
211
211
  export { constant } from './util/constant.mjs';
212
212
  export { defaultTo } from './util/defaultTo.mjs';
213
+ export { iteratee } from './util/iteratee.mjs';
213
214
  export { times } from './util/times.mjs';
214
215
  export { toFinite } from './util/toFinite.mjs';
215
216
  export { toInteger } from './util/toInteger.mjs';
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Returns a `identity` function when `value` is `null` or `undefined`.
3
+ *
4
+ * @param {null} [value] - The value to convert to an iteratee.
5
+ * @returns {<T>(value: T) => T} - Returns a `identity` function.
6
+ *
7
+ * @example
8
+ * const func = iteratee();
9
+ *
10
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [{ a: 1 }, { a: 2 }, { a: 3 }]
11
+ */
12
+ declare function iteratee(value?: null): <T>(value: T) => T;
13
+ /**
14
+ * Returns a given `func` function when `value` is a `function`.
15
+ *
16
+ * @template {(...args: any[]) => unknown} F - The function type.
17
+ * @param {F} func - The function to return.
18
+ * @returns {F} - Returns the given function.
19
+ *
20
+ * @example
21
+ * const func = iteratee((object) => object.a);
22
+ *
23
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
24
+ */
25
+ declare function iteratee<F extends (...args: any[]) => unknown>(func: F): F;
26
+ /**
27
+ * Creates a function that invokes `value` with the arguments of the created function.
28
+ *
29
+ * The created function returns the property value for a given element.
30
+ *
31
+ * @param {symbol | number | string | object} value - The value to convert to an iteratee.
32
+ * @returns {(...args: any[]) => any} - Returns the new iteratee function.
33
+ *
34
+ * @example
35
+ * const func = iteratee('a');
36
+ *
37
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
38
+ */
39
+ declare function iteratee(value: symbol | number | string | object): (...args: any[]) => any;
40
+
41
+ export { iteratee };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Returns a `identity` function when `value` is `null` or `undefined`.
3
+ *
4
+ * @param {null} [value] - The value to convert to an iteratee.
5
+ * @returns {<T>(value: T) => T} - Returns a `identity` function.
6
+ *
7
+ * @example
8
+ * const func = iteratee();
9
+ *
10
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [{ a: 1 }, { a: 2 }, { a: 3 }]
11
+ */
12
+ declare function iteratee(value?: null): <T>(value: T) => T;
13
+ /**
14
+ * Returns a given `func` function when `value` is a `function`.
15
+ *
16
+ * @template {(...args: any[]) => unknown} F - The function type.
17
+ * @param {F} func - The function to return.
18
+ * @returns {F} - Returns the given function.
19
+ *
20
+ * @example
21
+ * const func = iteratee((object) => object.a);
22
+ *
23
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
24
+ */
25
+ declare function iteratee<F extends (...args: any[]) => unknown>(func: F): F;
26
+ /**
27
+ * Creates a function that invokes `value` with the arguments of the created function.
28
+ *
29
+ * The created function returns the property value for a given element.
30
+ *
31
+ * @param {symbol | number | string | object} value - The value to convert to an iteratee.
32
+ * @returns {(...args: any[]) => any} - Returns the new iteratee function.
33
+ *
34
+ * @example
35
+ * const func = iteratee('a');
36
+ *
37
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
38
+ */
39
+ declare function iteratee(value: symbol | number | string | object): (...args: any[]) => any;
40
+
41
+ export { iteratee };
@@ -0,0 +1,21 @@
1
+ import { identity } from '../../function/identity.mjs';
2
+ import { property } from '../object/property.mjs';
3
+ import { matches } from '../predicate/matches.mjs';
4
+ import { matchesProperty } from '../predicate/matchesProperty.mjs';
5
+
6
+ function iteratee(value) {
7
+ if (value == null) {
8
+ return identity;
9
+ }
10
+ switch (typeof value) {
11
+ case 'function': {
12
+ return value;
13
+ }
14
+ case 'object': {
15
+ return Array.isArray(value) ? matchesProperty(value[0], value[1]) : matches(value);
16
+ }
17
+ }
18
+ return property(value);
19
+ }
20
+
21
+ export { iteratee };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.26.1-dev.834+10205c01",
4
+ "version": "1.26.1-dev.836+e94c4012",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {