es-toolkit 1.8.0-dev.167 → 1.8.0-dev.169

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.
@@ -1,4 +1,7 @@
1
- import "../chunk-467PWPPF.mjs";
1
+ import "../chunk-LOY6PATI.mjs";
2
+ import {
3
+ without
4
+ } from "../chunk-PYEYV7BY.mjs";
2
5
  import {
3
6
  xor
4
7
  } from "../chunk-L7FQX5MN.mjs";
@@ -17,12 +20,18 @@ import {
17
20
  import {
18
21
  zipWith
19
22
  } from "../chunk-4KYXHZ4R.mjs";
23
+ import {
24
+ union
25
+ } from "../chunk-R6QA7PLZ.mjs";
20
26
  import {
21
27
  unionBy
22
28
  } from "../chunk-NFS7RWWE.mjs";
23
29
  import {
24
30
  unionWith
25
31
  } from "../chunk-2ZCITDMK.mjs";
32
+ import {
33
+ uniq
34
+ } from "../chunk-DVK2N4KC.mjs";
26
35
  import {
27
36
  uniqBy
28
37
  } from "../chunk-OXAZEEGP.mjs";
@@ -35,9 +44,6 @@ import {
35
44
  import {
36
45
  unzipWith
37
46
  } from "../chunk-IFNXROZR.mjs";
38
- import {
39
- without
40
- } from "../chunk-PYEYV7BY.mjs";
41
47
  import {
42
48
  sample
43
49
  } from "../chunk-2KNLZB7V.mjs";
@@ -49,6 +55,9 @@ import "../chunk-SYWMYQYJ.mjs";
49
55
  import {
50
56
  shuffle
51
57
  } from "../chunk-G7UQ5PUR.mjs";
58
+ import {
59
+ tail
60
+ } from "../chunk-OF6NM4G7.mjs";
52
61
  import {
53
62
  take
54
63
  } from "../chunk-ME352XO7.mjs";
@@ -61,12 +70,6 @@ import {
61
70
  import {
62
71
  takeWhile
63
72
  } from "../chunk-2IXFGSUA.mjs";
64
- import {
65
- union
66
- } from "../chunk-R6QA7PLZ.mjs";
67
- import {
68
- uniq
69
- } from "../chunk-DVK2N4KC.mjs";
70
73
  import {
71
74
  intersection
72
75
  } from "../chunk-FVVSE2F2.mjs";
@@ -91,9 +94,6 @@ import {
91
94
  import {
92
95
  partition
93
96
  } from "../chunk-DN3NOZ3H.mjs";
94
- import {
95
- dropRight
96
- } from "../chunk-JEKUA56R.mjs";
97
97
  import {
98
98
  dropRightWhile
99
99
  } from "../chunk-JE6JKZU3.mjs";
@@ -103,6 +103,9 @@ import {
103
103
  import {
104
104
  fill
105
105
  } from "../chunk-C4WE4GLC.mjs";
106
+ import {
107
+ flatten
108
+ } from "../chunk-33MSBDC6.mjs";
106
109
  import {
107
110
  forEachRight
108
111
  } from "../chunk-IEA53J7P.mjs";
@@ -133,6 +136,9 @@ import {
133
136
  import {
134
137
  drop
135
138
  } from "../chunk-S3CORED5.mjs";
139
+ import {
140
+ dropRight
141
+ } from "../chunk-JEKUA56R.mjs";
136
142
  import "../chunk-2MM5EJJX.mjs";
137
143
  export {
138
144
  chunk,
@@ -146,6 +152,7 @@ export {
146
152
  dropRightWhile,
147
153
  dropWhile,
148
154
  fill,
155
+ flatten,
149
156
  forEachRight,
150
157
  groupBy,
151
158
  head,
@@ -160,6 +167,7 @@ export {
160
167
  sample,
161
168
  sampleSize,
162
169
  shuffle,
170
+ tail,
163
171
  take,
164
172
  takeRight,
165
173
  takeRightWhile,
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Returns an empty array when the input is a single-element array.
3
+ *
4
+ * @param {readonly [T]} arr - The single-element array to process.
5
+ * @returns {[]} An empty array.
6
+ *
7
+ * @example
8
+ * const arr = [1];
9
+ * const result = tail(arr);
10
+ * // result will be []
11
+ */
12
+ declare function tail<T>(arr: readonly [T]): [];
13
+ /**
14
+ * Returns an empty array when the input is an empty array.
15
+ *
16
+ * @param {readonly []} arr - The empty array to process.
17
+ * @returns {[]} An empty array.
18
+ *
19
+ * @example
20
+ * const arr = [];
21
+ * const result = tail(arr);
22
+ * // result will be []
23
+ */
24
+ declare function tail(arr: readonly []): [];
25
+ /**
26
+ * Returns a new array with all elements except for the first when the input is a tuple array.
27
+ *
28
+ * @param {readonly [T, ...U[]]} arr - The tuple array to process.
29
+ * @returns {U[]} A new array containing all elements of the input array except for the first one.
30
+ *
31
+ * @example
32
+ * const arr = [1, 2, 3];
33
+ * const result = tail(arr);
34
+ * // result will be [2, 3]
35
+ */
36
+ declare function tail<T, U>(arr: readonly [T, ...U[]]): U[];
37
+
38
+ export { tail };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Returns an empty array when the input is a single-element array.
3
+ *
4
+ * @param {readonly [T]} arr - The single-element array to process.
5
+ * @returns {[]} An empty array.
6
+ *
7
+ * @example
8
+ * const arr = [1];
9
+ * const result = tail(arr);
10
+ * // result will be []
11
+ */
12
+ declare function tail<T>(arr: readonly [T]): [];
13
+ /**
14
+ * Returns an empty array when the input is an empty array.
15
+ *
16
+ * @param {readonly []} arr - The empty array to process.
17
+ * @returns {[]} An empty array.
18
+ *
19
+ * @example
20
+ * const arr = [];
21
+ * const result = tail(arr);
22
+ * // result will be []
23
+ */
24
+ declare function tail(arr: readonly []): [];
25
+ /**
26
+ * Returns a new array with all elements except for the first when the input is a tuple array.
27
+ *
28
+ * @param {readonly [T, ...U[]]} arr - The tuple array to process.
29
+ * @returns {U[]} A new array containing all elements of the input array except for the first one.
30
+ *
31
+ * @example
32
+ * const arr = [1, 2, 3];
33
+ * const result = tail(arr);
34
+ * // result will be [2, 3]
35
+ */
36
+ declare function tail<T, U>(arr: readonly [T, ...U[]]): U[];
37
+
38
+ export { tail };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/array/tail.ts
21
+ var tail_exports = {};
22
+ __export(tail_exports, {
23
+ tail: () => tail
24
+ });
25
+ module.exports = __toCommonJS(tail_exports);
26
+ function tail(arr) {
27
+ const len = arr.length;
28
+ if (len <= 1) {
29
+ return [];
30
+ }
31
+ const result = new Array(len - 1);
32
+ for (let i = 1; i < len; i++) {
33
+ result[i - 1] = arr[i];
34
+ }
35
+ return result;
36
+ }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ tail
40
+ });
41
+ //# sourceMappingURL=tail.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/array/tail.ts"],"sourcesContent":["/**\n * Returns an empty array when the input is a single-element array.\n *\n * @param {readonly [T]} arr - The single-element array to process.\n * @returns {[]} An empty array.\n *\n * @example\n * const arr = [1];\n * const result = tail(arr);\n * // result will be []\n */\nexport function tail<T>(arr: readonly [T]): [];\n\n/**\n * Returns an empty array when the input is an empty array.\n *\n * @param {readonly []} arr - The empty array to process.\n * @returns {[]} An empty array.\n *\n * @example\n * const arr = [];\n * const result = tail(arr);\n * // result will be []\n */\nexport function tail(arr: readonly []): [];\n\n/**\n * Returns a new array with all elements except for the first when the input is a tuple array.\n *\n * @param {readonly [T, ...U[]]} arr - The tuple array to process.\n * @returns {U[]} A new array containing all elements of the input array except for the first one.\n *\n * @example\n * const arr = [1, 2, 3];\n * const result = tail(arr);\n * // result will be [2, 3]\n */\nexport function tail<T, U>(arr: readonly [T, ...U[]]): U[];\n\n/**\n * Returns a new array with all elements except for the first.\n *\n * This function takes an array and returns a new array containing all the elements\n * except for the first one. If the input array is empty or has only one element,\n * an empty array is returned.\n *\n * @param {readonly T[]} arr - The array to get the tail of.\n * @returns {T[]} A new array containing all elements of the input array except for the first one.\n *\n * @example\n * const arr1 = [1, 2, 3];\n * const result = tail(arr1);\n * // result will be [2, 3]\n *\n * const arr2 = [1];\n * const result2 = tail(arr2);\n * // result2 will be []\n *\n * const arr3 = [];\n * const result3 = tail(arr3);\n * // result3 will be []\n */\nexport function tail<T>(arr: readonly T[]): T[] {\n const len = arr.length;\n if (len <= 1) {\n return [];\n }\n const result = new Array(len - 1);\n for (let i = 1; i < len; i++) {\n result[i - 1] = arr[i];\n }\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8DO,SAAS,KAAQ,KAAwB;AAC9C,QAAM,MAAM,IAAI;AAChB,MAAI,OAAO,GAAG;AACZ,WAAO,CAAC;AAAA,EACV;AACA,QAAM,SAAS,IAAI,MAAM,MAAM,CAAC;AAChC,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,WAAO,IAAI,CAAC,IAAI,IAAI,CAAC;AAAA,EACvB;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ tail
3
+ } from "../chunk-OF6NM4G7.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ tail
7
+ };
8
+ //# sourceMappingURL=tail.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,21 @@
1
+ // src/array/flatten.ts
2
+ function flatten(arr, depth = 1) {
3
+ const result = [];
4
+ const flooredDepth = Math.floor(depth);
5
+ const recursive = (arr2, currentDepth) => {
6
+ for (const item of arr2) {
7
+ if (Array.isArray(item) && currentDepth < flooredDepth) {
8
+ recursive(item, currentDepth + 1);
9
+ } else {
10
+ result.push(item);
11
+ }
12
+ }
13
+ };
14
+ recursive(arr, 0);
15
+ return result;
16
+ }
17
+
18
+ export {
19
+ flatten
20
+ };
21
+ //# sourceMappingURL=chunk-33MSBDC6.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/flatten.ts"],"sourcesContent":["/**\n * Flattens an array up to the specified depth.\n *\n * @template T - The type of elements within the array.\n * @template D - The depth to which the array should be flattened.\n * @param {T[]} arr - The array to flatten.\n * @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.\n * @returns {Array<FlatArray<T[], D>>} A new array that has been flattened.\n *\n * @example\n * const arr = flatten([1, [2, 3], [4, [5, 6]]], 1);\n * // Returns: [1, 2, 3, 4, [5, 6]]\n *\n * const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);\n * // Returns: [1, 2, 3, 4, 5, 6]\n */\nexport function flatten<T, D extends number = 1>(arr: readonly T[], depth = 1 as D): Array<FlatArray<T[], D>> {\n const result: Array<FlatArray<T[], D>> = [];\n const flooredDepth = Math.floor(depth);\n\n const recursive = (arr: readonly T[], currentDepth: number) => {\n for (const item of arr) {\n if (Array.isArray(item) && currentDepth < flooredDepth) {\n recursive(item, currentDepth + 1);\n } else {\n result.push(item as FlatArray<T[], D>);\n }\n }\n };\n\n recursive(arr, 0);\n return result;\n}\n"],"mappings":";AAgBO,SAAS,QAAiC,KAAmB,QAAQ,GAAkC;AAC5G,QAAM,SAAmC,CAAC;AAC1C,QAAM,eAAe,KAAK,MAAM,KAAK;AAErC,QAAM,YAAY,CAACA,MAAmB,iBAAyB;AAC7D,eAAW,QAAQA,MAAK;AACtB,UAAI,MAAM,QAAQ,IAAI,KAAK,eAAe,cAAc;AACtD,kBAAU,MAAM,eAAe,CAAC;AAAA,MAClC,OAAO;AACL,eAAO,KAAK,IAAyB;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AAEA,YAAU,KAAK,CAAC;AAChB,SAAO;AACT;","names":["arr"]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-LOY6PATI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,17 @@
1
+ // src/array/tail.ts
2
+ function tail(arr) {
3
+ const len = arr.length;
4
+ if (len <= 1) {
5
+ return [];
6
+ }
7
+ const result = new Array(len - 1);
8
+ for (let i = 1; i < len; i++) {
9
+ result[i - 1] = arr[i];
10
+ }
11
+ return result;
12
+ }
13
+
14
+ export {
15
+ tail
16
+ };
17
+ //# sourceMappingURL=chunk-OF6NM4G7.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/tail.ts"],"sourcesContent":["/**\n * Returns an empty array when the input is a single-element array.\n *\n * @param {readonly [T]} arr - The single-element array to process.\n * @returns {[]} An empty array.\n *\n * @example\n * const arr = [1];\n * const result = tail(arr);\n * // result will be []\n */\nexport function tail<T>(arr: readonly [T]): [];\n\n/**\n * Returns an empty array when the input is an empty array.\n *\n * @param {readonly []} arr - The empty array to process.\n * @returns {[]} An empty array.\n *\n * @example\n * const arr = [];\n * const result = tail(arr);\n * // result will be []\n */\nexport function tail(arr: readonly []): [];\n\n/**\n * Returns a new array with all elements except for the first when the input is a tuple array.\n *\n * @param {readonly [T, ...U[]]} arr - The tuple array to process.\n * @returns {U[]} A new array containing all elements of the input array except for the first one.\n *\n * @example\n * const arr = [1, 2, 3];\n * const result = tail(arr);\n * // result will be [2, 3]\n */\nexport function tail<T, U>(arr: readonly [T, ...U[]]): U[];\n\n/**\n * Returns a new array with all elements except for the first.\n *\n * This function takes an array and returns a new array containing all the elements\n * except for the first one. If the input array is empty or has only one element,\n * an empty array is returned.\n *\n * @param {readonly T[]} arr - The array to get the tail of.\n * @returns {T[]} A new array containing all elements of the input array except for the first one.\n *\n * @example\n * const arr1 = [1, 2, 3];\n * const result = tail(arr1);\n * // result will be [2, 3]\n *\n * const arr2 = [1];\n * const result2 = tail(arr2);\n * // result2 will be []\n *\n * const arr3 = [];\n * const result3 = tail(arr3);\n * // result3 will be []\n */\nexport function tail<T>(arr: readonly T[]): T[] {\n const len = arr.length;\n if (len <= 1) {\n return [];\n }\n const result = new Array(len - 1);\n for (let i = 1; i < len; i++) {\n result[i - 1] = arr[i];\n }\n return result;\n}\n"],"mappings":";AA8DO,SAAS,KAAQ,KAAwB;AAC9C,QAAM,MAAM,IAAI;AAChB,MAAI,OAAO,GAAG;AACZ,WAAO,CAAC;AAAA,EACV;AACA,QAAM,SAAS,IAAI,MAAM,MAAM,CAAC;AAChC,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,WAAO,IAAI,CAAC,IAAI,IAAI,CAAC;AAAA,EACvB;AACA,SAAO;AACT;","names":[]}
@@ -1,4 +1,7 @@
1
1
  import "../chunk-N6EM6ETS.mjs";
2
+ import {
3
+ debounce
4
+ } from "../chunk-3IP4JVLL.mjs";
2
5
  import {
3
6
  noop
4
7
  } from "../chunk-LKXCOLNY.mjs";
@@ -8,9 +11,6 @@ import {
8
11
  import {
9
12
  throttle
10
13
  } from "../chunk-QOJGMVVR.mjs";
11
- import {
12
- debounce
13
- } from "../chunk-3IP4JVLL.mjs";
14
14
  import "../chunk-2MM5EJJX.mjs";
15
15
  export {
16
16
  debounce,
package/dist/index.d.mts CHANGED
@@ -9,6 +9,7 @@ export { dropRight } from './array/dropRight.mjs';
9
9
  export { dropRightWhile } from './array/dropRightWhile.mjs';
10
10
  export { dropWhile } from './array/dropWhile.mjs';
11
11
  export { fill } from './array/fill.mjs';
12
+ export { flatten } from './array/flatten.mjs';
12
13
  export { forEachRight } from './array/forEachRight.mjs';
13
14
  export { groupBy } from './array/groupBy.mjs';
14
15
  export { intersection } from './array/intersection.mjs';
@@ -42,6 +43,7 @@ export { zipObject } from './array/zipObject.mjs';
42
43
  export { zipWith } from './array/zipWith.mjs';
43
44
  export { without } from './array/without.mjs';
44
45
  export { head } from './array/head.mjs';
46
+ export { tail } from './array/tail.mjs';
45
47
  export { AbortError } from './error/AbortError.mjs';
46
48
  export { debounce } from './function/debounce.mjs';
47
49
  export { noop } from './function/noop.mjs';
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export { dropRight } from './array/dropRight.js';
9
9
  export { dropRightWhile } from './array/dropRightWhile.js';
10
10
  export { dropWhile } from './array/dropWhile.js';
11
11
  export { fill } from './array/fill.js';
12
+ export { flatten } from './array/flatten.js';
12
13
  export { forEachRight } from './array/forEachRight.js';
13
14
  export { groupBy } from './array/groupBy.js';
14
15
  export { intersection } from './array/intersection.js';
@@ -42,6 +43,7 @@ export { zipObject } from './array/zipObject.js';
42
43
  export { zipWith } from './array/zipWith.js';
43
44
  export { without } from './array/without.js';
44
45
  export { head } from './array/head.js';
46
+ export { tail } from './array/tail.js';
45
47
  export { AbortError } from './error/AbortError.js';
46
48
  export { debounce } from './function/debounce.js';
47
49
  export { noop } from './function/noop.js';
package/dist/index.js CHANGED
@@ -49,6 +49,7 @@ __export(src_exports, {
49
49
  dropRightWhile: () => dropRightWhile,
50
50
  dropWhile: () => dropWhile,
51
51
  fill: () => fill,
52
+ flatten: () => flatten,
52
53
  forEachRight: () => forEachRight,
53
54
  groupBy: () => groupBy,
54
55
  head: () => head,
@@ -82,6 +83,7 @@ __export(src_exports, {
82
83
  sampleSize: () => sampleSize,
83
84
  shuffle: () => shuffle,
84
85
  sum: () => sum,
86
+ tail: () => tail,
85
87
  take: () => take,
86
88
  takeRight: () => takeRight,
87
89
  takeRightWhile: () => takeRightWhile,
@@ -201,6 +203,23 @@ function fill(arr, value, start = 0, end = arr.length) {
201
203
  return arr;
202
204
  }
203
205
 
206
+ // src/array/flatten.ts
207
+ function flatten(arr, depth = 1) {
208
+ const result = [];
209
+ const flooredDepth = Math.floor(depth);
210
+ const recursive = (arr2, currentDepth) => {
211
+ for (const item of arr2) {
212
+ if (Array.isArray(item) && currentDepth < flooredDepth) {
213
+ recursive(item, currentDepth + 1);
214
+ } else {
215
+ result.push(item);
216
+ }
217
+ }
218
+ };
219
+ recursive(arr, 0);
220
+ return result;
221
+ }
222
+
204
223
  // src/array/forEachRight.ts
205
224
  function forEachRight(arr, callback) {
206
225
  for (let i = arr.length - 1; i >= 0; i--) {
@@ -557,6 +576,19 @@ function head(arr) {
557
576
  return arr[0];
558
577
  }
559
578
 
579
+ // src/array/tail.ts
580
+ function tail(arr) {
581
+ const len = arr.length;
582
+ if (len <= 1) {
583
+ return [];
584
+ }
585
+ const result = new Array(len - 1);
586
+ for (let i = 1; i < len; i++) {
587
+ result[i - 1] = arr[i];
588
+ }
589
+ return result;
590
+ }
591
+
560
592
  // src/error/AbortError.ts
561
593
  var AbortError = class extends Error {
562
594
  constructor(message = "The operation was aborted") {
@@ -800,6 +832,7 @@ function delay(ms, { signal } = {}) {
800
832
  dropRightWhile,
801
833
  dropWhile,
802
834
  fill,
835
+ flatten,
803
836
  forEachRight,
804
837
  groupBy,
805
838
  head,
@@ -833,6 +866,7 @@ function delay(ms, { signal } = {}) {
833
866
  sampleSize,
834
867
  shuffle,
835
868
  sum,
869
+ tail,
836
870
  take,
837
871
  takeRight,
838
872
  takeRightWhile,