es-toolkit 1.26.1-dev.835 → 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';
@@ -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';
@@ -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;
@@ -2329,21 +2355,6 @@ function defaultTo(value, defaultValue) {
2329
2355
  return value;
2330
2356
  }
2331
2357
 
2332
- function iteratee(value) {
2333
- if (value == null) {
2334
- return (value) => value;
2335
- }
2336
- switch (typeof value) {
2337
- case 'function': {
2338
- return value;
2339
- }
2340
- case 'object': {
2341
- return Array.isArray(value) ? matchesProperty(value[0], value[1]) : matches(value);
2342
- }
2343
- }
2344
- return property(value);
2345
- }
2346
-
2347
2358
  function times(n, getValue) {
2348
2359
  n = toInteger(n);
2349
2360
  if (n < 1 || !Number.isSafeInteger(n)) {
@@ -2383,7 +2394,6 @@ function uniqueId(prefix = '') {
2383
2394
 
2384
2395
  exports.at = zipWith.at;
2385
2396
  exports.countBy = zipWith.countBy;
2386
- exports.differenceBy = zipWith.differenceBy;
2387
2397
  exports.differenceWith = zipWith.differenceWith;
2388
2398
  exports.flatMap = zipWith.flatMap;
2389
2399
  exports.flatMapDeep = zipWith.flatMapDeep;
@@ -2490,6 +2500,7 @@ exports.defaultTo = defaultTo;
2490
2500
  exports.defaults = defaults;
2491
2501
  exports.defer = defer;
2492
2502
  exports.difference = difference;
2503
+ exports.differenceBy = differenceBy;
2493
2504
  exports.drop = drop;
2494
2505
  exports.dropRight = dropRight;
2495
2506
  exports.dropRightWhile = dropRightWhile;
@@ -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';
@@ -2,14 +2,14 @@
2
2
  * Returns a `identity` function when `value` is `null` or `undefined`.
3
3
  *
4
4
  * @param {null} [value] - The value to convert to an iteratee.
5
- * @returns {(value: unknown) => unknown} - Returns a `identity` function.
5
+ * @returns {<T>(value: T) => T} - Returns a `identity` function.
6
6
  *
7
7
  * @example
8
8
  * const func = iteratee();
9
9
  *
10
10
  * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [{ a: 1 }, { a: 2 }, { a: 3 }]
11
11
  */
12
- declare function iteratee(value?: null): (value: unknown) => unknown;
12
+ declare function iteratee(value?: null): <T>(value: T) => T;
13
13
  /**
14
14
  * Returns a given `func` function when `value` is a `function`.
15
15
  *
@@ -29,13 +29,13 @@ declare function iteratee<F extends (...args: any[]) => unknown>(func: F): F;
29
29
  * The created function returns the property value for a given element.
30
30
  *
31
31
  * @param {symbol | number | string | object} value - The value to convert to an iteratee.
32
- * @returns {(...args: any[]) => unknown} - Returns the new iteratee function.
32
+ * @returns {(...args: any[]) => any} - Returns the new iteratee function.
33
33
  *
34
34
  * @example
35
35
  * const func = iteratee('a');
36
36
  *
37
37
  * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
38
38
  */
39
- declare function iteratee(value: symbol | number | string | object): (...args: any[]) => unknown;
39
+ declare function iteratee(value: symbol | number | string | object): (...args: any[]) => any;
40
40
 
41
41
  export { iteratee };
@@ -2,14 +2,14 @@
2
2
  * Returns a `identity` function when `value` is `null` or `undefined`.
3
3
  *
4
4
  * @param {null} [value] - The value to convert to an iteratee.
5
- * @returns {(value: unknown) => unknown} - Returns a `identity` function.
5
+ * @returns {<T>(value: T) => T} - Returns a `identity` function.
6
6
  *
7
7
  * @example
8
8
  * const func = iteratee();
9
9
  *
10
10
  * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [{ a: 1 }, { a: 2 }, { a: 3 }]
11
11
  */
12
- declare function iteratee(value?: null): (value: unknown) => unknown;
12
+ declare function iteratee(value?: null): <T>(value: T) => T;
13
13
  /**
14
14
  * Returns a given `func` function when `value` is a `function`.
15
15
  *
@@ -29,13 +29,13 @@ declare function iteratee<F extends (...args: any[]) => unknown>(func: F): F;
29
29
  * The created function returns the property value for a given element.
30
30
  *
31
31
  * @param {symbol | number | string | object} value - The value to convert to an iteratee.
32
- * @returns {(...args: any[]) => unknown} - Returns the new iteratee function.
32
+ * @returns {(...args: any[]) => any} - Returns the new iteratee function.
33
33
  *
34
34
  * @example
35
35
  * const func = iteratee('a');
36
36
  *
37
37
  * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
38
38
  */
39
- declare function iteratee(value: symbol | number | string | object): (...args: any[]) => unknown;
39
+ declare function iteratee(value: symbol | number | string | object): (...args: any[]) => any;
40
40
 
41
41
  export { iteratee };
@@ -1,10 +1,11 @@
1
+ import { identity } from '../../function/identity.mjs';
1
2
  import { property } from '../object/property.mjs';
2
3
  import { matches } from '../predicate/matches.mjs';
3
4
  import { matchesProperty } from '../predicate/matchesProperty.mjs';
4
5
 
5
6
  function iteratee(value) {
6
7
  if (value == null) {
7
- return (value) => value;
8
+ return identity;
8
9
  }
9
10
  switch (typeof value) {
10
11
  case 'function': {
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.835+62fe7e03",
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": {