es-toolkit 1.13.1-dev.313 → 1.13.1-dev.315
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/CHANGELOG.md +1 -1
- package/dist/array/index.mjs +19 -19
- package/dist/browser.js +15 -0
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +19 -18
- package/dist/browser.mjs.map +1 -1
- package/dist/{chunk-PYFT73RZ.mjs → chunk-HKO7DEJK.mjs} +42 -38
- package/dist/{chunk-PYFT73RZ.mjs.map → chunk-HKO7DEJK.mjs.map} +1 -1
- package/dist/chunk-OGZMEWPR.mjs +18 -0
- package/dist/chunk-OGZMEWPR.mjs.map +1 -0
- package/dist/chunk-ZA2XI3OV.mjs +1 -0
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +16 -0
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +45 -41
- package/dist/function/after.d.mts +31 -0
- package/dist/function/after.d.ts +31 -0
- package/dist/function/after.js +42 -0
- package/dist/function/after.js.map +1 -0
- package/dist/function/after.mjs +8 -0
- package/dist/function/after.mjs.map +1 -0
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +16 -0
- package/dist/function/index.js.map +1 -1
- package/dist/function/index.mjs +5 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -41
- package/dist/math/index.mjs +3 -3
- package/dist/object/index.mjs +3 -3
- package/dist/predicate/index.mjs +3 -3
- package/dist/string/index.mjs +3 -3
- package/package.json +1 -1
- package/umd/browser.global.js +1 -1
- package/dist/chunk-236H5JZJ.mjs +0 -1
- /package/dist/{chunk-236H5JZJ.mjs.map → chunk-ZA2XI3OV.mjs.map} +0 -0
package/dist/compat/index.mjs
CHANGED
|
@@ -12,9 +12,12 @@ import {
|
|
|
12
12
|
set,
|
|
13
13
|
startsWith,
|
|
14
14
|
zipObjectDeep
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-HKO7DEJK.mjs";
|
|
16
16
|
import "../chunk-NKLIE2OI.mjs";
|
|
17
17
|
import "../chunk-XT74R35S.mjs";
|
|
18
|
+
import {
|
|
19
|
+
startCase
|
|
20
|
+
} from "../chunk-QXTNZR7B.mjs";
|
|
18
21
|
import {
|
|
19
22
|
camelCase
|
|
20
23
|
} from "../chunk-Y5V7UAZZ.mjs";
|
|
@@ -30,9 +33,6 @@ import {
|
|
|
30
33
|
import {
|
|
31
34
|
snakeCase
|
|
32
35
|
} from "../chunk-F3WCQQET.mjs";
|
|
33
|
-
import {
|
|
34
|
-
startCase
|
|
35
|
-
} from "../chunk-QXTNZR7B.mjs";
|
|
36
36
|
import "../chunk-WVQ7YVRK.mjs";
|
|
37
37
|
import "../chunk-4OIZM4HS.mjs";
|
|
38
38
|
import {
|
|
@@ -58,16 +58,19 @@ import {
|
|
|
58
58
|
import {
|
|
59
59
|
isArrayLike
|
|
60
60
|
} from "../chunk-LPZZIY5Z.mjs";
|
|
61
|
+
import {
|
|
62
|
+
isLength
|
|
63
|
+
} from "../chunk-27QMXBLJ.mjs";
|
|
61
64
|
import {
|
|
62
65
|
isEqual
|
|
63
66
|
} from "../chunk-JYSV56US.mjs";
|
|
64
67
|
import {
|
|
65
68
|
isFunction
|
|
66
69
|
} from "../chunk-74CREQXW.mjs";
|
|
67
|
-
import {
|
|
68
|
-
isLength
|
|
69
|
-
} from "../chunk-27QMXBLJ.mjs";
|
|
70
70
|
import "../chunk-54TK5BIS.mjs";
|
|
71
|
+
import {
|
|
72
|
+
omit
|
|
73
|
+
} from "../chunk-WFZXCGEG.mjs";
|
|
71
74
|
import {
|
|
72
75
|
omitBy
|
|
73
76
|
} from "../chunk-BCTYOXT7.mjs";
|
|
@@ -87,10 +90,10 @@ import "../chunk-MIGAC7F4.mjs";
|
|
|
87
90
|
import {
|
|
88
91
|
invert
|
|
89
92
|
} from "../chunk-OLX53VEF.mjs";
|
|
90
|
-
import {
|
|
91
|
-
omit
|
|
92
|
-
} from "../chunk-WFZXCGEG.mjs";
|
|
93
93
|
import "../chunk-FUS75PJ7.mjs";
|
|
94
|
+
import {
|
|
95
|
+
range
|
|
96
|
+
} from "../chunk-DPH2KE6O.mjs";
|
|
94
97
|
import {
|
|
95
98
|
round
|
|
96
99
|
} from "../chunk-5PMKOZ2F.mjs";
|
|
@@ -112,10 +115,13 @@ import {
|
|
|
112
115
|
import {
|
|
113
116
|
sum
|
|
114
117
|
} from "../chunk-2SLTL4KL.mjs";
|
|
115
|
-
import {
|
|
116
|
-
range
|
|
117
|
-
} from "../chunk-DPH2KE6O.mjs";
|
|
118
118
|
import "../chunk-DDH7K4QM.mjs";
|
|
119
|
+
import {
|
|
120
|
+
zipWith
|
|
121
|
+
} from "../chunk-4KYXHZ4R.mjs";
|
|
122
|
+
import {
|
|
123
|
+
unzip
|
|
124
|
+
} from "../chunk-UYZKMBDO.mjs";
|
|
119
125
|
import {
|
|
120
126
|
unzipWith
|
|
121
127
|
} from "../chunk-IFNXROZR.mjs";
|
|
@@ -138,8 +144,8 @@ import {
|
|
|
138
144
|
zipObject
|
|
139
145
|
} from "../chunk-6GWEY5EL.mjs";
|
|
140
146
|
import {
|
|
141
|
-
|
|
142
|
-
} from "../chunk-
|
|
147
|
+
takeWhile
|
|
148
|
+
} from "../chunk-2IXFGSUA.mjs";
|
|
143
149
|
import {
|
|
144
150
|
toFilled
|
|
145
151
|
} from "../chunk-OP4OAKQJ.mjs";
|
|
@@ -162,8 +168,8 @@ import {
|
|
|
162
168
|
uniqWith
|
|
163
169
|
} from "../chunk-237HGSZS.mjs";
|
|
164
170
|
import {
|
|
165
|
-
|
|
166
|
-
} from "../chunk-
|
|
171
|
+
partition
|
|
172
|
+
} from "../chunk-DN3NOZ3H.mjs";
|
|
167
173
|
import {
|
|
168
174
|
sample
|
|
169
175
|
} from "../chunk-2KNLZB7V.mjs";
|
|
@@ -192,8 +198,8 @@ import {
|
|
|
192
198
|
takeRightWhile
|
|
193
199
|
} from "../chunk-NTLX2MPV.mjs";
|
|
194
200
|
import {
|
|
195
|
-
|
|
196
|
-
} from "../chunk-
|
|
201
|
+
intersection
|
|
202
|
+
} from "../chunk-FVVSE2F2.mjs";
|
|
197
203
|
import {
|
|
198
204
|
intersectionBy
|
|
199
205
|
} from "../chunk-O6UXZR3U.mjs";
|
|
@@ -216,11 +222,14 @@ import {
|
|
|
216
222
|
orderBy
|
|
217
223
|
} from "../chunk-7B7W36UP.mjs";
|
|
218
224
|
import {
|
|
219
|
-
|
|
220
|
-
} from "../chunk-
|
|
225
|
+
flatMap
|
|
226
|
+
} from "../chunk-UY76KTPE.mjs";
|
|
221
227
|
import {
|
|
222
228
|
flattenDeep
|
|
223
229
|
} from "../chunk-ML727RRJ.mjs";
|
|
230
|
+
import {
|
|
231
|
+
flatten
|
|
232
|
+
} from "../chunk-33MSBDC6.mjs";
|
|
224
233
|
import {
|
|
225
234
|
forEachRight
|
|
226
235
|
} from "../chunk-IEA53J7P.mjs";
|
|
@@ -233,9 +242,7 @@ import {
|
|
|
233
242
|
import {
|
|
234
243
|
initial
|
|
235
244
|
} from "../chunk-XPSOKBRZ.mjs";
|
|
236
|
-
import
|
|
237
|
-
intersection
|
|
238
|
-
} from "../chunk-FVVSE2F2.mjs";
|
|
245
|
+
import "../chunk-JPUKH67K.mjs";
|
|
239
246
|
import {
|
|
240
247
|
differenceBy
|
|
241
248
|
} from "../chunk-LVWX5B43.mjs";
|
|
@@ -255,12 +262,19 @@ import {
|
|
|
255
262
|
dropWhile
|
|
256
263
|
} from "../chunk-LJ2C6MVP.mjs";
|
|
257
264
|
import "../chunk-YFN6KOC4.mjs";
|
|
265
|
+
import "../chunk-ZA2XI3OV.mjs";
|
|
258
266
|
import {
|
|
259
|
-
|
|
260
|
-
} from "../chunk-
|
|
267
|
+
negate
|
|
268
|
+
} from "../chunk-BOOQBJN2.mjs";
|
|
261
269
|
import {
|
|
262
|
-
|
|
263
|
-
} from "../chunk-
|
|
270
|
+
noop
|
|
271
|
+
} from "../chunk-LKXCOLNY.mjs";
|
|
272
|
+
import {
|
|
273
|
+
once
|
|
274
|
+
} from "../chunk-CMBC4MXG.mjs";
|
|
275
|
+
import {
|
|
276
|
+
throttle
|
|
277
|
+
} from "../chunk-QOJGMVVR.mjs";
|
|
264
278
|
import "../chunk-E6C5EZQA.mjs";
|
|
265
279
|
import {
|
|
266
280
|
compact
|
|
@@ -268,7 +282,6 @@ import {
|
|
|
268
282
|
import {
|
|
269
283
|
countBy
|
|
270
284
|
} from "../chunk-CRSKT4WW.mjs";
|
|
271
|
-
import "../chunk-JPUKH67K.mjs";
|
|
272
285
|
import "../chunk-F47GLYUU.mjs";
|
|
273
286
|
import {
|
|
274
287
|
AbortError
|
|
@@ -276,19 +289,9 @@ import {
|
|
|
276
289
|
import {
|
|
277
290
|
TimeoutError
|
|
278
291
|
} from "../chunk-KIOYQRMQ.mjs";
|
|
279
|
-
import "../chunk-236H5JZJ.mjs";
|
|
280
292
|
import {
|
|
281
|
-
|
|
282
|
-
} from "../chunk-
|
|
283
|
-
import {
|
|
284
|
-
noop
|
|
285
|
-
} from "../chunk-LKXCOLNY.mjs";
|
|
286
|
-
import {
|
|
287
|
-
once
|
|
288
|
-
} from "../chunk-CMBC4MXG.mjs";
|
|
289
|
-
import {
|
|
290
|
-
throttle
|
|
291
|
-
} from "../chunk-QOJGMVVR.mjs";
|
|
293
|
+
after
|
|
294
|
+
} from "../chunk-OGZMEWPR.mjs";
|
|
292
295
|
import {
|
|
293
296
|
debounce
|
|
294
297
|
} from "../chunk-3IP4JVLL.mjs";
|
|
@@ -296,6 +299,7 @@ import "../chunk-24FKGR6U.mjs";
|
|
|
296
299
|
export {
|
|
297
300
|
AbortError,
|
|
298
301
|
TimeoutError,
|
|
302
|
+
after,
|
|
299
303
|
camelCase,
|
|
300
304
|
capitalize,
|
|
301
305
|
chunk,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that only executes starting from the `n`-th call.
|
|
3
|
+
* The provided function will be invoked starting from the `n`-th call.
|
|
4
|
+
*
|
|
5
|
+
* This is particularly useful for scenarios involving events or asynchronous operations
|
|
6
|
+
* where an action should occur only after a certain number of invocations.
|
|
7
|
+
*
|
|
8
|
+
* @template F - The type of the function to be invoked.
|
|
9
|
+
* @param {number} n - The number of calls required for `func` to execute.
|
|
10
|
+
* @param {F} func - The function to be invoked.
|
|
11
|
+
* @returns {F} - A new function that:
|
|
12
|
+
* - Tracks the number of calls.
|
|
13
|
+
* - Invokes `func` starting from the `n`-th call.
|
|
14
|
+
* - Returns `undefined` if fewer than `n` calls have been made.
|
|
15
|
+
* @throws {Error} - Throws an error if `n` is negative.
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* const afterFn = after(3, () => {
|
|
19
|
+
* console.log("called")
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Will not log anything.
|
|
23
|
+
* afterFn()
|
|
24
|
+
* // Will not log anything.
|
|
25
|
+
* afterFn()
|
|
26
|
+
* // Will log 'called'.
|
|
27
|
+
* afterFn()
|
|
28
|
+
*/
|
|
29
|
+
declare const after: <F extends (...args: any[]) => any>(n: number, func: F) => F;
|
|
30
|
+
|
|
31
|
+
export { after };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that only executes starting from the `n`-th call.
|
|
3
|
+
* The provided function will be invoked starting from the `n`-th call.
|
|
4
|
+
*
|
|
5
|
+
* This is particularly useful for scenarios involving events or asynchronous operations
|
|
6
|
+
* where an action should occur only after a certain number of invocations.
|
|
7
|
+
*
|
|
8
|
+
* @template F - The type of the function to be invoked.
|
|
9
|
+
* @param {number} n - The number of calls required for `func` to execute.
|
|
10
|
+
* @param {F} func - The function to be invoked.
|
|
11
|
+
* @returns {F} - A new function that:
|
|
12
|
+
* - Tracks the number of calls.
|
|
13
|
+
* - Invokes `func` starting from the `n`-th call.
|
|
14
|
+
* - Returns `undefined` if fewer than `n` calls have been made.
|
|
15
|
+
* @throws {Error} - Throws an error if `n` is negative.
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* const afterFn = after(3, () => {
|
|
19
|
+
* console.log("called")
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Will not log anything.
|
|
23
|
+
* afterFn()
|
|
24
|
+
* // Will not log anything.
|
|
25
|
+
* afterFn()
|
|
26
|
+
* // Will log 'called'.
|
|
27
|
+
* afterFn()
|
|
28
|
+
*/
|
|
29
|
+
declare const after: <F extends (...args: any[]) => any>(n: number, func: F) => F;
|
|
30
|
+
|
|
31
|
+
export { after };
|
|
@@ -0,0 +1,42 @@
|
|
|
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/function/after.ts
|
|
21
|
+
var after_exports = {};
|
|
22
|
+
__export(after_exports, {
|
|
23
|
+
after: () => after
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(after_exports);
|
|
26
|
+
var after = (n, func) => {
|
|
27
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
28
|
+
throw new Error(`n must be a non-negative integer.`);
|
|
29
|
+
}
|
|
30
|
+
let counter = 0;
|
|
31
|
+
return (...args) => {
|
|
32
|
+
if (++counter >= n) {
|
|
33
|
+
return func(...args);
|
|
34
|
+
}
|
|
35
|
+
return void 0;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
after
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=after.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/function/after.ts"],"sourcesContent":["/**\n * Creates a function that only executes starting from the `n`-th call.\n * The provided function will be invoked starting from the `n`-th call.\n *\n * This is particularly useful for scenarios involving events or asynchronous operations\n * where an action should occur only after a certain number of invocations.\n *\n * @template F - The type of the function to be invoked.\n * @param {number} n - The number of calls required for `func` to execute.\n * @param {F} func - The function to be invoked.\n * @returns {F} - A new function that:\n * - Tracks the number of calls.\n * - Invokes `func` starting from the `n`-th call.\n * - Returns `undefined` if fewer than `n` calls have been made.\n * @throws {Error} - Throws an error if `n` is negative.\n * @example\n *\n * const afterFn = after(3, () => {\n * console.log(\"called\")\n * });\n *\n * // Will not log anything.\n * afterFn()\n * // Will not log anything.\n * afterFn()\n * // Will log 'called'.\n * afterFn()\n */\n\nexport const after = <F extends (...args: any[]) => any>(n: number, func: F): F => {\n if (!Number.isInteger(n) || n < 0) {\n throw new Error(`n must be a non-negative integer.`);\n }\n\n let counter = 0;\n return ((...args: Parameters<F>) => {\n if (++counter >= n) {\n return func(...args);\n }\n return undefined;\n }) as F;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6BO,IAAM,QAAQ,CAAoC,GAAW,SAAe;AACjF,MAAI,CAAC,OAAO,UAAU,CAAC,KAAK,IAAI,GAAG;AACjC,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,MAAI,UAAU;AACd,SAAQ,IAAI,SAAwB;AAClC,QAAI,EAAE,WAAW,GAAG;AAClB,aAAO,KAAK,GAAG,IAAI;AAAA,IACrB;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/function/index.d.ts
CHANGED
package/dist/function/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/function/index.ts
|
|
21
21
|
var function_exports = {};
|
|
22
22
|
__export(function_exports, {
|
|
23
|
+
after: () => after,
|
|
23
24
|
debounce: () => debounce,
|
|
24
25
|
negate: () => negate,
|
|
25
26
|
noop: () => noop,
|
|
@@ -28,6 +29,20 @@ __export(function_exports, {
|
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(function_exports);
|
|
30
31
|
|
|
32
|
+
// src/function/after.ts
|
|
33
|
+
var after = (n, func) => {
|
|
34
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
35
|
+
throw new Error(`n must be a non-negative integer.`);
|
|
36
|
+
}
|
|
37
|
+
let counter = 0;
|
|
38
|
+
return (...args) => {
|
|
39
|
+
if (++counter >= n) {
|
|
40
|
+
return func(...args);
|
|
41
|
+
}
|
|
42
|
+
return void 0;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
31
46
|
// src/function/debounce.ts
|
|
32
47
|
function debounce(func, debounceMs, { signal } = {}) {
|
|
33
48
|
let timeoutId = null;
|
|
@@ -94,6 +109,7 @@ function negate(func) {
|
|
|
94
109
|
}
|
|
95
110
|
// Annotate the CommonJS export names for ESM import in node:
|
|
96
111
|
0 && (module.exports = {
|
|
112
|
+
after,
|
|
97
113
|
debounce,
|
|
98
114
|
negate,
|
|
99
115
|
noop,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/function/index.ts","../../src/function/debounce.ts","../../src/function/noop.ts","../../src/function/once.ts","../../src/function/throttle.ts","../../src/function/negate.ts"],"sourcesContent":["export { debounce } from './debounce.ts';\nexport { noop } from './noop.ts';\nexport { once } from './once.ts';\nexport { throttle } from './throttle.ts';\nexport { negate } from './negate.ts';\n","interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @template F - The type of function.\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @param {DebounceOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n { signal }: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: number | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs) as any;\n } as F & { cancel: () => void };\n\n const onAbort = function () {\n debounced.cancel();\n };\n\n debounced.cancel = function () {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n };\n\n signal?.addEventListener('abort', onAbort, { once: true });\n\n return debounced;\n}\n","/**\n * A no-operation function that does nothing.\n * This can be used as a placeholder or default function.\n *\n * @example\n * noop(); // Does nothing\n *\n * @returns {void} This function does not return anything.\n */\nexport function noop(): void {}\n","/**\n * Creates a function that is restricted to invoking the provided function `func` once.\n * Repeated calls to the function will return the value from the first invocation.\n *\n * @template F - The type of function.\n * @param {F} func - The function to restrict.\n * @returns {F} A new function that invokes `func` once and caches the result.\n *\n * @example\n * const initialize = once(() => {\n * console.log('Initialized!');\n * return true;\n * });\n *\n * initialize(); // Logs: 'Initialized!' and returns true\n * initialize(); // Returns true without logging\n */\nexport function once<F extends () => any>(func: F): F {\n let called = false;\n let cache: ReturnType<F> | undefined;\n\n return function () {\n if (called) {\n return cache;\n }\n\n const result = func();\n\n called = true;\n cache = result;\n\n return result;\n } as F;\n}\n","/**\n * Creates a throttled function that only invokes the provided function at most once\n * per every `throttleMs` milliseconds. Subsequent calls to the throttled function\n * within the wait time will not trigger the execution of the original function.\n *\n * @template F - The type of function.\n * @param {F} func - The function to throttle.\n * @param {number} throttleMs - The number of milliseconds to throttle executions to.\n * @returns {F} A new throttled function that accepts the same parameters as the original function.\n *\n * @example\n * const throttledFunction = throttle(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' immediately\n * throttledFunction();\n *\n * // Will not log anything as it is within the throttle time\n * throttledFunction();\n *\n * // After 1 second\n * setTimeout(() => {\n * throttledFunction(); // Will log 'Function executed'\n * }, 1000);\n */\nexport function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number): F {\n let lastCallTime: number | null;\n\n const throttledFunction = function (...args: Parameters<F>) {\n const now = Date.now();\n\n if (lastCallTime == null || now - lastCallTime >= throttleMs) {\n lastCallTime = now;\n func(...args);\n }\n } as F;\n\n return throttledFunction;\n}\n","/**\n * Creates a function that negates the result of the predicate function.\n *\n * @template F - The type of the function to negate.\n * @param {F} func - The function to negate.\n * @returns {F} The new negated function, which negates the boolean result of `func`.\n */\nexport function negate<F extends (...args: unknown[]) => boolean>(func: F): F {\n return ((...args: any[]) => !func(...args)) as F;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;
|
|
1
|
+
{"version":3,"sources":["../../src/function/index.ts","../../src/function/after.ts","../../src/function/debounce.ts","../../src/function/noop.ts","../../src/function/once.ts","../../src/function/throttle.ts","../../src/function/negate.ts"],"sourcesContent":["export { after } from './after.ts';\nexport { debounce } from './debounce.ts';\nexport { noop } from './noop.ts';\nexport { once } from './once.ts';\nexport { throttle } from './throttle.ts';\nexport { negate } from './negate.ts';\n","/**\n * Creates a function that only executes starting from the `n`-th call.\n * The provided function will be invoked starting from the `n`-th call.\n *\n * This is particularly useful for scenarios involving events or asynchronous operations\n * where an action should occur only after a certain number of invocations.\n *\n * @template F - The type of the function to be invoked.\n * @param {number} n - The number of calls required for `func` to execute.\n * @param {F} func - The function to be invoked.\n * @returns {F} - A new function that:\n * - Tracks the number of calls.\n * - Invokes `func` starting from the `n`-th call.\n * - Returns `undefined` if fewer than `n` calls have been made.\n * @throws {Error} - Throws an error if `n` is negative.\n * @example\n *\n * const afterFn = after(3, () => {\n * console.log(\"called\")\n * });\n *\n * // Will not log anything.\n * afterFn()\n * // Will not log anything.\n * afterFn()\n * // Will log 'called'.\n * afterFn()\n */\n\nexport const after = <F extends (...args: any[]) => any>(n: number, func: F): F => {\n if (!Number.isInteger(n) || n < 0) {\n throw new Error(`n must be a non-negative integer.`);\n }\n\n let counter = 0;\n return ((...args: Parameters<F>) => {\n if (++counter >= n) {\n return func(...args);\n }\n return undefined;\n }) as F;\n};\n","interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @template F - The type of function.\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @param {DebounceOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n { signal }: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: number | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs) as any;\n } as F & { cancel: () => void };\n\n const onAbort = function () {\n debounced.cancel();\n };\n\n debounced.cancel = function () {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n };\n\n signal?.addEventListener('abort', onAbort, { once: true });\n\n return debounced;\n}\n","/**\n * A no-operation function that does nothing.\n * This can be used as a placeholder or default function.\n *\n * @example\n * noop(); // Does nothing\n *\n * @returns {void} This function does not return anything.\n */\nexport function noop(): void {}\n","/**\n * Creates a function that is restricted to invoking the provided function `func` once.\n * Repeated calls to the function will return the value from the first invocation.\n *\n * @template F - The type of function.\n * @param {F} func - The function to restrict.\n * @returns {F} A new function that invokes `func` once and caches the result.\n *\n * @example\n * const initialize = once(() => {\n * console.log('Initialized!');\n * return true;\n * });\n *\n * initialize(); // Logs: 'Initialized!' and returns true\n * initialize(); // Returns true without logging\n */\nexport function once<F extends () => any>(func: F): F {\n let called = false;\n let cache: ReturnType<F> | undefined;\n\n return function () {\n if (called) {\n return cache;\n }\n\n const result = func();\n\n called = true;\n cache = result;\n\n return result;\n } as F;\n}\n","/**\n * Creates a throttled function that only invokes the provided function at most once\n * per every `throttleMs` milliseconds. Subsequent calls to the throttled function\n * within the wait time will not trigger the execution of the original function.\n *\n * @template F - The type of function.\n * @param {F} func - The function to throttle.\n * @param {number} throttleMs - The number of milliseconds to throttle executions to.\n * @returns {F} A new throttled function that accepts the same parameters as the original function.\n *\n * @example\n * const throttledFunction = throttle(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' immediately\n * throttledFunction();\n *\n * // Will not log anything as it is within the throttle time\n * throttledFunction();\n *\n * // After 1 second\n * setTimeout(() => {\n * throttledFunction(); // Will log 'Function executed'\n * }, 1000);\n */\nexport function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number): F {\n let lastCallTime: number | null;\n\n const throttledFunction = function (...args: Parameters<F>) {\n const now = Date.now();\n\n if (lastCallTime == null || now - lastCallTime >= throttleMs) {\n lastCallTime = now;\n func(...args);\n }\n } as F;\n\n return throttledFunction;\n}\n","/**\n * Creates a function that negates the result of the predicate function.\n *\n * @template F - The type of the function to negate.\n * @param {F} func - The function to negate.\n * @returns {F} The new negated function, which negates the boolean result of `func`.\n */\nexport function negate<F extends (...args: unknown[]) => boolean>(func: F): F {\n return ((...args: any[]) => !func(...args)) as F;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6BO,IAAM,QAAQ,CAAoC,GAAW,SAAe;AACjF,MAAI,CAAC,OAAO,UAAU,CAAC,KAAK,IAAI,GAAG;AACjC,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,MAAI,UAAU;AACd,SAAQ,IAAI,SAAwB;AAClC,QAAI,EAAE,WAAW,GAAG;AAClB,aAAO,KAAK,GAAG,IAAI;AAAA,IACrB;AACA,WAAO;AAAA,EACT;AACF;;;ACFO,SAAS,SACd,MACA,YACA,EAAE,OAAO,IAAqB,CAAC,GACH;AAC5B,MAAI,YAA2B;AAE/B,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AAAA,IACxB;AAEA,QAAI,iCAAQ,SAAS;AACnB;AAAA,IACF;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AACZ,kBAAY;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,QAAM,UAAU,WAAY;AAC1B,cAAU,OAAO;AAAA,EACnB;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAAA,EACF;AAEA,mCAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK;AAExD,SAAO;AACT;;;AClEO,SAAS,OAAa;AAAC;;;ACQvB,SAAS,KAA0B,MAAY;AACpD,MAAI,SAAS;AACb,MAAI;AAEJ,SAAO,WAAY;AACjB,QAAI,QAAQ;AACV,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,KAAK;AAEpB,aAAS;AACT,YAAQ;AAER,WAAO;AAAA,EACT;AACF;;;ACPO,SAAS,SAA6C,MAAS,YAAuB;AAC3F,MAAI;AAEJ,QAAM,oBAAoB,YAAa,MAAqB;AAC1D,UAAM,MAAM,KAAK,IAAI;AAErB,QAAI,gBAAgB,QAAQ,MAAM,gBAAgB,YAAY;AAC5D,qBAAe;AACf,WAAK,GAAG,IAAI;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AACT;;;AChCO,SAAS,OAAkD,MAAY;AAC1E,SAAQ,IAAI,SAAgB,CAAC,KAAK,GAAG,IAAI;AAC7C;","names":[]}
|
package/dist/function/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-ZA2XI3OV.mjs";
|
|
2
2
|
import {
|
|
3
3
|
negate
|
|
4
4
|
} from "../chunk-BOOQBJN2.mjs";
|
|
@@ -11,11 +11,15 @@ import {
|
|
|
11
11
|
import {
|
|
12
12
|
throttle
|
|
13
13
|
} from "../chunk-QOJGMVVR.mjs";
|
|
14
|
+
import {
|
|
15
|
+
after
|
|
16
|
+
} from "../chunk-OGZMEWPR.mjs";
|
|
14
17
|
import {
|
|
15
18
|
debounce
|
|
16
19
|
} from "../chunk-3IP4JVLL.mjs";
|
|
17
20
|
import "../chunk-24FKGR6U.mjs";
|
|
18
21
|
export {
|
|
22
|
+
after,
|
|
19
23
|
debounce,
|
|
20
24
|
negate,
|
|
21
25
|
noop,
|
package/dist/index.d.mts
CHANGED
|
@@ -51,6 +51,7 @@ export { last } from './array/last.mjs';
|
|
|
51
51
|
export { initial } from './array/initial.mjs';
|
|
52
52
|
export { AbortError } from './error/AbortError.mjs';
|
|
53
53
|
export { TimeoutError } from './error/TimeoutError.mjs';
|
|
54
|
+
export { after } from './function/after.mjs';
|
|
54
55
|
export { debounce } from './function/debounce.mjs';
|
|
55
56
|
export { noop } from './function/noop.mjs';
|
|
56
57
|
export { once } from './function/once.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export { last } from './array/last.js';
|
|
|
51
51
|
export { initial } from './array/initial.js';
|
|
52
52
|
export { AbortError } from './error/AbortError.js';
|
|
53
53
|
export { TimeoutError } from './error/TimeoutError.js';
|
|
54
|
+
export { after } from './function/after.js';
|
|
54
55
|
export { debounce } from './function/debounce.js';
|
|
55
56
|
export { noop } from './function/noop.js';
|
|
56
57
|
export { once } from './function/once.js';
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,7 @@ var src_exports = {};
|
|
|
56
56
|
__export(src_exports, {
|
|
57
57
|
AbortError: () => AbortError,
|
|
58
58
|
TimeoutError: () => TimeoutError,
|
|
59
|
+
after: () => after,
|
|
59
60
|
camelCase: () => camelCase,
|
|
60
61
|
capitalize: () => capitalize,
|
|
61
62
|
chunk: () => chunk,
|
|
@@ -691,6 +692,20 @@ var TimeoutError = class extends Error {
|
|
|
691
692
|
}
|
|
692
693
|
};
|
|
693
694
|
|
|
695
|
+
// src/function/after.ts
|
|
696
|
+
var after = (n, func) => {
|
|
697
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
698
|
+
throw new Error(`n must be a non-negative integer.`);
|
|
699
|
+
}
|
|
700
|
+
let counter = 0;
|
|
701
|
+
return (...args) => {
|
|
702
|
+
if (++counter >= n) {
|
|
703
|
+
return func(...args);
|
|
704
|
+
}
|
|
705
|
+
return void 0;
|
|
706
|
+
};
|
|
707
|
+
};
|
|
708
|
+
|
|
694
709
|
// src/function/debounce.ts
|
|
695
710
|
function debounce(func, debounceMs, { signal } = {}) {
|
|
696
711
|
let timeoutId = null;
|
|
@@ -1132,6 +1147,7 @@ function startCase(str) {
|
|
|
1132
1147
|
0 && (module.exports = {
|
|
1133
1148
|
AbortError,
|
|
1134
1149
|
TimeoutError,
|
|
1150
|
+
after,
|
|
1135
1151
|
camelCase,
|
|
1136
1152
|
capitalize,
|
|
1137
1153
|
chunk,
|