es-toolkit 1.8.0-dev.158 → 1.8.0-dev.160

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,16 @@
1
- import "../chunk-OC7ZNKWX.mjs";
1
+ import "../chunk-467PWPPF.mjs";
2
+ import {
3
+ without
4
+ } from "../chunk-PYEYV7BY.mjs";
5
+ import {
6
+ xor
7
+ } from "../chunk-L7FQX5MN.mjs";
8
+ import {
9
+ xorBy
10
+ } from "../chunk-Q47NGNXT.mjs";
11
+ import {
12
+ xorWith
13
+ } from "../chunk-QRSJBBFY.mjs";
2
14
  import {
3
15
  zip
4
16
  } from "../chunk-IDCUZVJL.mjs";
@@ -8,24 +20,39 @@ import {
8
20
  import {
9
21
  zipWith
10
22
  } from "../chunk-4KYXHZ4R.mjs";
23
+ import {
24
+ union
25
+ } from "../chunk-R6QA7PLZ.mjs";
26
+ import {
27
+ unionBy
28
+ } from "../chunk-NFS7RWWE.mjs";
29
+ import {
30
+ unionWith
31
+ } from "../chunk-2ZCITDMK.mjs";
32
+ import {
33
+ uniq
34
+ } from "../chunk-DVK2N4KC.mjs";
11
35
  import {
12
36
  uniqBy
13
37
  } from "../chunk-OXAZEEGP.mjs";
38
+ import {
39
+ uniqWith
40
+ } from "../chunk-237HGSZS.mjs";
41
+ import {
42
+ unzip
43
+ } from "../chunk-UYZKMBDO.mjs";
14
44
  import {
15
45
  unzipWith
16
46
  } from "../chunk-IFNXROZR.mjs";
17
47
  import {
18
- without
19
- } from "../chunk-PYEYV7BY.mjs";
20
- import {
21
- xor
22
- } from "../chunk-L7FQX5MN.mjs";
48
+ partition
49
+ } from "../chunk-DN3NOZ3H.mjs";
23
50
  import {
24
- xorBy
25
- } from "../chunk-Q47NGNXT.mjs";
51
+ sample
52
+ } from "../chunk-2KNLZB7V.mjs";
26
53
  import {
27
- xorWith
28
- } from "../chunk-QRSJBBFY.mjs";
54
+ sampleSize
55
+ } from "../chunk-EHSKB6DF.mjs";
29
56
  import {
30
57
  shuffle
31
58
  } from "../chunk-G7UQ5PUR.mjs";
@@ -42,20 +69,11 @@ import {
42
69
  takeWhile
43
70
  } from "../chunk-2IXFGSUA.mjs";
44
71
  import {
45
- union
46
- } from "../chunk-R6QA7PLZ.mjs";
47
- import {
48
- uniq
49
- } from "../chunk-DVK2N4KC.mjs";
50
- import {
51
- unionBy
52
- } from "../chunk-NFS7RWWE.mjs";
53
- import {
54
- unionWith
55
- } from "../chunk-2ZCITDMK.mjs";
72
+ intersection
73
+ } from "../chunk-FVVSE2F2.mjs";
56
74
  import {
57
- uniqWith
58
- } from "../chunk-237HGSZS.mjs";
75
+ intersectionBy
76
+ } from "../chunk-O6UXZR3U.mjs";
59
77
  import {
60
78
  intersectionWith
61
79
  } from "../chunk-XI7KRD2C.mjs";
@@ -72,16 +90,11 @@ import {
72
90
  orderBy
73
91
  } from "../chunk-7B7W36UP.mjs";
74
92
  import {
75
- partition
76
- } from "../chunk-DN3NOZ3H.mjs";
77
- import {
78
- sample
79
- } from "../chunk-2KNLZB7V.mjs";
93
+ drop
94
+ } from "../chunk-S3CORED5.mjs";
80
95
  import {
81
- sampleSize
82
- } from "../chunk-EHSKB6DF.mjs";
83
- import "../chunk-GIWAOOFY.mjs";
84
- import "../chunk-SYWMYQYJ.mjs";
96
+ dropRight
97
+ } from "../chunk-JEKUA56R.mjs";
85
98
  import {
86
99
  dropRightWhile
87
100
  } from "../chunk-JE6JKZU3.mjs";
@@ -98,11 +111,8 @@ import {
98
111
  groupBy
99
112
  } from "../chunk-E6E4RZLN.mjs";
100
113
  import {
101
- intersection
102
- } from "../chunk-FVVSE2F2.mjs";
103
- import {
104
- intersectionBy
105
- } from "../chunk-O6UXZR3U.mjs";
114
+ head
115
+ } from "../chunk-HM2JT2RX.mjs";
106
116
  import {
107
117
  chunk
108
118
  } from "../chunk-E6C5EZQA.mjs";
@@ -121,12 +131,8 @@ import {
121
131
  import {
122
132
  differenceWith
123
133
  } from "../chunk-6NVQAHXP.mjs";
124
- import {
125
- drop
126
- } from "../chunk-S3CORED5.mjs";
127
- import {
128
- dropRight
129
- } from "../chunk-JEKUA56R.mjs";
134
+ import "../chunk-GIWAOOFY.mjs";
135
+ import "../chunk-SYWMYQYJ.mjs";
130
136
  import "../chunk-2MM5EJJX.mjs";
131
137
  export {
132
138
  chunk,
@@ -142,6 +148,7 @@ export {
142
148
  fill,
143
149
  forEachRight,
144
150
  groupBy,
151
+ head,
145
152
  intersection,
146
153
  intersectionBy,
147
154
  intersectionWith,
@@ -163,6 +170,7 @@ export {
163
170
  uniq,
164
171
  uniqBy,
165
172
  uniqWith,
173
+ unzip,
166
174
  unzipWith,
167
175
  without,
168
176
  xor,
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Gathers elements in the same position in an internal array
3
+ * from a grouped array of elements and returns them as a new array.
4
+ *
5
+ * @param zipped - The nested array to unzip.
6
+ * @returns A new array of unzipped elements.
7
+ *
8
+ * @example
9
+ * const zipped = [['a', true, 1],['b', false, 2]];
10
+ * const result = unzip(zipped);
11
+ * // result will be [['a', 'b'], [true, false], [1, 2]]
12
+ */
13
+ declare function unzip<T extends unknown[]>(zipped: Array<[...T]>): Unzip<T>;
14
+ type Unzip<K extends unknown[]> = {
15
+ [I in keyof K]: Array<K[I]>;
16
+ };
17
+
18
+ export { unzip };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Gathers elements in the same position in an internal array
3
+ * from a grouped array of elements and returns them as a new array.
4
+ *
5
+ * @param zipped - The nested array to unzip.
6
+ * @returns A new array of unzipped elements.
7
+ *
8
+ * @example
9
+ * const zipped = [['a', true, 1],['b', false, 2]];
10
+ * const result = unzip(zipped);
11
+ * // result will be [['a', 'b'], [true, false], [1, 2]]
12
+ */
13
+ declare function unzip<T extends unknown[]>(zipped: Array<[...T]>): Unzip<T>;
14
+ type Unzip<K extends unknown[]> = {
15
+ [I in keyof K]: Array<K[I]>;
16
+ };
17
+
18
+ export { unzip };
@@ -0,0 +1,46 @@
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/unzip.ts
21
+ var unzip_exports = {};
22
+ __export(unzip_exports, {
23
+ unzip: () => unzip
24
+ });
25
+ module.exports = __toCommonJS(unzip_exports);
26
+ function unzip(zipped) {
27
+ let maxLen = 0;
28
+ for (let i = 0; i < zipped.length; i++) {
29
+ if (zipped[i].length > maxLen) {
30
+ maxLen = zipped[i].length;
31
+ }
32
+ }
33
+ const result = new Array(maxLen);
34
+ for (let i = 0; i < maxLen; i++) {
35
+ result[i] = new Array(zipped.length);
36
+ for (let j = 0; j < zipped.length; j++) {
37
+ result[i][j] = zipped[j][i];
38
+ }
39
+ }
40
+ return result;
41
+ }
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ unzip
45
+ });
46
+ //# sourceMappingURL=unzip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/array/unzip.ts"],"sourcesContent":["/**\n * Gathers elements in the same position in an internal array \n * from a grouped array of elements and returns them as a new array.\n *\n * @param zipped - The nested array to unzip.\n * @returns A new array of unzipped elements.\n *\n * @example\n * const zipped = [['a', true, 1],['b', false, 2]];\n * const result = unzip(zipped);\n * // result will be [['a', 'b'], [true, false], [1, 2]]\n */\nexport function unzip<T extends unknown[]>(zipped: Array<[...T]>): Unzip<T> {\n // For performance reasons, use this implementation instead of\n // const maxLen = Math.max(...zipped.map(arr => arr.length));\n let maxLen = 0;\n\n for (let i = 0; i < zipped.length; i++) {\n if (zipped[i].length > maxLen) {\n maxLen = zipped[i].length;\n }\n }\n\n const result = new Array(maxLen) as Unzip<T>;\n\n for (let i = 0; i < maxLen; i++) {\n result[i] = new Array(zipped.length);\n for (let j = 0; j < zipped.length; j++) {\n result[i][j] = zipped[j][i];\n }\n }\n\n return result;\n}\n\ntype Unzip<K extends unknown[]> = { [I in keyof K]: Array<K[I]> };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,MAA2B,QAAiC;AAG1E,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,QAAI,OAAO,CAAC,EAAE,SAAS,QAAQ;AAC7B,eAAS,OAAO,CAAC,EAAE;AAAA,IACrB;AAAA,EACF;AAEA,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,IAAI,MAAM,OAAO,MAAM;AACnC,aAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,aAAO,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ unzip
3
+ } from "../chunk-UYZKMBDO.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ unzip
7
+ };
8
+ //# sourceMappingURL=unzip.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-467PWPPF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,9 @@
1
+ // src/array/head.ts
2
+ function head(arr) {
3
+ return arr[0];
4
+ }
5
+
6
+ export {
7
+ head
8
+ };
9
+ //# sourceMappingURL=chunk-HM2JT2RX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/head.ts"],"sourcesContent":["/**\n * Returns the first element of an array.\n *\n * This function takes an array and returns the first element of the array.\n * If the array is empty, the function returns `undefined`.\n *\n * @param {T[]} arr - The array from which to get the first element.\n * @returns {T | undefined} The first element of the array, or `undefined` if the array is empty.\n *\n * @example\n * const arr = [1, 2, 3];\n * const firstElement = head(arr);\n * // firstElement will be 1\n *\n * const emptyArr: number[] = [];\n * const noElement = head(emptyArr);\n * // noElement will be undefined\n */\nexport function head<T>(arr: readonly [T, ...T[]]): T;\nexport function head<T>(arr: readonly T[]): T | undefined;\nexport function head<T>(arr: readonly T[]): T | undefined {\n return arr[0];\n}\n"],"mappings":";AAoBO,SAAS,KAAQ,KAAkC;AACxD,SAAO,IAAI,CAAC;AACd;","names":[]}
@@ -0,0 +1,22 @@
1
+ // src/array/unzip.ts
2
+ function unzip(zipped) {
3
+ let maxLen = 0;
4
+ for (let i = 0; i < zipped.length; i++) {
5
+ if (zipped[i].length > maxLen) {
6
+ maxLen = zipped[i].length;
7
+ }
8
+ }
9
+ const result = new Array(maxLen);
10
+ for (let i = 0; i < maxLen; i++) {
11
+ result[i] = new Array(zipped.length);
12
+ for (let j = 0; j < zipped.length; j++) {
13
+ result[i][j] = zipped[j][i];
14
+ }
15
+ }
16
+ return result;
17
+ }
18
+
19
+ export {
20
+ unzip
21
+ };
22
+ //# sourceMappingURL=chunk-UYZKMBDO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/unzip.ts"],"sourcesContent":["/**\n * Gathers elements in the same position in an internal array \n * from a grouped array of elements and returns them as a new array.\n *\n * @param zipped - The nested array to unzip.\n * @returns A new array of unzipped elements.\n *\n * @example\n * const zipped = [['a', true, 1],['b', false, 2]];\n * const result = unzip(zipped);\n * // result will be [['a', 'b'], [true, false], [1, 2]]\n */\nexport function unzip<T extends unknown[]>(zipped: Array<[...T]>): Unzip<T> {\n // For performance reasons, use this implementation instead of\n // const maxLen = Math.max(...zipped.map(arr => arr.length));\n let maxLen = 0;\n\n for (let i = 0; i < zipped.length; i++) {\n if (zipped[i].length > maxLen) {\n maxLen = zipped[i].length;\n }\n }\n\n const result = new Array(maxLen) as Unzip<T>;\n\n for (let i = 0; i < maxLen; i++) {\n result[i] = new Array(zipped.length);\n for (let j = 0; j < zipped.length; j++) {\n result[i][j] = zipped[j][i];\n }\n }\n\n return result;\n}\n\ntype Unzip<K extends unknown[]> = { [I in keyof K]: Array<K[I]> };\n"],"mappings":";AAYO,SAAS,MAA2B,QAAiC;AAG1E,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,QAAI,OAAO,CAAC,EAAE,SAAS,QAAQ;AAC7B,eAAS,OAAO,CAAC,EAAE;AAAA,IACrB;AAAA,EACF;AAEA,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,IAAI,MAAM,OAAO,MAAM;AACnC,aAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,aAAO,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
package/dist/index.d.mts CHANGED
@@ -32,6 +32,7 @@ export { unionWith } from './array/unionWith.mjs';
32
32
  export { uniq } from './array/uniq.mjs';
33
33
  export { uniqBy } from './array/uniqBy.mjs';
34
34
  export { uniqWith } from './array/uniqWith.mjs';
35
+ export { unzip } from './array/unzip.mjs';
35
36
  export { unzipWith } from './array/unzipWith.mjs';
36
37
  export { xor } from './array/xor.mjs';
37
38
  export { xorBy } from './array/xorBy.mjs';
@@ -40,6 +41,7 @@ export { zip } from './array/zip.mjs';
40
41
  export { zipObject } from './array/zipObject.mjs';
41
42
  export { zipWith } from './array/zipWith.mjs';
42
43
  export { without } from './array/without.mjs';
44
+ export { head } from './array/head.mjs';
43
45
  export { AbortError } from './error/AbortError.mjs';
44
46
  export { debounce } from './function/debounce.mjs';
45
47
  export { noop } from './function/noop.mjs';
package/dist/index.d.ts CHANGED
@@ -32,6 +32,7 @@ export { unionWith } from './array/unionWith.js';
32
32
  export { uniq } from './array/uniq.js';
33
33
  export { uniqBy } from './array/uniqBy.js';
34
34
  export { uniqWith } from './array/uniqWith.js';
35
+ export { unzip } from './array/unzip.js';
35
36
  export { unzipWith } from './array/unzipWith.js';
36
37
  export { xor } from './array/xor.js';
37
38
  export { xorBy } from './array/xorBy.js';
@@ -40,6 +41,7 @@ export { zip } from './array/zip.js';
40
41
  export { zipObject } from './array/zipObject.js';
41
42
  export { zipWith } from './array/zipWith.js';
42
43
  export { without } from './array/without.js';
44
+ export { head } from './array/head.js';
43
45
  export { AbortError } from './error/AbortError.js';
44
46
  export { debounce } from './function/debounce.js';
45
47
  export { noop } from './function/noop.js';
package/dist/index.js CHANGED
@@ -51,6 +51,7 @@ __export(src_exports, {
51
51
  fill: () => fill,
52
52
  forEachRight: () => forEachRight,
53
53
  groupBy: () => groupBy,
54
+ head: () => head,
54
55
  inRange: () => inRange,
55
56
  intersection: () => intersection,
56
57
  intersectionBy: () => intersectionBy,
@@ -92,6 +93,7 @@ __export(src_exports, {
92
93
  uniq: () => uniq,
93
94
  uniqBy: () => uniqBy,
94
95
  uniqWith: () => uniqWith,
96
+ unzip: () => unzip,
95
97
  unzipWith: () => unzipWith,
96
98
  without: () => without,
97
99
  xor: () => xor,
@@ -457,6 +459,24 @@ function uniqBy(arr, mapper) {
457
459
  return Array.from(map.values());
458
460
  }
459
461
 
462
+ // src/array/unzip.ts
463
+ function unzip(zipped) {
464
+ let maxLen = 0;
465
+ for (let i = 0; i < zipped.length; i++) {
466
+ if (zipped[i].length > maxLen) {
467
+ maxLen = zipped[i].length;
468
+ }
469
+ }
470
+ const result = new Array(maxLen);
471
+ for (let i = 0; i < maxLen; i++) {
472
+ result[i] = new Array(zipped.length);
473
+ for (let j = 0; j < zipped.length; j++) {
474
+ result[i][j] = zipped[j][i];
475
+ }
476
+ }
477
+ return result;
478
+ }
479
+
460
480
  // src/array/unzipWith.ts
461
481
  function unzipWith(target, iteratee) {
462
482
  const maxLength = Math.max(...target.map((innerArray) => innerArray.length));
@@ -532,6 +552,11 @@ function without(array, ...values) {
532
552
  return array.filter((item) => !valuesSet.has(item));
533
553
  }
534
554
 
555
+ // src/array/head.ts
556
+ function head(arr) {
557
+ return arr[0];
558
+ }
559
+
535
560
  // src/error/AbortError.ts
536
561
  var AbortError = class extends Error {
537
562
  constructor(message = "The operation was aborted") {
@@ -777,6 +802,7 @@ function delay(ms, { signal } = {}) {
777
802
  fill,
778
803
  forEachRight,
779
804
  groupBy,
805
+ head,
780
806
  inRange,
781
807
  intersection,
782
808
  intersectionBy,
@@ -818,6 +844,7 @@ function delay(ms, { signal } = {}) {
818
844
  uniq,
819
845
  uniqBy,
820
846
  uniqWith,
847
+ unzip,
821
848
  unzipWith,
822
849
  without,
823
850
  xor,