es-toolkit 1.10.1-dev.251 → 1.10.1-dev.252
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.
- package/dist/array/chunk.mjs +1 -1
- package/dist/array/compact.mjs +1 -1
- package/dist/array/countBy.mjs +1 -1
- package/dist/array/difference.mjs +1 -1
- package/dist/array/differenceBy.mjs +1 -1
- package/dist/array/differenceWith.mjs +1 -1
- package/dist/array/drop.mjs +1 -1
- package/dist/array/dropRight.mjs +1 -1
- package/dist/array/dropRightWhile.mjs +1 -1
- package/dist/array/dropWhile.mjs +1 -1
- package/dist/array/fill.mjs +1 -1
- package/dist/array/flatMap.mjs +1 -1
- package/dist/array/flatten.mjs +1 -1
- package/dist/array/flattenDeep.mjs +1 -1
- package/dist/array/forEachRight.mjs +1 -1
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/head.mjs +1 -1
- package/dist/array/index.mjs +20 -20
- package/dist/array/initial.mjs +1 -1
- package/dist/array/intersection.mjs +1 -1
- package/dist/array/intersectionBy.mjs +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/keyBy.mjs +1 -1
- package/dist/array/last.mjs +1 -1
- package/dist/array/maxBy.mjs +1 -1
- package/dist/array/minBy.mjs +1 -1
- package/dist/array/orderBy.mjs +1 -1
- package/dist/array/partition.mjs +1 -1
- package/dist/array/sample.mjs +1 -1
- package/dist/array/sampleSize.mjs +1 -1
- package/dist/array/shuffle.mjs +1 -1
- package/dist/array/tail.mjs +1 -1
- package/dist/array/take.mjs +1 -1
- package/dist/array/takeRight.mjs +1 -1
- package/dist/array/takeRightWhile.mjs +1 -1
- package/dist/array/takeWhile.mjs +1 -1
- package/dist/array/toFilled.mjs +1 -1
- package/dist/array/union.mjs +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/unionWith.mjs +1 -1
- package/dist/array/uniq.mjs +1 -1
- package/dist/array/uniqBy.mjs +1 -1
- package/dist/array/uniqWith.mjs +1 -1
- package/dist/array/unzip.mjs +1 -1
- package/dist/array/unzipWith.mjs +1 -1
- package/dist/array/without.mjs +1 -1
- package/dist/array/xor.mjs +1 -1
- package/dist/array/xorBy.mjs +1 -1
- package/dist/array/xorWith.mjs +1 -1
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipObject.mjs +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/{chunk-2MM5EJJX.mjs → chunk-424M7IR7.mjs} +23 -2
- package/dist/chunk-4OIZM4HS.mjs +1 -0
- package/dist/chunk-F47GLYUU.mjs +1 -0
- package/dist/chunk-J3GE7DEU.mjs +22 -0
- package/dist/chunk-J3GE7DEU.mjs.map +1 -0
- package/dist/chunk-KIOYQRMQ.mjs +12 -0
- package/dist/chunk-KIOYQRMQ.mjs.map +1 -0
- package/dist/{chunk-QZITBKWX.mjs → chunk-U7V3G7CR.mjs} +2 -2
- package/dist/chunk-XWPCDIFC.mjs +18 -0
- package/dist/chunk-XWPCDIFC.mjs.map +1 -0
- package/dist/compat/index.d.mts +2 -0
- package/dist/compat/index.d.ts +2 -0
- package/dist/compat/index.js +47 -0
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +59 -50
- package/dist/compat/index.mjs.map +1 -1
- package/dist/error/AbortError.mjs +1 -1
- package/dist/error/TimeoutError.d.mts +9 -0
- package/dist/error/TimeoutError.d.ts +9 -0
- package/dist/error/TimeoutError.js +36 -0
- package/dist/error/TimeoutError.js.map +1 -0
- package/dist/error/TimeoutError.mjs +8 -0
- package/dist/error/TimeoutError.mjs.map +1 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +12 -2
- package/dist/error/index.js.map +1 -1
- package/dist/error/index.mjs +7 -3
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.mjs +4 -4
- package/dist/function/negate.mjs +1 -1
- package/dist/function/noop.mjs +1 -1
- package/dist/function/once.mjs +1 -1
- package/dist/function/throttle.mjs +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -50
- package/dist/math/clamp.mjs +1 -1
- package/dist/math/inRange.mjs +1 -1
- package/dist/math/index.mjs +7 -7
- package/dist/math/mean.mjs +1 -1
- package/dist/math/meanBy.mjs +1 -1
- package/dist/math/random.mjs +1 -1
- package/dist/math/randomInt.mjs +1 -1
- package/dist/math/range.mjs +1 -1
- package/dist/math/round.mjs +1 -1
- package/dist/math/sum.mjs +1 -1
- package/dist/math/sumBy.mjs +1 -1
- package/dist/object/clone.mjs +1 -1
- package/dist/object/get.mjs +1 -1
- package/dist/object/index.mjs +5 -5
- package/dist/object/invert.mjs +1 -1
- package/dist/object/omit.mjs +2 -2
- package/dist/object/omitBy.mjs +1 -1
- package/dist/object/pick.mjs +1 -1
- package/dist/object/pickBy.mjs +1 -1
- package/dist/predicate/index.mjs +1 -1
- package/dist/predicate/isEqual.mjs +1 -1
- package/dist/predicate/isNil.mjs +1 -1
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/predicate/isNull.mjs +1 -1
- package/dist/predicate/isUndefined.mjs +1 -1
- package/dist/promise/delay.mjs +1 -1
- package/dist/promise/index.d.mts +1 -0
- package/dist/promise/index.d.ts +1 -0
- package/dist/promise/index.js +47 -2
- package/dist/promise/index.js.map +1 -1
- package/dist/promise/index.mjs +9 -3
- package/dist/promise/timeout.d.mts +10 -0
- package/dist/promise/timeout.d.ts +10 -0
- package/dist/promise/timeout.js +92 -0
- package/dist/promise/timeout.js.map +1 -0
- package/dist/promise/timeout.mjs +11 -0
- package/dist/promise/timeout.mjs.map +1 -0
- package/dist/promise/withTimeout.d.mts +22 -0
- package/dist/promise/withTimeout.d.ts +22 -0
- package/dist/promise/withTimeout.js +99 -0
- package/dist/promise/withTimeout.js.map +1 -0
- package/dist/promise/withTimeout.mjs +12 -0
- package/dist/promise/withTimeout.mjs.map +1 -0
- package/dist/string/camelCase.mjs +1 -1
- package/dist/string/capitalize.mjs +1 -1
- package/dist/string/index.mjs +10 -10
- package/dist/string/kebabCase.mjs +1 -1
- package/dist/string/lowerCase.mjs +1 -1
- package/dist/string/snakeCase.mjs +1 -1
- package/dist/string/startCase.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-ARZ5BDR6.mjs +0 -1
- package/dist/chunk-FZEZH22H.mjs +0 -1
- /package/dist/{chunk-2MM5EJJX.mjs.map → chunk-424M7IR7.mjs.map} +0 -0
- /package/dist/{chunk-ARZ5BDR6.mjs.map → chunk-4OIZM4HS.mjs.map} +0 -0
- /package/dist/{chunk-FZEZH22H.mjs.map → chunk-F47GLYUU.mjs.map} +0 -0
- /package/dist/{chunk-QZITBKWX.mjs.map → chunk-U7V3G7CR.mjs.map} +0 -0
package/dist/compat/index.mjs
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import "../chunk-NKLIE2OI.mjs";
|
|
2
|
-
import "../chunk-
|
|
3
|
-
import "../chunk-XT74R35S.mjs";
|
|
4
|
-
import {
|
|
5
|
-
camelCase
|
|
6
|
-
} from "../chunk-Y5V7UAZZ.mjs";
|
|
2
|
+
import "../chunk-4OIZM4HS.mjs";
|
|
7
3
|
import {
|
|
8
|
-
|
|
9
|
-
} from "../chunk-
|
|
4
|
+
withTimeout
|
|
5
|
+
} from "../chunk-XWPCDIFC.mjs";
|
|
6
|
+
import "../chunk-J3GE7DEU.mjs";
|
|
10
7
|
import {
|
|
11
|
-
|
|
12
|
-
} from "../chunk-
|
|
8
|
+
delay
|
|
9
|
+
} from "../chunk-O64NE2P4.mjs";
|
|
10
|
+
import "../chunk-XT74R35S.mjs";
|
|
13
11
|
import {
|
|
14
12
|
lowerCase
|
|
15
13
|
} from "../chunk-5IKVJGHO.mjs";
|
|
@@ -19,6 +17,15 @@ import {
|
|
|
19
17
|
import {
|
|
20
18
|
startCase
|
|
21
19
|
} from "../chunk-QXTNZR7B.mjs";
|
|
20
|
+
import {
|
|
21
|
+
camelCase
|
|
22
|
+
} from "../chunk-Y5V7UAZZ.mjs";
|
|
23
|
+
import {
|
|
24
|
+
capitalize
|
|
25
|
+
} from "../chunk-U56ZOM7L.mjs";
|
|
26
|
+
import {
|
|
27
|
+
kebabCase
|
|
28
|
+
} from "../chunk-EYYZQFOP.mjs";
|
|
22
29
|
import "../chunk-WVQ7YVRK.mjs";
|
|
23
30
|
import "../chunk-ASJF5D6C.mjs";
|
|
24
31
|
import {
|
|
@@ -36,10 +43,10 @@ import {
|
|
|
36
43
|
import {
|
|
37
44
|
isUndefined
|
|
38
45
|
} from "../chunk-VH2PV426.mjs";
|
|
39
|
-
import {
|
|
40
|
-
delay
|
|
41
|
-
} from "../chunk-O64NE2P4.mjs";
|
|
42
46
|
import "../chunk-54TK5BIS.mjs";
|
|
47
|
+
import {
|
|
48
|
+
pick
|
|
49
|
+
} from "../chunk-HPFDYUGP.mjs";
|
|
43
50
|
import {
|
|
44
51
|
pickBy
|
|
45
52
|
} from "../chunk-6CLH5YZ2.mjs";
|
|
@@ -54,39 +61,39 @@ import {
|
|
|
54
61
|
} from "../chunk-OLX53VEF.mjs";
|
|
55
62
|
import {
|
|
56
63
|
omit
|
|
57
|
-
} from "../chunk-
|
|
64
|
+
} from "../chunk-U7V3G7CR.mjs";
|
|
58
65
|
import {
|
|
59
66
|
omitBy
|
|
60
67
|
} from "../chunk-BCTYOXT7.mjs";
|
|
61
|
-
import {
|
|
62
|
-
pick
|
|
63
|
-
} from "../chunk-HPFDYUGP.mjs";
|
|
64
68
|
import "../chunk-FUS75PJ7.mjs";
|
|
65
69
|
import {
|
|
66
70
|
sumBy
|
|
67
71
|
} from "../chunk-5L4VWRFX.mjs";
|
|
72
|
+
import {
|
|
73
|
+
inRange
|
|
74
|
+
} from "../chunk-BH6HLGBA.mjs";
|
|
68
75
|
import {
|
|
69
76
|
meanBy
|
|
70
77
|
} from "../chunk-MY4G7R3I.mjs";
|
|
71
78
|
import {
|
|
72
79
|
mean
|
|
73
80
|
} from "../chunk-5ASRKEB4.mjs";
|
|
81
|
+
import {
|
|
82
|
+
sum
|
|
83
|
+
} from "../chunk-2SLTL4KL.mjs";
|
|
74
84
|
import {
|
|
75
85
|
range
|
|
76
86
|
} from "../chunk-DPH2KE6O.mjs";
|
|
77
87
|
import {
|
|
78
88
|
round
|
|
79
89
|
} from "../chunk-5PMKOZ2F.mjs";
|
|
80
|
-
import {
|
|
81
|
-
sum
|
|
82
|
-
} from "../chunk-2SLTL4KL.mjs";
|
|
83
90
|
import {
|
|
84
91
|
clamp
|
|
85
92
|
} from "../chunk-MLCL773E.mjs";
|
|
86
|
-
import {
|
|
87
|
-
inRange
|
|
88
|
-
} from "../chunk-BH6HLGBA.mjs";
|
|
89
93
|
import "../chunk-DDH7K4QM.mjs";
|
|
94
|
+
import {
|
|
95
|
+
without
|
|
96
|
+
} from "../chunk-PYEYV7BY.mjs";
|
|
90
97
|
import {
|
|
91
98
|
xor
|
|
92
99
|
} from "../chunk-L7FQX5MN.mjs";
|
|
@@ -105,12 +112,18 @@ import {
|
|
|
105
112
|
import {
|
|
106
113
|
zipWith
|
|
107
114
|
} from "../chunk-4KYXHZ4R.mjs";
|
|
115
|
+
import {
|
|
116
|
+
union
|
|
117
|
+
} from "../chunk-R6QA7PLZ.mjs";
|
|
108
118
|
import {
|
|
109
119
|
unionBy
|
|
110
120
|
} from "../chunk-NFS7RWWE.mjs";
|
|
111
121
|
import {
|
|
112
122
|
unionWith
|
|
113
123
|
} from "../chunk-2ZCITDMK.mjs";
|
|
124
|
+
import {
|
|
125
|
+
uniq
|
|
126
|
+
} from "../chunk-DVK2N4KC.mjs";
|
|
114
127
|
import {
|
|
115
128
|
uniqBy
|
|
116
129
|
} from "../chunk-B4COTK4K.mjs";
|
|
@@ -124,8 +137,14 @@ import {
|
|
|
124
137
|
unzipWith
|
|
125
138
|
} from "../chunk-IFNXROZR.mjs";
|
|
126
139
|
import {
|
|
127
|
-
|
|
128
|
-
} from "../chunk-
|
|
140
|
+
sampleSize
|
|
141
|
+
} from "../chunk-EHSKB6DF.mjs";
|
|
142
|
+
import {
|
|
143
|
+
randomInt
|
|
144
|
+
} from "../chunk-GIWAOOFY.mjs";
|
|
145
|
+
import {
|
|
146
|
+
random
|
|
147
|
+
} from "../chunk-SYWMYQYJ.mjs";
|
|
129
148
|
import {
|
|
130
149
|
shuffle
|
|
131
150
|
} from "../chunk-G7UQ5PUR.mjs";
|
|
@@ -148,11 +167,8 @@ import {
|
|
|
148
167
|
toFilled
|
|
149
168
|
} from "../chunk-OP4OAKQJ.mjs";
|
|
150
169
|
import {
|
|
151
|
-
|
|
152
|
-
} from "../chunk-
|
|
153
|
-
import {
|
|
154
|
-
uniq
|
|
155
|
-
} from "../chunk-DVK2N4KC.mjs";
|
|
170
|
+
intersectionWith
|
|
171
|
+
} from "../chunk-XI7KRD2C.mjs";
|
|
156
172
|
import {
|
|
157
173
|
keyBy
|
|
158
174
|
} from "../chunk-AJKZMN2V.mjs";
|
|
@@ -175,14 +191,8 @@ import {
|
|
|
175
191
|
sample
|
|
176
192
|
} from "../chunk-2KNLZB7V.mjs";
|
|
177
193
|
import {
|
|
178
|
-
|
|
179
|
-
} from "../chunk-
|
|
180
|
-
import {
|
|
181
|
-
randomInt
|
|
182
|
-
} from "../chunk-GIWAOOFY.mjs";
|
|
183
|
-
import {
|
|
184
|
-
random
|
|
185
|
-
} from "../chunk-SYWMYQYJ.mjs";
|
|
194
|
+
flattenDeep
|
|
195
|
+
} from "../chunk-ML727RRJ.mjs";
|
|
186
196
|
import {
|
|
187
197
|
forEachRight
|
|
188
198
|
} from "../chunk-IEA53J7P.mjs";
|
|
@@ -202,8 +212,8 @@ import {
|
|
|
202
212
|
intersectionBy
|
|
203
213
|
} from "../chunk-O6UXZR3U.mjs";
|
|
204
214
|
import {
|
|
205
|
-
|
|
206
|
-
} from "../chunk-
|
|
215
|
+
differenceWith
|
|
216
|
+
} from "../chunk-6NVQAHXP.mjs";
|
|
207
217
|
import {
|
|
208
218
|
drop
|
|
209
219
|
} from "../chunk-S3CORED5.mjs";
|
|
@@ -222,9 +232,6 @@ import {
|
|
|
222
232
|
import {
|
|
223
233
|
flatMap
|
|
224
234
|
} from "../chunk-UY76KTPE.mjs";
|
|
225
|
-
import {
|
|
226
|
-
flattenDeep
|
|
227
|
-
} from "../chunk-ML727RRJ.mjs";
|
|
228
235
|
import {
|
|
229
236
|
flatten
|
|
230
237
|
} from "../chunk-33MSBDC6.mjs";
|
|
@@ -243,14 +250,17 @@ import {
|
|
|
243
250
|
import {
|
|
244
251
|
differenceBy
|
|
245
252
|
} from "../chunk-LVWX5B43.mjs";
|
|
246
|
-
import
|
|
247
|
-
differenceWith
|
|
248
|
-
} from "../chunk-6NVQAHXP.mjs";
|
|
249
|
-
import "../chunk-FZEZH22H.mjs";
|
|
253
|
+
import "../chunk-F47GLYUU.mjs";
|
|
250
254
|
import {
|
|
251
255
|
AbortError
|
|
252
256
|
} from "../chunk-DXB7EZUQ.mjs";
|
|
257
|
+
import {
|
|
258
|
+
TimeoutError
|
|
259
|
+
} from "../chunk-KIOYQRMQ.mjs";
|
|
253
260
|
import "../chunk-236H5JZJ.mjs";
|
|
261
|
+
import {
|
|
262
|
+
noop
|
|
263
|
+
} from "../chunk-LKXCOLNY.mjs";
|
|
254
264
|
import {
|
|
255
265
|
once
|
|
256
266
|
} from "../chunk-CMBC4MXG.mjs";
|
|
@@ -263,10 +273,7 @@ import {
|
|
|
263
273
|
import {
|
|
264
274
|
negate
|
|
265
275
|
} from "../chunk-BOOQBJN2.mjs";
|
|
266
|
-
import
|
|
267
|
-
noop
|
|
268
|
-
} from "../chunk-LKXCOLNY.mjs";
|
|
269
|
-
import "../chunk-2MM5EJJX.mjs";
|
|
276
|
+
import "../chunk-424M7IR7.mjs";
|
|
270
277
|
|
|
271
278
|
// src/compat/array/chunk.ts
|
|
272
279
|
function chunk2(arr, size = 1) {
|
|
@@ -359,6 +366,7 @@ var endsWith = (str, target, position = str.length) => {
|
|
|
359
366
|
};
|
|
360
367
|
export {
|
|
361
368
|
AbortError,
|
|
369
|
+
TimeoutError,
|
|
362
370
|
camelCase,
|
|
363
371
|
capitalize,
|
|
364
372
|
chunk2 as chunk,
|
|
@@ -440,6 +448,7 @@ export {
|
|
|
440
448
|
uniqWith,
|
|
441
449
|
unzip,
|
|
442
450
|
unzipWith,
|
|
451
|
+
withTimeout,
|
|
443
452
|
without,
|
|
444
453
|
xor,
|
|
445
454
|
xorBy,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/compat/array/chunk.ts","../../src/compat/_internal/isIndex.ts","../../src/compat/_internal/toPath.ts","../../src/compat/object/set.ts","../../src/compat/array/zipObjectDeep.ts","../../src/compat/string/startsWith.ts","../../src/compat/string/endsWith.ts"],"sourcesContent":["import { chunk as chunkToolkit } from '../../array/chunk.ts';\n\n/**\n * Splits an array into smaller arrays of a specified length.\n *\n * This function takes an input array and divides it into multiple smaller arrays,\n * each of a specified length. If the input array cannot be evenly divided,\n * the final sub-array will contain the remaining elements.\n *\n * @template T The type of elements in the array.\n * @param {T[]} arr - The array to be chunked into smaller arrays.\n * @param {number} size - The size of each smaller array. Must be a positive integer.\n * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.\n * @throws {Error} Throws an error if `size` is not a positive integer.\n *\n * @example\n * // Splits an array of numbers into sub-arrays of length 2\n * chunk([1, 2, 3, 4, 5], 2);\n * // Returns: [[1, 2], [3, 4], [5]]\n *\n * @example\n * // Splits an array of strings into sub-arrays of length 3\n * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);\n * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]\n */\nexport function chunk<T>(arr: readonly T[], size: number = 1): T[][] {\n size = Math.max(Math.floor(size), 0);\n\n if (size === 0) {\n return [];\n }\n\n return chunkToolkit(arr, size);\n}\n","const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\\d*)$/\n\nexport function isIndex(value: PropertyKey) {\n switch (typeof value) {\n case 'number': {\n return Number.isInteger(value) && value >= 0 && value < Number.MAX_SAFE_INTEGER;\n }\n case 'symbol': {\n return false;\n }\n case 'string': {\n return IS_UNSIGNED_INTEGER.test(value);\n }\n }\n}","const ESCAPE_REGEXP = /\\\\(\\\\)?/g;\nconst PROPERTY_REGEXP = RegExp(\n // Match anything that isn't a dot or bracket.\n \"[^.[\\\\]]+\" +\n \"|\" +\n // Or match property names within brackets.\n \"\\\\[(?:\" +\n // Match a non-string expression.\n \"([^\\\"'][^[]*)\" +\n \"|\" +\n // Or match strings (supports escaping characters).\n \"([\\\"'])((?:(?!\\\\2)[^\\\\\\\\]|\\\\\\\\.)*?)\\\\2\" +\n \")\\\\]\" +\n \"|\" +\n // Or match \"\" as the space between consecutive dots or empty brackets.\n \"(?=(?:\\\\.|\\\\[\\\\])(?:\\\\.|\\\\[\\\\]|$))\",\n \"g\",\n);\n\n/**\n * Converts a deep key string into an array of path segments.\n *\n * This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.\n *\n * @param deepKey - The deep key string to convert.\n * @returns An array of strings, each representing a segment of the path.\n *\n * Examples:\n *\n * toPath('a.b.c') // Returns ['a', 'b', 'c']\n * toPath('a[b][c]') // Returns ['a', 'b', 'c']\n * toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']\n * toPath('a[\"b.c\"].d') // Returns ['a', 'b.c', 'd']\n * toPath('') // Returns []\n * toPath('.a[b].c.d[e][\"f.g\"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']\n */\nexport function toPath(deepKey: string): string[] {\n const result: string[] = [];\n\n if (deepKey[0] === \".\") {\n result.push(\"\");\n }\n\n let match: RegExpExecArray | null;\n\n while ((match = PROPERTY_REGEXP.exec(deepKey)) !== null) {\n let [key, expr, quote, substr] = match;\n\n if (quote) {\n key = substr.replace(ESCAPE_REGEXP, \"$1\");\n } else if (expr) {\n key = expr.trim();\n }\n\n result.push(key);\n }\n\n return result;\n}\n","import { isIndex } from \"../_internal/isIndex.ts\";\nimport { toPath } from \"../_internal/toPath.ts\";\n\n/**\n * Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.\n *\n * @template T - The type of the object.\n * @param {Settable} obj - The object to modify.\n * @param {Path} path - The path of the property to set.\n * @param {any} value - The value to set.\n * @returns {T} - The modified object.\n *\n * @example\n * // Set a value in a nested object\n * const obj = { a: { b: { c: 3 } } };\n * set(obj, 'a.b.c', 4);\n * console.log(obj.a.b.c); // 4\n *\n * @example\n * // Set a value in an array\n * const arr = [1, 2, 3];\n * set(arr, 1, 4);\n * console.log(arr[1]); // 4\n *\n * @example\n * // Create non-existent path and set value\n * const obj = {};\n * set(obj, 'a.b.c', 4);\n * console.log(obj); // { a: { b: { c: 4 } } }\n */\nexport function set<T>(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T;\nexport function set<T extends object>(obj: T, path: PropertyKey | readonly PropertyKey[], value: unknown): T {\n const resolvedPath = Array.isArray(path)\n ? path\n : typeof path === 'string'\n ? toPath(path)\n : [path];\n\n let current: any = obj;\n\n for (let i = 0; i < resolvedPath.length - 1; i++) {\n const key = resolvedPath[i];\n const nextKey = resolvedPath[i + 1];\n\n if (current[key] == null) {\n current[key] = isIndex(nextKey) ? [] : {};\n }\n\n current = current[key];\n }\n\n const lastKey = resolvedPath[resolvedPath.length - 1];\n current[lastKey] = value;\n\n return obj;\n}\n","import { zip } from \"../../array/zip.ts\";\nimport { set } from \"../object/set.ts\";\n\n/**\n * Creates a deeply nested object given arrays of paths and values.\n *\n * This function takes two arrays: one containing arrays of property paths, and the other containing corresponding values.\n * It returns a new object where paths from the first array are used as key paths to set values, with corresponding elements from the second array as values.\n * Paths can be dot-separated strings or arrays of property names.\n * \n * If the `keys` array is longer than the `values` array, the remaining keys will have `undefined` as their values.\n *\n * @template V - The type of elements in the array.\n * @param {string[] | string[][]} keys - An array of property paths, each path can be a dot-separated string or an array of property names.\n * @param {V[]} values - An array of values corresponding to the property paths.\n * @returns {object} A new object composed of the given property paths and values.\n *\n * @example\n * const paths = ['a.b.c', 'd.e.f'];\n * const values = [1, 2];\n * const result = zipObjectDeep(paths, values);\n * // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } }\n *\n * @example\n * const paths = [['a', 'b', 'c'], ['d', 'e', 'f']];\n * const values = [1, 2];\n * const result = zipObjectDeep(paths, values);\n * // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } }\n * \n * @example\n * const paths = ['a.b[0].c', 'a.b[1].d'];\n * const values = [1, 2];\n * const result = zipObjectDeep(paths, values);\n * // result will be { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }\n */\nexport function zipObjectDeep<P extends string | number | symbol, V>(keys: P[], values: V[]): { [K in P]: V } {\n const result = {} as { [K in P]: V };\n const zipped = zip(keys, values);\n\n for (let i = 0; i < zipped.length; i++) {\n const [key, value] = zipped[i];\n\n if (key != null) {\n set(result, key, value);\n }\n }\n\n return result;\n}\n","/**\n * Checks if a string contains another string at the beginning of the string.\n *\n * Checks if one string startsWith another string. Optional position parameter to start searching from a certain index.\n *\n * @param {string} str - The string that might contain the target string.\n * @param {string} target - The string to search for.\n * @param {number} position - An optional offset to start searching in the str string\n * @returns {boolean} - True if the str string starts with the target string.\n *\n * @example\n * const isPrefix = startsWith('fooBar', 'foo') // returns true\n * const isPrefix = startsWith('fooBar', 'bar') // returns false\n * const isPrefix = startsWith('fooBar', 'abc') // returns false\n * const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true\n * const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false\n */\nexport const startsWith = (str: string, target: string, position: number = 0): boolean => {\n return str.startsWith(target, position);\n};\n","/**\n * Checks if a string contains another string at the end of the string.\n *\n * Checks if one string endsWith another string. Optional position parameter to offset searching before a certain index.\n *\n * @param {string} str - The string that might contain the target string.\n * @param {string} target - The string to search for.\n * @param {number} position - An optional position from the start to search up to this index\n * @returns {boolean} - True if the str string ends with the target string.\n *\n * @example\n * const isPrefix = endsWith('fooBar', 'foo') // returns true\n * const isPrefix = endsWith('fooBar', 'bar') // returns false\n * const isPrefix = endsWith('fooBar', 'abc') // returns false\n * const isPrefix = endsWith('fooBar', 'foo', 3) // returns true\n * const isPrefix = endsWith('fooBar', 'abc', 5) // returns false\n */\nexport const endsWith = (str: string, target: string, position: number = str.length): boolean => {\n return str.endsWith(target, position);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,SAASA,OAAS,KAAmB,OAAe,GAAU;AACnE,SAAO,KAAK,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC;AAEnC,MAAI,SAAS,GAAG;AACd,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,MAAa,KAAK,IAAI;AAC/B;;;ACjCA,IAAM,sBAAsB;AAErB,SAAS,QAAQ,OAAoB;AAC1C,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,aAAO,OAAO,UAAU,KAAK,KAAK,SAAS,KAAK,QAAQ,OAAO;AAAA,IACjE;AAAA,IACA,KAAK,UAAU;AACb,aAAO;AAAA,IACT;AAAA,IACA,KAAK,UAAU;AACb,aAAO,oBAAoB,KAAK,KAAK;AAAA,IACvC;AAAA,EACF;AACF;;;ACdA,IAAM,gBAAgB;AACtB,IAAM,kBAAkB;AAAA;AAAA,EAEtB;AAAA,EAaA;AACF;AAmBO,SAAS,OAAO,SAA2B;AAChD,QAAM,SAAmB,CAAC;AAE1B,MAAI,QAAQ,CAAC,MAAM,KAAK;AACtB,WAAO,KAAK,EAAE;AAAA,EAChB;AAEA,MAAI;AAEJ,UAAQ,QAAQ,gBAAgB,KAAK,OAAO,OAAO,MAAM;AACvD,QAAI,CAAC,KAAK,MAAM,OAAO,MAAM,IAAI;AAEjC,QAAI,OAAO;AACT,YAAM,OAAO,QAAQ,eAAe,IAAI;AAAA,IAC1C,WAAW,MAAM;AACf,YAAM,KAAK,KAAK;AAAA,IAClB;AAEA,WAAO,KAAK,GAAG;AAAA,EACjB;AAEA,SAAO;AACT;;;AC3BO,SAAS,IAAsB,KAAQ,MAA4C,OAAmB;AAC3G,QAAM,eAAe,MAAM,QAAQ,IAAI,IACnC,OACA,OAAO,SAAS,WACd,OAAO,IAAI,IACX,CAAC,IAAI;AAEX,MAAI,UAAe;AAEnB,WAAS,IAAI,GAAG,IAAI,aAAa,SAAS,GAAG,KAAK;AAChD,UAAM,MAAM,aAAa,CAAC;AAC1B,UAAM,UAAU,aAAa,IAAI,CAAC;AAElC,QAAI,QAAQ,GAAG,KAAK,MAAM;AACxB,cAAQ,GAAG,IAAI,QAAQ,OAAO,IAAI,CAAC,IAAI,CAAC;AAAA,IAC1C;AAEA,cAAU,QAAQ,GAAG;AAAA,EACvB;AAEA,QAAM,UAAU,aAAa,aAAa,SAAS,CAAC;AACpD,UAAQ,OAAO,IAAI;AAEnB,SAAO;AACT;;;ACpBO,SAAS,cAAqD,MAAW,QAA8B;AAC5G,QAAM,SAAS,CAAC;AAChB,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,CAAC,KAAK,KAAK,IAAI,OAAO,CAAC;AAE7B,QAAI,OAAO,MAAM;AACf,UAAI,QAAQ,KAAK,KAAK;AAAA,IACxB;AAAA,EACF;AAEA,SAAO;AACT;;;AC/BO,IAAM,aAAa,CAAC,KAAa,QAAgB,WAAmB,MAAe;AACxF,SAAO,IAAI,WAAW,QAAQ,QAAQ;AACxC;;;ACFO,IAAM,WAAW,CAAC,KAAa,QAAgB,WAAmB,IAAI,WAAoB;AAC/F,SAAO,IAAI,SAAS,QAAQ,QAAQ;AACtC;","names":["chunk"]}
|
|
1
|
+
{"version":3,"sources":["../../src/compat/array/chunk.ts","../../src/compat/_internal/isIndex.ts","../../src/compat/_internal/toPath.ts","../../src/compat/object/set.ts","../../src/compat/array/zipObjectDeep.ts","../../src/compat/string/startsWith.ts","../../src/compat/string/endsWith.ts"],"sourcesContent":["import { chunk as chunkToolkit } from '../../array/chunk.ts';\n\n/**\n * Splits an array into smaller arrays of a specified length.\n *\n * This function takes an input array and divides it into multiple smaller arrays,\n * each of a specified length. If the input array cannot be evenly divided,\n * the final sub-array will contain the remaining elements.\n *\n * @template T The type of elements in the array.\n * @param {T[]} arr - The array to be chunked into smaller arrays.\n * @param {number} size - The size of each smaller array. Must be a positive integer.\n * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.\n * @throws {Error} Throws an error if `size` is not a positive integer.\n *\n * @example\n * // Splits an array of numbers into sub-arrays of length 2\n * chunk([1, 2, 3, 4, 5], 2);\n * // Returns: [[1, 2], [3, 4], [5]]\n *\n * @example\n * // Splits an array of strings into sub-arrays of length 3\n * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);\n * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]\n */\nexport function chunk<T>(arr: readonly T[], size: number = 1): T[][] {\n size = Math.max(Math.floor(size), 0);\n\n if (size === 0) {\n return [];\n }\n\n return chunkToolkit(arr, size);\n}\n","const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\\d*)$/\n\nexport function isIndex(value: PropertyKey) {\n switch (typeof value) {\n case 'number': {\n return Number.isInteger(value) && value >= 0 && value < Number.MAX_SAFE_INTEGER;\n }\n case 'symbol': {\n return false;\n }\n case 'string': {\n return IS_UNSIGNED_INTEGER.test(value);\n }\n }\n}","const ESCAPE_REGEXP = /\\\\(\\\\)?/g;\nconst PROPERTY_REGEXP = RegExp(\n // Match anything that isn't a dot or bracket.\n \"[^.[\\\\]]+\" +\n \"|\" +\n // Or match property names within brackets.\n \"\\\\[(?:\" +\n // Match a non-string expression.\n \"([^\\\"'][^[]*)\" +\n \"|\" +\n // Or match strings (supports escaping characters).\n \"([\\\"'])((?:(?!\\\\2)[^\\\\\\\\]|\\\\\\\\.)*?)\\\\2\" +\n \")\\\\]\" +\n \"|\" +\n // Or match \"\" as the space between consecutive dots or empty brackets.\n \"(?=(?:\\\\.|\\\\[\\\\])(?:\\\\.|\\\\[\\\\]|$))\",\n \"g\",\n);\n\n/**\n * Converts a deep key string into an array of path segments.\n *\n * This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.\n *\n * @param deepKey - The deep key string to convert.\n * @returns An array of strings, each representing a segment of the path.\n *\n * Examples:\n *\n * toPath('a.b.c') // Returns ['a', 'b', 'c']\n * toPath('a[b][c]') // Returns ['a', 'b', 'c']\n * toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']\n * toPath('a[\"b.c\"].d') // Returns ['a', 'b.c', 'd']\n * toPath('') // Returns []\n * toPath('.a[b].c.d[e][\"f.g\"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']\n */\nexport function toPath(deepKey: string): string[] {\n const result: string[] = [];\n\n if (deepKey[0] === \".\") {\n result.push(\"\");\n }\n\n let match: RegExpExecArray | null;\n\n while ((match = PROPERTY_REGEXP.exec(deepKey)) !== null) {\n let [key, expr, quote, substr] = match;\n\n if (quote) {\n key = substr.replace(ESCAPE_REGEXP, \"$1\");\n } else if (expr) {\n key = expr.trim();\n }\n\n result.push(key);\n }\n\n return result;\n}\n","import { isIndex } from \"../_internal/isIndex.ts\";\nimport { toPath } from \"../_internal/toPath.ts\";\n\n/**\n * Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.\n *\n * @template T - The type of the object.\n * @param {Settable} obj - The object to modify.\n * @param {Path} path - The path of the property to set.\n * @param {any} value - The value to set.\n * @returns {T} - The modified object.\n *\n * @example\n * // Set a value in a nested object\n * const obj = { a: { b: { c: 3 } } };\n * set(obj, 'a.b.c', 4);\n * console.log(obj.a.b.c); // 4\n *\n * @example\n * // Set a value in an array\n * const arr = [1, 2, 3];\n * set(arr, 1, 4);\n * console.log(arr[1]); // 4\n *\n * @example\n * // Create non-existent path and set value\n * const obj = {};\n * set(obj, 'a.b.c', 4);\n * console.log(obj); // { a: { b: { c: 4 } } }\n */\nexport function set<T>(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T;\nexport function set<T extends object>(obj: T, path: PropertyKey | readonly PropertyKey[], value: unknown): T {\n const resolvedPath = Array.isArray(path)\n ? path\n : typeof path === 'string'\n ? toPath(path)\n : [path];\n\n let current: any = obj;\n\n for (let i = 0; i < resolvedPath.length - 1; i++) {\n const key = resolvedPath[i];\n const nextKey = resolvedPath[i + 1];\n\n if (current[key] == null) {\n current[key] = isIndex(nextKey) ? [] : {};\n }\n\n current = current[key];\n }\n\n const lastKey = resolvedPath[resolvedPath.length - 1];\n current[lastKey] = value;\n\n return obj;\n}\n","import { zip } from \"../../array/zip.ts\";\nimport { set } from \"../object/set.ts\";\n\n/**\n * Creates a deeply nested object given arrays of paths and values.\n *\n * This function takes two arrays: one containing arrays of property paths, and the other containing corresponding values.\n * It returns a new object where paths from the first array are used as key paths to set values, with corresponding elements from the second array as values.\n * Paths can be dot-separated strings or arrays of property names.\n * \n * If the `keys` array is longer than the `values` array, the remaining keys will have `undefined` as their values.\n *\n * @template V - The type of elements in the array.\n * @param {string[] | string[][]} keys - An array of property paths, each path can be a dot-separated string or an array of property names.\n * @param {V[]} values - An array of values corresponding to the property paths.\n * @returns {object} A new object composed of the given property paths and values.\n *\n * @example\n * const paths = ['a.b.c', 'd.e.f'];\n * const values = [1, 2];\n * const result = zipObjectDeep(paths, values);\n * // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } }\n *\n * @example\n * const paths = [['a', 'b', 'c'], ['d', 'e', 'f']];\n * const values = [1, 2];\n * const result = zipObjectDeep(paths, values);\n * // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } }\n * \n * @example\n * const paths = ['a.b[0].c', 'a.b[1].d'];\n * const values = [1, 2];\n * const result = zipObjectDeep(paths, values);\n * // result will be { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }\n */\nexport function zipObjectDeep<P extends string | number | symbol, V>(keys: P[], values: V[]): { [K in P]: V } {\n const result = {} as { [K in P]: V };\n const zipped = zip(keys, values);\n\n for (let i = 0; i < zipped.length; i++) {\n const [key, value] = zipped[i];\n\n if (key != null) {\n set(result, key, value);\n }\n }\n\n return result;\n}\n","/**\n * Checks if a string contains another string at the beginning of the string.\n *\n * Checks if one string startsWith another string. Optional position parameter to start searching from a certain index.\n *\n * @param {string} str - The string that might contain the target string.\n * @param {string} target - The string to search for.\n * @param {number} position - An optional offset to start searching in the str string\n * @returns {boolean} - True if the str string starts with the target string.\n *\n * @example\n * const isPrefix = startsWith('fooBar', 'foo') // returns true\n * const isPrefix = startsWith('fooBar', 'bar') // returns false\n * const isPrefix = startsWith('fooBar', 'abc') // returns false\n * const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true\n * const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false\n */\nexport const startsWith = (str: string, target: string, position: number = 0): boolean => {\n return str.startsWith(target, position);\n};\n","/**\n * Checks if a string contains another string at the end of the string.\n *\n * Checks if one string endsWith another string. Optional position parameter to offset searching before a certain index.\n *\n * @param {string} str - The string that might contain the target string.\n * @param {string} target - The string to search for.\n * @param {number} position - An optional position from the start to search up to this index\n * @returns {boolean} - True if the str string ends with the target string.\n *\n * @example\n * const isPrefix = endsWith('fooBar', 'foo') // returns true\n * const isPrefix = endsWith('fooBar', 'bar') // returns false\n * const isPrefix = endsWith('fooBar', 'abc') // returns false\n * const isPrefix = endsWith('fooBar', 'foo', 3) // returns true\n * const isPrefix = endsWith('fooBar', 'abc', 5) // returns false\n */\nexport const endsWith = (str: string, target: string, position: number = str.length): boolean => {\n return str.endsWith(target, position);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,SAASA,OAAS,KAAmB,OAAe,GAAU;AACnE,SAAO,KAAK,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC;AAEnC,MAAI,SAAS,GAAG;AACd,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,MAAa,KAAK,IAAI;AAC/B;;;ACjCA,IAAM,sBAAsB;AAErB,SAAS,QAAQ,OAAoB;AAC1C,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,aAAO,OAAO,UAAU,KAAK,KAAK,SAAS,KAAK,QAAQ,OAAO;AAAA,IACjE;AAAA,IACA,KAAK,UAAU;AACb,aAAO;AAAA,IACT;AAAA,IACA,KAAK,UAAU;AACb,aAAO,oBAAoB,KAAK,KAAK;AAAA,IACvC;AAAA,EACF;AACF;;;ACdA,IAAM,gBAAgB;AACtB,IAAM,kBAAkB;AAAA;AAAA,EAEtB;AAAA,EAaA;AACF;AAmBO,SAAS,OAAO,SAA2B;AAChD,QAAM,SAAmB,CAAC;AAE1B,MAAI,QAAQ,CAAC,MAAM,KAAK;AACtB,WAAO,KAAK,EAAE;AAAA,EAChB;AAEA,MAAI;AAEJ,UAAQ,QAAQ,gBAAgB,KAAK,OAAO,OAAO,MAAM;AACvD,QAAI,CAAC,KAAK,MAAM,OAAO,MAAM,IAAI;AAEjC,QAAI,OAAO;AACT,YAAM,OAAO,QAAQ,eAAe,IAAI;AAAA,IAC1C,WAAW,MAAM;AACf,YAAM,KAAK,KAAK;AAAA,IAClB;AAEA,WAAO,KAAK,GAAG;AAAA,EACjB;AAEA,SAAO;AACT;;;AC3BO,SAAS,IAAsB,KAAQ,MAA4C,OAAmB;AAC3G,QAAM,eAAe,MAAM,QAAQ,IAAI,IACnC,OACA,OAAO,SAAS,WACd,OAAO,IAAI,IACX,CAAC,IAAI;AAEX,MAAI,UAAe;AAEnB,WAAS,IAAI,GAAG,IAAI,aAAa,SAAS,GAAG,KAAK;AAChD,UAAM,MAAM,aAAa,CAAC;AAC1B,UAAM,UAAU,aAAa,IAAI,CAAC;AAElC,QAAI,QAAQ,GAAG,KAAK,MAAM;AACxB,cAAQ,GAAG,IAAI,QAAQ,OAAO,IAAI,CAAC,IAAI,CAAC;AAAA,IAC1C;AAEA,cAAU,QAAQ,GAAG;AAAA,EACvB;AAEA,QAAM,UAAU,aAAa,aAAa,SAAS,CAAC;AACpD,UAAQ,OAAO,IAAI;AAEnB,SAAO;AACT;;;ACpBO,SAAS,cAAqD,MAAW,QAA8B;AAC5G,QAAM,SAAS,CAAC;AAChB,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,CAAC,KAAK,KAAK,IAAI,OAAO,CAAC;AAE7B,QAAI,OAAO,MAAM;AACf,UAAI,QAAQ,KAAK,KAAK;AAAA,IACxB;AAAA,EACF;AAEA,SAAO;AACT;;;AC/BO,IAAM,aAAa,CAAC,KAAa,QAAgB,WAAmB,MAAe;AACxF,SAAO,IAAI,WAAW,QAAQ,QAAQ;AACxC;;;ACFO,IAAM,WAAW,CAAC,KAAa,QAAgB,WAAmB,IAAI,WAAoB;AAC/F,SAAO,IAAI,SAAS,QAAQ,QAAQ;AACtC;","names":["chunk"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
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/error/TimeoutError.ts
|
|
21
|
+
var TimeoutError_exports = {};
|
|
22
|
+
__export(TimeoutError_exports, {
|
|
23
|
+
TimeoutError: () => TimeoutError
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(TimeoutError_exports);
|
|
26
|
+
var TimeoutError = class extends Error {
|
|
27
|
+
constructor(message = "The operation was timed out") {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = "TimeoutError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
TimeoutError
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=TimeoutError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/error/TimeoutError.ts"],"sourcesContent":["/**\n * An error class representing an timeout operation.\n * @augments Error\n */\nexport class TimeoutError extends Error {\n constructor(message = 'The operation was timed out') {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,UAAU,+BAA+B;AACnD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/error/index.d.mts
CHANGED
package/dist/error/index.d.ts
CHANGED
package/dist/error/index.js
CHANGED
|
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/error/index.ts
|
|
21
21
|
var error_exports = {};
|
|
22
22
|
__export(error_exports, {
|
|
23
|
-
AbortError: () => AbortError
|
|
23
|
+
AbortError: () => AbortError,
|
|
24
|
+
TimeoutError: () => TimeoutError
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(error_exports);
|
|
26
27
|
|
|
@@ -31,8 +32,17 @@ var AbortError = class extends Error {
|
|
|
31
32
|
this.name = "AbortError";
|
|
32
33
|
}
|
|
33
34
|
};
|
|
35
|
+
|
|
36
|
+
// src/error/TimeoutError.ts
|
|
37
|
+
var TimeoutError = class extends Error {
|
|
38
|
+
constructor(message = "The operation was timed out") {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = "TimeoutError";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
34
43
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
44
|
0 && (module.exports = {
|
|
36
|
-
AbortError
|
|
45
|
+
AbortError,
|
|
46
|
+
TimeoutError
|
|
37
47
|
});
|
|
38
48
|
//# sourceMappingURL=index.js.map
|
package/dist/error/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/error/index.ts","../../src/error/AbortError.ts"],"sourcesContent":["export { AbortError } from './AbortError.ts';\n","/**\n * An error class representing an aborted operation.\n * @augments Error\n */\nexport class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/error/index.ts","../../src/error/AbortError.ts","../../src/error/TimeoutError.ts"],"sourcesContent":["export { AbortError } from './AbortError.ts';\nexport { TimeoutError } from './TimeoutError.ts';\n","/**\n * An error class representing an aborted operation.\n * @augments Error\n */\nexport class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n","/**\n * An error class representing an timeout operation.\n * @augments Error\n */\nexport class TimeoutError extends Error {\n constructor(message = 'The operation was timed out') {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACLO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,UAAU,+BAA+B;AACnD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
|
package/dist/error/index.mjs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-F47GLYUU.mjs";
|
|
2
2
|
import {
|
|
3
3
|
AbortError
|
|
4
4
|
} from "../chunk-DXB7EZUQ.mjs";
|
|
5
|
-
import
|
|
5
|
+
import {
|
|
6
|
+
TimeoutError
|
|
7
|
+
} from "../chunk-KIOYQRMQ.mjs";
|
|
8
|
+
import "../chunk-424M7IR7.mjs";
|
|
6
9
|
export {
|
|
7
|
-
AbortError
|
|
10
|
+
AbortError,
|
|
11
|
+
TimeoutError
|
|
8
12
|
};
|
|
9
13
|
//# sourceMappingURL=index.mjs.map
|
package/dist/function/index.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import "../chunk-236H5JZJ.mjs";
|
|
2
|
+
import {
|
|
3
|
+
noop
|
|
4
|
+
} from "../chunk-LKXCOLNY.mjs";
|
|
2
5
|
import {
|
|
3
6
|
once
|
|
4
7
|
} from "../chunk-CMBC4MXG.mjs";
|
|
@@ -11,10 +14,7 @@ import {
|
|
|
11
14
|
import {
|
|
12
15
|
negate
|
|
13
16
|
} from "../chunk-BOOQBJN2.mjs";
|
|
14
|
-
import
|
|
15
|
-
noop
|
|
16
|
-
} from "../chunk-LKXCOLNY.mjs";
|
|
17
|
-
import "../chunk-2MM5EJJX.mjs";
|
|
17
|
+
import "../chunk-424M7IR7.mjs";
|
|
18
18
|
export {
|
|
19
19
|
debounce,
|
|
20
20
|
negate,
|
package/dist/function/negate.mjs
CHANGED
package/dist/function/noop.mjs
CHANGED
package/dist/function/once.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -50,6 +50,7 @@ export { toFilled } from './array/toFilled.mjs';
|
|
|
50
50
|
export { last } from './array/last.mjs';
|
|
51
51
|
export { initial } from './array/initial.mjs';
|
|
52
52
|
export { AbortError } from './error/AbortError.mjs';
|
|
53
|
+
export { TimeoutError } from './error/TimeoutError.mjs';
|
|
53
54
|
export { debounce } from './function/debounce.mjs';
|
|
54
55
|
export { noop } from './function/noop.mjs';
|
|
55
56
|
export { once } from './function/once.mjs';
|
|
@@ -78,6 +79,7 @@ export { isNotNil } from './predicate/isNotNil.mjs';
|
|
|
78
79
|
export { isNull } from './predicate/isNull.mjs';
|
|
79
80
|
export { isUndefined } from './predicate/isUndefined.mjs';
|
|
80
81
|
export { delay } from './promise/delay.mjs';
|
|
82
|
+
export { withTimeout } from './promise/withTimeout.mjs';
|
|
81
83
|
export { camelCase } from './string/camelCase.mjs';
|
|
82
84
|
export { snakeCase } from './string/snakeCase.mjs';
|
|
83
85
|
export { kebabCase } from './string/kebabCase.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export { toFilled } from './array/toFilled.js';
|
|
|
50
50
|
export { last } from './array/last.js';
|
|
51
51
|
export { initial } from './array/initial.js';
|
|
52
52
|
export { AbortError } from './error/AbortError.js';
|
|
53
|
+
export { TimeoutError } from './error/TimeoutError.js';
|
|
53
54
|
export { debounce } from './function/debounce.js';
|
|
54
55
|
export { noop } from './function/noop.js';
|
|
55
56
|
export { once } from './function/once.js';
|
|
@@ -78,6 +79,7 @@ export { isNotNil } from './predicate/isNotNil.js';
|
|
|
78
79
|
export { isNull } from './predicate/isNull.js';
|
|
79
80
|
export { isUndefined } from './predicate/isUndefined.js';
|
|
80
81
|
export { delay } from './promise/delay.js';
|
|
82
|
+
export { withTimeout } from './promise/withTimeout.js';
|
|
81
83
|
export { camelCase } from './string/camelCase.js';
|
|
82
84
|
export { snakeCase } from './string/snakeCase.js';
|
|
83
85
|
export { kebabCase } from './string/kebabCase.js';
|
package/dist/index.js
CHANGED
|
@@ -30,11 +30,32 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
30
30
|
return to;
|
|
31
31
|
};
|
|
32
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var __async = (__this, __arguments, generator) => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
var fulfilled = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.next(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var rejected = (value) => {
|
|
43
|
+
try {
|
|
44
|
+
step(generator.throw(value));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
reject(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
+
});
|
|
52
|
+
};
|
|
33
53
|
|
|
34
54
|
// src/index.ts
|
|
35
55
|
var src_exports = {};
|
|
36
56
|
__export(src_exports, {
|
|
37
57
|
AbortError: () => AbortError,
|
|
58
|
+
TimeoutError: () => TimeoutError,
|
|
38
59
|
camelCase: () => camelCase,
|
|
39
60
|
capitalize: () => capitalize,
|
|
40
61
|
chunk: () => chunk,
|
|
@@ -113,6 +134,7 @@ __export(src_exports, {
|
|
|
113
134
|
uniqWith: () => uniqWith,
|
|
114
135
|
unzip: () => unzip,
|
|
115
136
|
unzipWith: () => unzipWith,
|
|
137
|
+
withTimeout: () => withTimeout,
|
|
116
138
|
without: () => without,
|
|
117
139
|
xor: () => xor,
|
|
118
140
|
xorBy: () => xorBy,
|
|
@@ -652,6 +674,14 @@ var AbortError = class extends Error {
|
|
|
652
674
|
}
|
|
653
675
|
};
|
|
654
676
|
|
|
677
|
+
// src/error/TimeoutError.ts
|
|
678
|
+
var TimeoutError = class extends Error {
|
|
679
|
+
constructor(message = "The operation was timed out") {
|
|
680
|
+
super(message);
|
|
681
|
+
this.name = "TimeoutError";
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
|
|
655
685
|
// src/function/debounce.ts
|
|
656
686
|
function debounce(func, debounceMs, { signal } = {}) {
|
|
657
687
|
let timeoutId = null;
|
|
@@ -984,6 +1014,21 @@ function delay(ms, { signal } = {}) {
|
|
|
984
1014
|
});
|
|
985
1015
|
}
|
|
986
1016
|
|
|
1017
|
+
// src/promise/timeout.ts
|
|
1018
|
+
function timeout(ms) {
|
|
1019
|
+
return __async(this, null, function* () {
|
|
1020
|
+
yield delay(ms);
|
|
1021
|
+
throw new TimeoutError();
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
// src/promise/withTimeout.ts
|
|
1026
|
+
function withTimeout(run, ms) {
|
|
1027
|
+
return __async(this, null, function* () {
|
|
1028
|
+
return Promise.race([run(), timeout(ms)]);
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
|
|
987
1032
|
// src/string/capitalize.ts
|
|
988
1033
|
var capitalize = (str) => {
|
|
989
1034
|
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
@@ -1043,6 +1088,7 @@ function startCase(str) {
|
|
|
1043
1088
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1044
1089
|
0 && (module.exports = {
|
|
1045
1090
|
AbortError,
|
|
1091
|
+
TimeoutError,
|
|
1046
1092
|
camelCase,
|
|
1047
1093
|
capitalize,
|
|
1048
1094
|
chunk,
|
|
@@ -1121,6 +1167,7 @@ function startCase(str) {
|
|
|
1121
1167
|
uniqWith,
|
|
1122
1168
|
unzip,
|
|
1123
1169
|
unzipWith,
|
|
1170
|
+
withTimeout,
|
|
1124
1171
|
without,
|
|
1125
1172
|
xor,
|
|
1126
1173
|
xorBy,
|