es-toolkit 1.13.1-dev.318 → 1.13.1-dev.321
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.js +1 -2
- package/dist/array/countBy.js.map +1 -1
- package/dist/array/countBy.mjs +2 -2
- 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.js +1 -2
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +2 -2
- 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/browser.js +33 -58
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +19 -17
- package/dist/browser.mjs.map +1 -1
- package/dist/{chunk-QXTNZR7B.mjs → chunk-3SBT6WDU.mjs} +2 -2
- package/dist/{chunk-O64NE2P4.mjs → chunk-4DFAGGIM.mjs} +3 -3
- package/dist/{chunk-O64NE2P4.mjs.map → chunk-4DFAGGIM.mjs.map} +1 -1
- package/dist/{chunk-Y5V7UAZZ.mjs → chunk-4ZES5T6V.mjs} +4 -4
- package/dist/{chunk-EYYZQFOP.mjs → chunk-ET33L3MQ.mjs} +2 -2
- package/dist/chunk-EZYYB34V.mjs +17 -0
- package/dist/{chunk-CVVZHOJX.mjs.map → chunk-EZYYB34V.mjs.map} +1 -1
- package/dist/{chunk-36ZJSTNA.mjs → chunk-IGM5IABU.mjs} +37 -24
- package/dist/chunk-IGM5IABU.mjs.map +1 -0
- package/dist/{chunk-F3WCQQET.mjs → chunk-IWXZI3QT.mjs} +2 -2
- package/dist/chunk-J5LGTIGS.mjs +10 -0
- package/dist/{chunk-5CPXZFCB.mjs → chunk-K5WL54BY.mjs} +2 -2
- package/dist/{chunk-5CPXZFCB.mjs.map → chunk-K5WL54BY.mjs.map} +1 -1
- package/dist/{chunk-3IP4JVLL.mjs → chunk-MSHSKENG.mjs} +3 -3
- package/dist/{chunk-3IP4JVLL.mjs.map → chunk-MSHSKENG.mjs.map} +1 -1
- package/dist/{chunk-WVQ7YVRK.mjs → chunk-OG2RLT5U.mjs} +2 -3
- package/dist/{chunk-WVQ7YVRK.mjs.map → chunk-OG2RLT5U.mjs.map} +1 -1
- package/dist/chunk-R6GLTTAB.mjs +9 -0
- package/dist/chunk-R6GLTTAB.mjs.map +1 -0
- package/dist/{chunk-5IKVJGHO.mjs → chunk-RTFTLCF3.mjs} +2 -2
- package/dist/chunk-SXFMQQ6F.mjs +9 -0
- package/dist/chunk-SXFMQQ6F.mjs.map +1 -0
- package/dist/{chunk-WFZXCGEG.mjs → chunk-YOPFSFTD.mjs} +2 -6
- package/dist/{chunk-WFZXCGEG.mjs.map → chunk-YOPFSFTD.mjs.map} +1 -1
- package/dist/chunk-YXD3AQAK.mjs +1 -0
- package/dist/{chunk-CRSKT4WW.mjs → chunk-Z7HWEOQX.mjs} +2 -3
- package/dist/{chunk-CRSKT4WW.mjs.map → chunk-Z7HWEOQX.mjs.map} +1 -1
- package/dist/chunk-ZPNX2QDE.mjs +13 -0
- package/dist/{chunk-IIDZ3KAJ.mjs.map → chunk-ZPNX2QDE.mjs.map} +1 -1
- package/dist/compat/index.d.mts +20 -1
- package/dist/compat/index.d.ts +20 -1
- package/dist/compat/index.js +35 -57
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +30 -23
- package/dist/error/AbortError.mjs +1 -1
- package/dist/error/TimeoutError.mjs +1 -1
- package/dist/error/index.mjs +1 -1
- package/dist/function/after.mjs +1 -1
- package/dist/function/debounce.js +2 -2
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/debounce.mjs +2 -2
- package/dist/function/index.js +2 -2
- package/dist/function/index.js.map +1 -1
- package/dist/function/index.mjs +2 -2
- 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 +27 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -22
- package/dist/math/clamp.mjs +1 -1
- package/dist/math/inRange.mjs +1 -1
- package/dist/math/index.mjs +1 -1
- 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/cloneDeep.js +1 -1
- package/dist/object/cloneDeep.js.map +1 -1
- package/dist/object/cloneDeep.mjs +2 -2
- package/dist/object/flattenObject.mjs +1 -1
- package/dist/object/index.js +2 -16
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +3 -3
- package/dist/object/invert.mjs +1 -1
- package/dist/object/omit.js +1 -15
- package/dist/object/omit.js.map +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.d.mts +2 -0
- package/dist/predicate/index.d.ts +2 -0
- package/dist/predicate/index.js +14 -0
- package/dist/predicate/index.js.map +1 -1
- package/dist/predicate/index.mjs +12 -4
- package/dist/predicate/isArrayLike.mjs +1 -1
- package/dist/predicate/isEqual.mjs +1 -1
- package/dist/predicate/isFunction.mjs +1 -1
- package/dist/predicate/isLength.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/isPlainObject.mjs +1 -1
- package/dist/predicate/isPrimitive.d.mts +17 -0
- package/dist/predicate/isPrimitive.d.ts +17 -0
- package/dist/predicate/isPrimitive.js +33 -0
- package/dist/predicate/isPrimitive.js.map +1 -0
- package/dist/predicate/isPrimitive.mjs +8 -0
- package/dist/predicate/isPrimitive.mjs.map +1 -0
- package/dist/predicate/isTypedArray.d.mts +19 -0
- package/dist/predicate/isTypedArray.d.ts +19 -0
- package/dist/predicate/isTypedArray.js +33 -0
- package/dist/predicate/isTypedArray.js.map +1 -0
- package/dist/predicate/isTypedArray.mjs +8 -0
- package/dist/predicate/isTypedArray.mjs.map +1 -0
- package/dist/predicate/isUndefined.mjs +1 -1
- package/dist/promise/delay.js +2 -2
- package/dist/promise/delay.js.map +1 -1
- package/dist/promise/delay.mjs +2 -2
- package/dist/promise/index.js +7 -31
- package/dist/promise/index.js.map +1 -1
- package/dist/promise/index.mjs +4 -4
- package/dist/promise/timeout.js +5 -27
- package/dist/promise/timeout.js.map +1 -1
- package/dist/promise/timeout.mjs +3 -3
- package/dist/promise/withTimeout.js +7 -31
- package/dist/promise/withTimeout.js.map +1 -1
- package/dist/promise/withTimeout.mjs +4 -4
- package/dist/string/camelCase.js +1 -2
- package/dist/string/camelCase.js.map +1 -1
- package/dist/string/camelCase.mjs +3 -3
- package/dist/string/capitalize.mjs +1 -1
- package/dist/string/index.js +1 -2
- package/dist/string/index.js.map +1 -1
- package/dist/string/index.mjs +11 -11
- package/dist/string/kebabCase.js +1 -2
- package/dist/string/kebabCase.js.map +1 -1
- package/dist/string/kebabCase.mjs +3 -3
- package/dist/string/lowerCase.js +1 -2
- package/dist/string/lowerCase.js.map +1 -1
- package/dist/string/lowerCase.mjs +3 -3
- package/dist/string/snakeCase.js +1 -2
- package/dist/string/snakeCase.js.map +1 -1
- package/dist/string/snakeCase.mjs +3 -3
- package/dist/string/startCase.js +1 -2
- package/dist/string/startCase.js.map +1 -1
- package/dist/string/startCase.mjs +3 -3
- package/package.json +1 -1
- package/umd/browser.global.js +1 -1
- package/dist/chunk-24FKGR6U.mjs +0 -47
- package/dist/chunk-36ZJSTNA.mjs.map +0 -1
- package/dist/chunk-CVVZHOJX.mjs +0 -22
- package/dist/chunk-IIDZ3KAJ.mjs +0 -18
- package/dist/chunk-U4JWMVQK.mjs +0 -1
- /package/dist/{chunk-QXTNZR7B.mjs.map → chunk-3SBT6WDU.mjs.map} +0 -0
- /package/dist/{chunk-Y5V7UAZZ.mjs.map → chunk-4ZES5T6V.mjs.map} +0 -0
- /package/dist/{chunk-EYYZQFOP.mjs.map → chunk-ET33L3MQ.mjs.map} +0 -0
- /package/dist/{chunk-F3WCQQET.mjs.map → chunk-IWXZI3QT.mjs.map} +0 -0
- /package/dist/{chunk-24FKGR6U.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/{chunk-5IKVJGHO.mjs.map → chunk-RTFTLCF3.mjs.map} +0 -0
- /package/dist/{chunk-U4JWMVQK.mjs.map → chunk-YXD3AQAK.mjs.map} +0 -0
package/dist/compat/index.mjs
CHANGED
|
@@ -7,42 +7,46 @@ import {
|
|
|
7
7
|
get,
|
|
8
8
|
isArray,
|
|
9
9
|
isPlainObject,
|
|
10
|
+
isTypedArray,
|
|
10
11
|
max,
|
|
11
12
|
min,
|
|
12
13
|
set,
|
|
13
14
|
startsWith,
|
|
14
15
|
zipObjectDeep
|
|
15
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-IGM5IABU.mjs";
|
|
16
17
|
import "../chunk-NKLIE2OI.mjs";
|
|
17
18
|
import "../chunk-4OIZM4HS.mjs";
|
|
18
19
|
import {
|
|
19
20
|
withTimeout
|
|
20
|
-
} from "../chunk-
|
|
21
|
-
import "../chunk-
|
|
21
|
+
} from "../chunk-ZPNX2QDE.mjs";
|
|
22
|
+
import "../chunk-EZYYB34V.mjs";
|
|
23
|
+
import {
|
|
24
|
+
delay
|
|
25
|
+
} from "../chunk-4DFAGGIM.mjs";
|
|
22
26
|
import "../chunk-XT74R35S.mjs";
|
|
27
|
+
import {
|
|
28
|
+
kebabCase
|
|
29
|
+
} from "../chunk-ET33L3MQ.mjs";
|
|
30
|
+
import {
|
|
31
|
+
lowerCase
|
|
32
|
+
} from "../chunk-RTFTLCF3.mjs";
|
|
23
33
|
import {
|
|
24
34
|
snakeCase
|
|
25
|
-
} from "../chunk-
|
|
35
|
+
} from "../chunk-IWXZI3QT.mjs";
|
|
26
36
|
import {
|
|
27
37
|
startCase
|
|
28
|
-
} from "../chunk-
|
|
38
|
+
} from "../chunk-3SBT6WDU.mjs";
|
|
29
39
|
import {
|
|
30
40
|
camelCase
|
|
31
|
-
} from "../chunk-
|
|
41
|
+
} from "../chunk-4ZES5T6V.mjs";
|
|
42
|
+
import "../chunk-OG2RLT5U.mjs";
|
|
32
43
|
import {
|
|
33
44
|
capitalize
|
|
34
45
|
} from "../chunk-U56ZOM7L.mjs";
|
|
46
|
+
import "../chunk-YXD3AQAK.mjs";
|
|
35
47
|
import {
|
|
36
|
-
|
|
37
|
-
} from "../chunk-
|
|
38
|
-
import {
|
|
39
|
-
lowerCase
|
|
40
|
-
} from "../chunk-5IKVJGHO.mjs";
|
|
41
|
-
import "../chunk-WVQ7YVRK.mjs";
|
|
42
|
-
import {
|
|
43
|
-
delay
|
|
44
|
-
} from "../chunk-O64NE2P4.mjs";
|
|
45
|
-
import "../chunk-U4JWMVQK.mjs";
|
|
48
|
+
isUndefined
|
|
49
|
+
} from "../chunk-VH2PV426.mjs";
|
|
46
50
|
import {
|
|
47
51
|
isFunction
|
|
48
52
|
} from "../chunk-74CREQXW.mjs";
|
|
@@ -56,8 +60,9 @@ import {
|
|
|
56
60
|
isNull
|
|
57
61
|
} from "../chunk-AIRSKN47.mjs";
|
|
58
62
|
import {
|
|
59
|
-
|
|
60
|
-
} from "../chunk-
|
|
63
|
+
isPrimitive
|
|
64
|
+
} from "../chunk-R6GLTTAB.mjs";
|
|
65
|
+
import "../chunk-SXFMQQ6F.mjs";
|
|
61
66
|
import {
|
|
62
67
|
isArrayLike
|
|
63
68
|
} from "../chunk-LPZZIY5Z.mjs";
|
|
@@ -73,7 +78,7 @@ import {
|
|
|
73
78
|
} from "../chunk-OLX53VEF.mjs";
|
|
74
79
|
import {
|
|
75
80
|
omit
|
|
76
|
-
} from "../chunk-
|
|
81
|
+
} from "../chunk-YOPFSFTD.mjs";
|
|
77
82
|
import {
|
|
78
83
|
omitBy
|
|
79
84
|
} from "../chunk-BCTYOXT7.mjs";
|
|
@@ -88,7 +93,7 @@ import {
|
|
|
88
93
|
} from "../chunk-VRUTBJYS.mjs";
|
|
89
94
|
import {
|
|
90
95
|
cloneDeep
|
|
91
|
-
} from "../chunk-
|
|
96
|
+
} from "../chunk-K5WL54BY.mjs";
|
|
92
97
|
import {
|
|
93
98
|
flattenObject
|
|
94
99
|
} from "../chunk-XGQWTHW6.mjs";
|
|
@@ -127,7 +132,7 @@ import {
|
|
|
127
132
|
} from "../chunk-OGZMEWPR.mjs";
|
|
128
133
|
import {
|
|
129
134
|
debounce
|
|
130
|
-
} from "../chunk-
|
|
135
|
+
} from "../chunk-MSHSKENG.mjs";
|
|
131
136
|
import {
|
|
132
137
|
negate
|
|
133
138
|
} from "../chunk-BOOQBJN2.mjs";
|
|
@@ -267,7 +272,7 @@ import {
|
|
|
267
272
|
} from "../chunk-HM2JT2RX.mjs";
|
|
268
273
|
import {
|
|
269
274
|
countBy
|
|
270
|
-
} from "../chunk-
|
|
275
|
+
} from "../chunk-Z7HWEOQX.mjs";
|
|
271
276
|
import "../chunk-JPUKH67K.mjs";
|
|
272
277
|
import {
|
|
273
278
|
differenceBy
|
|
@@ -298,7 +303,7 @@ import "../chunk-E6C5EZQA.mjs";
|
|
|
298
303
|
import {
|
|
299
304
|
compact
|
|
300
305
|
} from "../chunk-DTJJIMKJ.mjs";
|
|
301
|
-
import "../chunk-
|
|
306
|
+
import "../chunk-J5LGTIGS.mjs";
|
|
302
307
|
export {
|
|
303
308
|
AbortError,
|
|
304
309
|
TimeoutError,
|
|
@@ -347,6 +352,8 @@ export {
|
|
|
347
352
|
isNotNil,
|
|
348
353
|
isNull,
|
|
349
354
|
isPlainObject,
|
|
355
|
+
isPrimitive,
|
|
356
|
+
isTypedArray,
|
|
350
357
|
isUndefined,
|
|
351
358
|
kebabCase,
|
|
352
359
|
keyBy,
|
package/dist/error/index.mjs
CHANGED
package/dist/function/after.mjs
CHANGED
|
@@ -29,7 +29,7 @@ function debounce(func, debounceMs, { signal } = {}) {
|
|
|
29
29
|
if (timeoutId !== null) {
|
|
30
30
|
clearTimeout(timeoutId);
|
|
31
31
|
}
|
|
32
|
-
if (signal
|
|
32
|
+
if (signal?.aborted) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
timeoutId = setTimeout(() => {
|
|
@@ -46,7 +46,7 @@ function debounce(func, debounceMs, { signal } = {}) {
|
|
|
46
46
|
timeoutId = null;
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
signal
|
|
49
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
50
50
|
return debounced;
|
|
51
51
|
}
|
|
52
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/function/debounce.ts"],"sourcesContent":["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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuCO,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,
|
|
1
|
+
{"version":3,"sources":["../../src/function/debounce.ts"],"sourcesContent":["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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuCO,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,QAAQ,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,UAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;AAEzD,SAAO;AACT;","names":[]}
|
package/dist/function/index.js
CHANGED
|
@@ -50,7 +50,7 @@ function debounce(func, debounceMs, { signal } = {}) {
|
|
|
50
50
|
if (timeoutId !== null) {
|
|
51
51
|
clearTimeout(timeoutId);
|
|
52
52
|
}
|
|
53
|
-
if (signal
|
|
53
|
+
if (signal?.aborted) {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
timeoutId = setTimeout(() => {
|
|
@@ -67,7 +67,7 @@ function debounce(func, debounceMs, { signal } = {}) {
|
|
|
67
67
|
timeoutId = null;
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
|
-
signal
|
|
70
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
71
71
|
return debounced;
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,QAAQ,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,UAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;AAEzD,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
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "../chunk-OGZMEWPR.mjs";
|
|
8
8
|
import {
|
|
9
9
|
debounce
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-MSHSKENG.mjs";
|
|
11
11
|
import {
|
|
12
12
|
negate
|
|
13
13
|
} from "../chunk-BOOQBJN2.mjs";
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import {
|
|
18
18
|
once
|
|
19
19
|
} from "../chunk-CMBC4MXG.mjs";
|
|
20
|
-
import "../chunk-
|
|
20
|
+
import "../chunk-J5LGTIGS.mjs";
|
|
21
21
|
export {
|
|
22
22
|
after,
|
|
23
23
|
debounce,
|
package/dist/function/negate.mjs
CHANGED
package/dist/function/noop.mjs
CHANGED
package/dist/function/once.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -84,6 +84,8 @@ export { isLength } from './predicate/isLength.mjs';
|
|
|
84
84
|
export { isPlainObject } from './predicate/isPlainObject.mjs';
|
|
85
85
|
export { isFunction } from './predicate/isFunction.mjs';
|
|
86
86
|
export { isArrayLike } from './predicate/isArrayLike.mjs';
|
|
87
|
+
export { isTypedArray } from './predicate/isTypedArray.mjs';
|
|
88
|
+
export { isPrimitive } from './predicate/isPrimitive.mjs';
|
|
87
89
|
export { delay } from './promise/delay.mjs';
|
|
88
90
|
export { withTimeout } from './promise/withTimeout.mjs';
|
|
89
91
|
export { camelCase } from './string/camelCase.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,8 @@ export { isLength } from './predicate/isLength.js';
|
|
|
84
84
|
export { isPlainObject } from './predicate/isPlainObject.js';
|
|
85
85
|
export { isFunction } from './predicate/isFunction.js';
|
|
86
86
|
export { isArrayLike } from './predicate/isArrayLike.js';
|
|
87
|
+
export { isTypedArray } from './predicate/isTypedArray.js';
|
|
88
|
+
export { isPrimitive } from './predicate/isPrimitive.js';
|
|
87
89
|
export { delay } from './promise/delay.js';
|
|
88
90
|
export { withTimeout } from './promise/withTimeout.js';
|
|
89
91
|
export { camelCase } from './string/camelCase.js';
|
package/dist/index.js
CHANGED
|
@@ -2,21 +2,7 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
6
|
var __export = (target, all) => {
|
|
21
7
|
for (var name in all)
|
|
22
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,26 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
30
16
|
return to;
|
|
31
17
|
};
|
|
32
18
|
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
|
-
};
|
|
53
19
|
|
|
54
20
|
// src/index.ts
|
|
55
21
|
var src_exports = {};
|
|
@@ -96,6 +62,8 @@ __export(src_exports, {
|
|
|
96
62
|
isNotNil: () => isNotNil,
|
|
97
63
|
isNull: () => isNull,
|
|
98
64
|
isPlainObject: () => isPlainObject,
|
|
65
|
+
isPrimitive: () => isPrimitive3,
|
|
66
|
+
isTypedArray: () => isTypedArray2,
|
|
99
67
|
isUndefined: () => isUndefined,
|
|
100
68
|
kebabCase: () => kebabCase,
|
|
101
69
|
keyBy: () => keyBy,
|
|
@@ -179,11 +147,10 @@ function compact(arr) {
|
|
|
179
147
|
|
|
180
148
|
// src/array/countBy.ts
|
|
181
149
|
function countBy(arr, mapper) {
|
|
182
|
-
var _a;
|
|
183
150
|
const result = {};
|
|
184
151
|
for (const item of arr) {
|
|
185
152
|
const key = mapper(item);
|
|
186
|
-
result[key] = (
|
|
153
|
+
result[key] = (result[key] ?? 0) + 1;
|
|
187
154
|
}
|
|
188
155
|
return result;
|
|
189
156
|
}
|
|
@@ -714,7 +681,7 @@ function debounce(func, debounceMs, { signal } = {}) {
|
|
|
714
681
|
if (timeoutId !== null) {
|
|
715
682
|
clearTimeout(timeoutId);
|
|
716
683
|
}
|
|
717
|
-
if (signal
|
|
684
|
+
if (signal?.aborted) {
|
|
718
685
|
return;
|
|
719
686
|
}
|
|
720
687
|
timeoutId = setTimeout(() => {
|
|
@@ -731,7 +698,7 @@ function debounce(func, debounceMs, { signal } = {}) {
|
|
|
731
698
|
timeoutId = null;
|
|
732
699
|
}
|
|
733
700
|
};
|
|
734
|
-
signal
|
|
701
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
735
702
|
return debounced;
|
|
736
703
|
}
|
|
737
704
|
|
|
@@ -849,7 +816,7 @@ function range(start, end, step) {
|
|
|
849
816
|
|
|
850
817
|
// src/object/omit.ts
|
|
851
818
|
function omit(obj, keys) {
|
|
852
|
-
const result =
|
|
819
|
+
const result = { ...obj };
|
|
853
820
|
for (const key of keys) {
|
|
854
821
|
delete result[key];
|
|
855
822
|
}
|
|
@@ -1019,7 +986,7 @@ function cloneDeepHelper(obj, clonedObj) {
|
|
|
1019
986
|
for (const key in obj) {
|
|
1020
987
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
1021
988
|
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
1022
|
-
if ((
|
|
989
|
+
if ((descriptor?.writable || descriptor?.set) && typeof descriptor?.value !== "function") {
|
|
1023
990
|
clonedObj[key] = cloneDeep(obj[key]);
|
|
1024
991
|
}
|
|
1025
992
|
}
|
|
@@ -1144,6 +1111,16 @@ function isArrayLike(value) {
|
|
|
1144
1111
|
return value != null && typeof value !== "function" && isLength(value.length);
|
|
1145
1112
|
}
|
|
1146
1113
|
|
|
1114
|
+
// src/predicate/isTypedArray.ts
|
|
1115
|
+
function isTypedArray2(x) {
|
|
1116
|
+
return x instanceof Uint8Array || x instanceof Uint8ClampedArray || x instanceof Uint16Array || x instanceof Uint32Array || x instanceof BigUint64Array || x instanceof Int8Array || x instanceof Int16Array || x instanceof Int32Array || x instanceof BigInt64Array || x instanceof Float32Array || x instanceof Float64Array;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// src/predicate/isPrimitive.ts
|
|
1120
|
+
function isPrimitive3(value) {
|
|
1121
|
+
return value == null || typeof value !== "object" && typeof value !== "function";
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1147
1124
|
// src/promise/delay.ts
|
|
1148
1125
|
function delay(ms, { signal } = {}) {
|
|
1149
1126
|
return new Promise((resolve, reject) => {
|
|
@@ -1154,27 +1131,23 @@ function delay(ms, { signal } = {}) {
|
|
|
1154
1131
|
clearTimeout(timeoutId);
|
|
1155
1132
|
abortError();
|
|
1156
1133
|
};
|
|
1157
|
-
if (signal
|
|
1134
|
+
if (signal?.aborted) {
|
|
1158
1135
|
return abortError();
|
|
1159
1136
|
}
|
|
1160
1137
|
const timeoutId = setTimeout(resolve, ms);
|
|
1161
|
-
signal
|
|
1138
|
+
signal?.addEventListener("abort", abortHandler, { once: true });
|
|
1162
1139
|
});
|
|
1163
1140
|
}
|
|
1164
1141
|
|
|
1165
1142
|
// src/promise/timeout.ts
|
|
1166
|
-
function timeout(ms) {
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
throw new TimeoutError();
|
|
1170
|
-
});
|
|
1143
|
+
async function timeout(ms) {
|
|
1144
|
+
await delay(ms);
|
|
1145
|
+
throw new TimeoutError();
|
|
1171
1146
|
}
|
|
1172
1147
|
|
|
1173
1148
|
// src/promise/withTimeout.ts
|
|
1174
|
-
function withTimeout(run, ms) {
|
|
1175
|
-
return
|
|
1176
|
-
return Promise.race([run(), timeout(ms)]);
|
|
1177
|
-
});
|
|
1149
|
+
async function withTimeout(run, ms) {
|
|
1150
|
+
return Promise.race([run(), timeout(ms)]);
|
|
1178
1151
|
}
|
|
1179
1152
|
|
|
1180
1153
|
// src/string/capitalize.ts
|
|
@@ -1185,8 +1158,7 @@ var capitalize = (str) => {
|
|
|
1185
1158
|
// src/string/_internal/getWords.ts
|
|
1186
1159
|
var CASE_SPLIT_PATTERN = /[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g;
|
|
1187
1160
|
function getWords(str) {
|
|
1188
|
-
|
|
1189
|
-
return Array.from((_a = str.match(CASE_SPLIT_PATTERN)) != null ? _a : []);
|
|
1161
|
+
return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);
|
|
1190
1162
|
}
|
|
1191
1163
|
|
|
1192
1164
|
// src/string/camelCase.ts
|
|
@@ -1277,6 +1249,8 @@ function startCase(str) {
|
|
|
1277
1249
|
isNotNil,
|
|
1278
1250
|
isNull,
|
|
1279
1251
|
isPlainObject,
|
|
1252
|
+
isPrimitive,
|
|
1253
|
+
isTypedArray,
|
|
1280
1254
|
isUndefined,
|
|
1281
1255
|
kebabCase,
|
|
1282
1256
|
keyBy,
|