es-toolkit 1.13.1-dev.364 → 1.13.1-dev.365

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,25 @@
1
+ /**
2
+ * Utility type for recursively unpacking nested array types to extract the type of the innermost element
3
+ *
4
+ * @example
5
+ * ExtractNestedArrayType<(number | (number | number[])[])[]>
6
+ * // number
7
+ *
8
+ * ExtractNestedArrayType<(boolean | (string | number[])[])[]>
9
+ * // string | number | boolean
10
+ */
11
+ type ExtractNestedArrayType<T> = T extends ReadonlyArray<infer U> ? ExtractNestedArrayType<U> : T;
12
+ /**
13
+ * Flattens all depths of a nested array.
14
+ *
15
+ * @template T - The type of elements within the array.
16
+ * @param {T[] | object} value - The value to flatten.
17
+ * @returns {Array<ExtractNestedArrayType<T>> | []} A new array that has been flattened.
18
+ *
19
+ * @example
20
+ * const value = flattenDeep([1, [2, [3]], [4, [5, 6]]]);
21
+ * // Returns: [1, 2, 3, 4, 5, 6]
22
+ */
23
+ declare function flattenDeep<T>(value: readonly T[] | object): Array<ExtractNestedArrayType<T>> | [];
24
+
25
+ export { flattenDeep };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Utility type for recursively unpacking nested array types to extract the type of the innermost element
3
+ *
4
+ * @example
5
+ * ExtractNestedArrayType<(number | (number | number[])[])[]>
6
+ * // number
7
+ *
8
+ * ExtractNestedArrayType<(boolean | (string | number[])[])[]>
9
+ * // string | number | boolean
10
+ */
11
+ type ExtractNestedArrayType<T> = T extends ReadonlyArray<infer U> ? ExtractNestedArrayType<U> : T;
12
+ /**
13
+ * Flattens all depths of a nested array.
14
+ *
15
+ * @template T - The type of elements within the array.
16
+ * @param {T[] | object} value - The value to flatten.
17
+ * @returns {Array<ExtractNestedArrayType<T>> | []} A new array that has been flattened.
18
+ *
19
+ * @example
20
+ * const value = flattenDeep([1, [2, [3]], [4, [5, 6]]]);
21
+ * // Returns: [1, 2, 3, 4, 5, 6]
22
+ */
23
+ declare function flattenDeep<T>(value: readonly T[] | object): Array<ExtractNestedArrayType<T>> | [];
24
+
25
+ export { flattenDeep };
@@ -0,0 +1,7 @@
1
+ import { flatten } from './flatten.mjs';
2
+
3
+ function flattenDeep(value) {
4
+ return flatten(value, Infinity);
5
+ }
6
+
7
+ export { flattenDeep };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Flattens an array up to the specified depth.
3
+ *
4
+ * @template T - The type of elements within the array.
5
+ * @template D - The depth to which the array should be flattened.
6
+ * @param {T[] | object} value - The value to flatten.
7
+ * @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
8
+ * @returns {Array<FlatArray<T[], D>> | []} A new array that has been flattened.
9
+ *
10
+ * @example
11
+ * const arr = flatten([1, [2, 3], [4, [5, 6]]], 1);
12
+ * // Returns: [1, 2, 3, 4, [5, 6]]
13
+ *
14
+ * const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
15
+ * // Returns: [1, 2, 3, 4, 5, 6]
16
+ */
17
+ declare function flattenDepth<T, D extends number = 1>(value: T[] | object, depth?: D): Array<FlatArray<T[], D>> | [];
18
+
19
+ export { flattenDepth };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Flattens an array up to the specified depth.
3
+ *
4
+ * @template T - The type of elements within the array.
5
+ * @template D - The depth to which the array should be flattened.
6
+ * @param {T[] | object} value - The value to flatten.
7
+ * @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
8
+ * @returns {Array<FlatArray<T[], D>> | []} A new array that has been flattened.
9
+ *
10
+ * @example
11
+ * const arr = flatten([1, [2, 3], [4, [5, 6]]], 1);
12
+ * // Returns: [1, 2, 3, 4, [5, 6]]
13
+ *
14
+ * const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
15
+ * // Returns: [1, 2, 3, 4, 5, 6]
16
+ */
17
+ declare function flattenDepth<T, D extends number = 1>(value: T[] | object, depth?: D): Array<FlatArray<T[], D>> | [];
18
+
19
+ export { flattenDepth };
@@ -0,0 +1,7 @@
1
+ import { flatten } from './flatten.mjs';
2
+
3
+ function flattenDepth(value, depth = 1) {
4
+ return flatten(value, depth);
5
+ }
6
+
7
+ export { flattenDepth };
@@ -7,7 +7,6 @@ export { dropRight } from '../array/dropRight.mjs';
7
7
  export { dropRightWhile } from '../array/dropRightWhile.mjs';
8
8
  export { dropWhile } from '../array/dropWhile.mjs';
9
9
  export { flatMap } from '../array/flatMap.mjs';
10
- export { flattenDeep } from '../array/flattenDeep.mjs';
11
10
  export { forEachRight } from '../array/forEachRight.mjs';
12
11
  export { groupBy } from '../array/groupBy.mjs';
13
12
  export { intersection } from '../array/intersection.mjs';
@@ -99,6 +98,8 @@ export { concat } from './array/concat.mjs';
99
98
  export { difference } from './array/difference.mjs';
100
99
  export { fill } from './array/fill.mjs';
101
100
  export { flatten } from './array/flatten.mjs';
101
+ export { flattenDeep } from './array/flattenDeep.mjs';
102
+ export { flattenDepth } from './array/flattenDepth.mjs';
102
103
  export { zipObjectDeep } from './array/zipObjectDeep.mjs';
103
104
  export { get } from './object/get.mjs';
104
105
  export { set } from './object/set.mjs';
@@ -7,7 +7,6 @@ export { dropRight } from '../array/dropRight.js';
7
7
  export { dropRightWhile } from '../array/dropRightWhile.js';
8
8
  export { dropWhile } from '../array/dropWhile.js';
9
9
  export { flatMap } from '../array/flatMap.js';
10
- export { flattenDeep } from '../array/flattenDeep.js';
11
10
  export { forEachRight } from '../array/forEachRight.js';
12
11
  export { groupBy } from '../array/groupBy.js';
13
12
  export { intersection } from '../array/intersection.js';
@@ -99,6 +98,8 @@ export { concat } from './array/concat.js';
99
98
  export { difference } from './array/difference.js';
100
99
  export { fill } from './array/fill.js';
101
100
  export { flatten } from './array/flatten.js';
101
+ export { flattenDeep } from './array/flattenDeep.js';
102
+ export { flattenDepth } from './array/flattenDepth.js';
102
103
  export { zipObjectDeep } from './array/zipObjectDeep.js';
103
104
  export { get } from './object/get.js';
104
105
  export { set } from './object/set.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const array_index = require('../array/index.js');
5
+ const size = require('../_chunk/size-CJyNw8.js');
6
6
  const isNil = require('../_chunk/isNil-IuJ4cv.js');
7
7
  const promise_index = require('../_chunk/index-CwRt_M.js');
8
8
  const function_index = require('../function/index.js');
@@ -13,22 +13,22 @@ const predicate_index = require('../predicate/index.js');
13
13
  const isPrimitive = require('../_chunk/isPrimitive-BBs6Fb.js');
14
14
  const string_index = require('../string/index.js');
15
15
 
16
- function chunk(arr, size = 1) {
17
- size = Math.max(Math.floor(size), 0);
18
- if (size === 0) {
16
+ function chunk(arr, size$1 = 1) {
17
+ size$1 = Math.max(Math.floor(size$1), 0);
18
+ if (size$1 === 0) {
19
19
  return [];
20
20
  }
21
- return array_index.chunk(arr, size);
21
+ return size.chunk(arr, size$1);
22
22
  }
23
23
 
24
24
  function concat(...values) {
25
- return array_index.flatten(values);
25
+ return size.flatten(values);
26
26
  }
27
27
 
28
28
  function difference(arr, ...values) {
29
29
  const arr1 = arr;
30
- const arr2 = array_index.flatten(values);
31
- return array_index.difference(arr1, arr2);
30
+ const arr2 = size.flatten(values);
31
+ return size.difference(arr1, arr2);
32
32
  }
33
33
 
34
34
  function fill(array, value, start = 0, end = array.length) {
@@ -40,7 +40,7 @@ function fill(array, value, start = 0, end = array.length) {
40
40
  if (!end) {
41
41
  end = 0;
42
42
  }
43
- return array_index.fill(array, value, start, end);
43
+ return size.fill(array, value, start, end);
44
44
  }
45
45
 
46
46
  function flatten(value, depth = 1) {
@@ -71,6 +71,14 @@ function flatten(value, depth = 1) {
71
71
  return result;
72
72
  }
73
73
 
74
+ function flattenDeep(value) {
75
+ return flatten(value, Infinity);
76
+ }
77
+
78
+ function flattenDepth(value, depth = 1) {
79
+ return flatten(value, depth);
80
+ }
81
+
74
82
  const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
75
83
  function isIndex(value) {
76
84
  switch (typeof value) {
@@ -147,7 +155,7 @@ function set(obj, path, value) {
147
155
 
148
156
  function zipObjectDeep(keys, values) {
149
157
  const result = {};
150
- const zipped = array_index.zip(keys, values);
158
+ const zipped = size.zip(keys, values);
151
159
  for (let i = 0; i < zipped.length; i++) {
152
160
  const [key, value] = zipped[i];
153
161
  if (key != null) {
@@ -398,53 +406,52 @@ function min(items = []) {
398
406
  return minElement;
399
407
  }
400
408
 
401
- exports.compact = array_index.compact;
402
- exports.countBy = array_index.countBy;
403
- exports.differenceBy = array_index.differenceBy;
404
- exports.differenceWith = array_index.differenceWith;
405
- exports.drop = array_index.drop;
406
- exports.dropRight = array_index.dropRight;
407
- exports.dropRightWhile = array_index.dropRightWhile;
408
- exports.dropWhile = array_index.dropWhile;
409
- exports.first = array_index.head;
410
- exports.flatMap = array_index.flatMap;
411
- exports.flattenDeep = array_index.flattenDeep;
412
- exports.forEachRight = array_index.forEachRight;
413
- exports.groupBy = array_index.groupBy;
414
- exports.head = array_index.head;
415
- exports.initial = array_index.initial;
416
- exports.intersection = array_index.intersection;
417
- exports.intersectionBy = array_index.intersectionBy;
418
- exports.intersectionWith = array_index.intersectionWith;
419
- exports.keyBy = array_index.keyBy;
420
- exports.last = array_index.last;
421
- exports.maxBy = array_index.maxBy;
422
- exports.minBy = array_index.minBy;
423
- exports.orderBy = array_index.orderBy;
424
- exports.partition = array_index.partition;
425
- exports.sample = array_index.sample;
426
- exports.sampleSize = array_index.sampleSize;
427
- exports.shuffle = array_index.shuffle;
428
- exports.size = array_index.size;
429
- exports.tail = array_index.tail;
430
- exports.take = array_index.take;
431
- exports.takeRight = array_index.takeRight;
432
- exports.takeRightWhile = array_index.takeRightWhile;
433
- exports.takeWhile = array_index.takeWhile;
434
- exports.toFilled = array_index.toFilled;
435
- exports.unionBy = array_index.unionBy;
436
- exports.unionWith = array_index.unionWith;
437
- exports.uniqBy = array_index.uniqBy;
438
- exports.uniqWith = array_index.uniqWith;
439
- exports.unzip = array_index.unzip;
440
- exports.unzipWith = array_index.unzipWith;
441
- exports.without = array_index.without;
442
- exports.xor = array_index.xor;
443
- exports.xorBy = array_index.xorBy;
444
- exports.xorWith = array_index.xorWith;
445
- exports.zip = array_index.zip;
446
- exports.zipObject = array_index.zipObject;
447
- exports.zipWith = array_index.zipWith;
409
+ exports.compact = size.compact;
410
+ exports.countBy = size.countBy;
411
+ exports.differenceBy = size.differenceBy;
412
+ exports.differenceWith = size.differenceWith;
413
+ exports.drop = size.drop;
414
+ exports.dropRight = size.dropRight;
415
+ exports.dropRightWhile = size.dropRightWhile;
416
+ exports.dropWhile = size.dropWhile;
417
+ exports.first = size.head;
418
+ exports.flatMap = size.flatMap;
419
+ exports.forEachRight = size.forEachRight;
420
+ exports.groupBy = size.groupBy;
421
+ exports.head = size.head;
422
+ exports.initial = size.initial;
423
+ exports.intersection = size.intersection;
424
+ exports.intersectionBy = size.intersectionBy;
425
+ exports.intersectionWith = size.intersectionWith;
426
+ exports.keyBy = size.keyBy;
427
+ exports.last = size.last;
428
+ exports.maxBy = size.maxBy;
429
+ exports.minBy = size.minBy;
430
+ exports.orderBy = size.orderBy;
431
+ exports.partition = size.partition;
432
+ exports.sample = size.sample;
433
+ exports.sampleSize = size.sampleSize;
434
+ exports.shuffle = size.shuffle;
435
+ exports.size = size.size;
436
+ exports.tail = size.tail;
437
+ exports.take = size.take;
438
+ exports.takeRight = size.takeRight;
439
+ exports.takeRightWhile = size.takeRightWhile;
440
+ exports.takeWhile = size.takeWhile;
441
+ exports.toFilled = size.toFilled;
442
+ exports.unionBy = size.unionBy;
443
+ exports.unionWith = size.unionWith;
444
+ exports.uniqBy = size.uniqBy;
445
+ exports.uniqWith = size.uniqWith;
446
+ exports.unzip = size.unzip;
447
+ exports.unzipWith = size.unzipWith;
448
+ exports.without = size.without;
449
+ exports.xor = size.xor;
450
+ exports.xorBy = size.xorBy;
451
+ exports.xorWith = size.xorWith;
452
+ exports.zip = size.zip;
453
+ exports.zipObject = size.zipObject;
454
+ exports.zipWith = size.zipWith;
448
455
  exports.isNil = isNil.isNil;
449
456
  exports.union = isNil.union;
450
457
  exports.uniq = isNil.uniq;
@@ -501,6 +508,8 @@ exports.difference = difference;
501
508
  exports.endsWith = endsWith;
502
509
  exports.fill = fill;
503
510
  exports.flatten = flatten;
511
+ exports.flattenDeep = flattenDeep;
512
+ exports.flattenDepth = flattenDepth;
504
513
  exports.get = get;
505
514
  exports.isArray = isArray;
506
515
  exports.isMatch = isMatch;
@@ -7,7 +7,6 @@ export { dropRight } from '../array/dropRight.mjs';
7
7
  export { dropRightWhile } from '../array/dropRightWhile.mjs';
8
8
  export { dropWhile } from '../array/dropWhile.mjs';
9
9
  export { flatMap } from '../array/flatMap.mjs';
10
- export { flattenDeep } from '../array/flattenDeep.mjs';
11
10
  export { forEachRight } from '../array/forEachRight.mjs';
12
11
  export { groupBy } from '../array/groupBy.mjs';
13
12
  export { intersection } from '../array/intersection.mjs';
@@ -99,6 +98,8 @@ export { concat } from './array/concat.mjs';
99
98
  export { difference } from './array/difference.mjs';
100
99
  export { fill } from './array/fill.mjs';
101
100
  export { flatten } from './array/flatten.mjs';
101
+ export { flattenDeep } from './array/flattenDeep.mjs';
102
+ export { flattenDepth } from './array/flattenDepth.mjs';
102
103
  export { zipObjectDeep } from './array/zipObjectDeep.mjs';
103
104
  export { get } from './object/get.mjs';
104
105
  export { set } from './object/set.mjs';
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
+ const size = require('./_chunk/size-CJyNw8.js');
5
6
  const array_index = require('./array/index.js');
6
7
  const isNil = require('./_chunk/isNil-IuJ4cv.js');
7
8
  const promise_index = require('./_chunk/index-CwRt_M.js');
@@ -15,56 +16,56 @@ const string_index = require('./string/index.js');
15
16
 
16
17
 
17
18
 
18
- exports.chunk = array_index.chunk;
19
- exports.compact = array_index.compact;
20
- exports.countBy = array_index.countBy;
21
- exports.difference = array_index.difference;
22
- exports.differenceBy = array_index.differenceBy;
23
- exports.differenceWith = array_index.differenceWith;
24
- exports.drop = array_index.drop;
25
- exports.dropRight = array_index.dropRight;
26
- exports.dropRightWhile = array_index.dropRightWhile;
27
- exports.dropWhile = array_index.dropWhile;
28
- exports.fill = array_index.fill;
29
- exports.flatMap = array_index.flatMap;
30
- exports.flatten = array_index.flatten;
19
+ exports.chunk = size.chunk;
20
+ exports.compact = size.compact;
21
+ exports.countBy = size.countBy;
22
+ exports.difference = size.difference;
23
+ exports.differenceBy = size.differenceBy;
24
+ exports.differenceWith = size.differenceWith;
25
+ exports.drop = size.drop;
26
+ exports.dropRight = size.dropRight;
27
+ exports.dropRightWhile = size.dropRightWhile;
28
+ exports.dropWhile = size.dropWhile;
29
+ exports.fill = size.fill;
30
+ exports.flatMap = size.flatMap;
31
+ exports.flatten = size.flatten;
32
+ exports.forEachRight = size.forEachRight;
33
+ exports.groupBy = size.groupBy;
34
+ exports.head = size.head;
35
+ exports.initial = size.initial;
36
+ exports.intersection = size.intersection;
37
+ exports.intersectionBy = size.intersectionBy;
38
+ exports.intersectionWith = size.intersectionWith;
39
+ exports.keyBy = size.keyBy;
40
+ exports.last = size.last;
41
+ exports.maxBy = size.maxBy;
42
+ exports.minBy = size.minBy;
43
+ exports.orderBy = size.orderBy;
44
+ exports.partition = size.partition;
45
+ exports.sample = size.sample;
46
+ exports.sampleSize = size.sampleSize;
47
+ exports.shuffle = size.shuffle;
48
+ exports.size = size.size;
49
+ exports.tail = size.tail;
50
+ exports.take = size.take;
51
+ exports.takeRight = size.takeRight;
52
+ exports.takeRightWhile = size.takeRightWhile;
53
+ exports.takeWhile = size.takeWhile;
54
+ exports.toFilled = size.toFilled;
55
+ exports.unionBy = size.unionBy;
56
+ exports.unionWith = size.unionWith;
57
+ exports.uniqBy = size.uniqBy;
58
+ exports.uniqWith = size.uniqWith;
59
+ exports.unzip = size.unzip;
60
+ exports.unzipWith = size.unzipWith;
61
+ exports.without = size.without;
62
+ exports.xor = size.xor;
63
+ exports.xorBy = size.xorBy;
64
+ exports.xorWith = size.xorWith;
65
+ exports.zip = size.zip;
66
+ exports.zipObject = size.zipObject;
67
+ exports.zipWith = size.zipWith;
31
68
  exports.flattenDeep = array_index.flattenDeep;
32
- exports.forEachRight = array_index.forEachRight;
33
- exports.groupBy = array_index.groupBy;
34
- exports.head = array_index.head;
35
- exports.initial = array_index.initial;
36
- exports.intersection = array_index.intersection;
37
- exports.intersectionBy = array_index.intersectionBy;
38
- exports.intersectionWith = array_index.intersectionWith;
39
- exports.keyBy = array_index.keyBy;
40
- exports.last = array_index.last;
41
- exports.maxBy = array_index.maxBy;
42
- exports.minBy = array_index.minBy;
43
- exports.orderBy = array_index.orderBy;
44
- exports.partition = array_index.partition;
45
- exports.sample = array_index.sample;
46
- exports.sampleSize = array_index.sampleSize;
47
- exports.shuffle = array_index.shuffle;
48
- exports.size = array_index.size;
49
- exports.tail = array_index.tail;
50
- exports.take = array_index.take;
51
- exports.takeRight = array_index.takeRight;
52
- exports.takeRightWhile = array_index.takeRightWhile;
53
- exports.takeWhile = array_index.takeWhile;
54
- exports.toFilled = array_index.toFilled;
55
- exports.unionBy = array_index.unionBy;
56
- exports.unionWith = array_index.unionWith;
57
- exports.uniqBy = array_index.uniqBy;
58
- exports.uniqWith = array_index.uniqWith;
59
- exports.unzip = array_index.unzip;
60
- exports.unzipWith = array_index.unzipWith;
61
- exports.without = array_index.without;
62
- exports.xor = array_index.xor;
63
- exports.xorBy = array_index.xorBy;
64
- exports.xorWith = array_index.xorWith;
65
- exports.zip = array_index.zip;
66
- exports.zipObject = array_index.zipObject;
67
- exports.zipWith = array_index.zipWith;
68
69
  exports.isNil = isNil.isNil;
69
70
  exports.union = isNil.union;
70
71
  exports.uniq = isNil.uniq;
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.13.1-dev.364+b2817323",
4
+ "version": "1.13.1-dev.365+f715a730",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {