es-toolkit 1.13.1-dev.327 → 1.13.1-dev.329

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.
Files changed (34) hide show
  1. package/dist/array/index.js.map +1 -1
  2. package/dist/array/index.mjs +16 -16
  3. package/dist/array/zipObject.d.mts +1 -1
  4. package/dist/array/zipObject.d.ts +1 -1
  5. package/dist/array/zipObject.js.map +1 -1
  6. package/dist/array/zipObject.mjs +1 -1
  7. package/dist/browser.js.map +1 -1
  8. package/dist/browser.mjs +18 -18
  9. package/dist/{chunk-MSHSKENG.mjs → chunk-5F26PFZL.mjs} +1 -1
  10. package/dist/{chunk-MSHSKENG.mjs.map → chunk-5F26PFZL.mjs.map} +1 -1
  11. package/dist/{chunk-JYSV56US.mjs → chunk-7GXKT3VW.mjs} +1 -1
  12. package/dist/chunk-7GXKT3VW.mjs.map +1 -0
  13. package/dist/{chunk-6GWEY5EL.mjs → chunk-BGWHVWY4.mjs} +1 -1
  14. package/dist/{chunk-6GWEY5EL.mjs.map → chunk-BGWHVWY4.mjs.map} +1 -1
  15. package/dist/{chunk-LXO6F6XN.mjs → chunk-GZGXXIF7.mjs} +40 -40
  16. package/dist/chunk-GZGXXIF7.mjs.map +1 -0
  17. package/dist/compat/index.d.mts +2 -2
  18. package/dist/compat/index.d.ts +2 -2
  19. package/dist/compat/index.js.map +1 -1
  20. package/dist/compat/index.mjs +39 -39
  21. package/dist/function/debounce.js.map +1 -1
  22. package/dist/function/debounce.mjs +1 -1
  23. package/dist/function/index.js.map +1 -1
  24. package/dist/function/index.mjs +9 -9
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +40 -40
  27. package/dist/predicate/index.js.map +1 -1
  28. package/dist/predicate/index.mjs +1 -1
  29. package/dist/predicate/isEqual.js.map +1 -1
  30. package/dist/predicate/isEqual.mjs +1 -1
  31. package/package.json +4 -1
  32. package/umd/browser.global.js +1 -1
  33. package/dist/chunk-JYSV56US.mjs.map +0 -1
  34. package/dist/chunk-LXO6F6XN.mjs.map +0 -1
@@ -13,7 +13,7 @@ import {
13
13
  set,
14
14
  startsWith,
15
15
  zipObjectDeep
16
- } from "../chunk-LXO6F6XN.mjs";
16
+ } from "../chunk-GZGXXIF7.mjs";
17
17
  import "../chunk-NKLIE2OI.mjs";
18
18
  import "../chunk-4OIZM4HS.mjs";
19
19
  import {
@@ -71,7 +71,7 @@ import {
71
71
  } from "../chunk-27QMXBLJ.mjs";
72
72
  import {
73
73
  isEqual
74
- } from "../chunk-JYSV56US.mjs";
74
+ } from "../chunk-7GXKT3VW.mjs";
75
75
  import "../chunk-YXAOYIRV.mjs";
76
76
  import {
77
77
  invert
@@ -123,29 +123,7 @@ import {
123
123
  import {
124
124
  sum
125
125
  } from "../chunk-2SLTL4KL.mjs";
126
- import "../chunk-ZA2XI3OV.mjs";
127
- import {
128
- throttle
129
- } from "../chunk-QOJGMVVR.mjs";
130
- import {
131
- after
132
- } from "../chunk-OGZMEWPR.mjs";
133
- import {
134
- debounce
135
- } from "../chunk-MSHSKENG.mjs";
136
- import {
137
- negate
138
- } from "../chunk-BOOQBJN2.mjs";
139
- import {
140
- noop
141
- } from "../chunk-LKXCOLNY.mjs";
142
- import {
143
- once
144
- } from "../chunk-CMBC4MXG.mjs";
145
126
  import "../chunk-DDH7K4QM.mjs";
146
- import {
147
- zipObject
148
- } from "../chunk-6GWEY5EL.mjs";
149
127
  import {
150
128
  zipWith
151
129
  } from "../chunk-MJ7LNBI6.mjs";
@@ -171,8 +149,8 @@ import {
171
149
  zip
172
150
  } from "../chunk-OLORW442.mjs";
173
151
  import {
174
- takeRightWhile
175
- } from "../chunk-NTLX2MPV.mjs";
152
+ zipObject
153
+ } from "../chunk-BGWHVWY4.mjs";
176
154
  import {
177
155
  takeWhile
178
156
  } from "../chunk-2IXFGSUA.mjs";
@@ -188,9 +166,6 @@ import {
188
166
  import {
189
167
  unionWith
190
168
  } from "../chunk-2ZCITDMK.mjs";
191
- import {
192
- uniqWith
193
- } from "../chunk-237HGSZS.mjs";
194
169
  import {
195
170
  uniq
196
171
  } from "../chunk-DVK2N4KC.mjs";
@@ -198,8 +173,8 @@ import {
198
173
  uniqBy
199
174
  } from "../chunk-B4COTK4K.mjs";
200
175
  import {
201
- orderBy
202
- } from "../chunk-7B7W36UP.mjs";
176
+ uniqWith
177
+ } from "../chunk-237HGSZS.mjs";
203
178
  import {
204
179
  partition
205
180
  } from "../chunk-DN3NOZ3H.mjs";
@@ -228,8 +203,8 @@ import {
228
203
  takeRight
229
204
  } from "../chunk-N3QYJX4T.mjs";
230
205
  import {
231
- initial
232
- } from "../chunk-XPSOKBRZ.mjs";
206
+ takeRightWhile
207
+ } from "../chunk-NTLX2MPV.mjs";
233
208
  import {
234
209
  intersection
235
210
  } from "../chunk-FVVSE2F2.mjs";
@@ -251,7 +226,9 @@ import {
251
226
  import {
252
227
  minBy
253
228
  } from "../chunk-IJD7FE2Z.mjs";
254
- import "../chunk-GTFDDKZ2.mjs";
229
+ import {
230
+ orderBy
231
+ } from "../chunk-7B7W36UP.mjs";
255
232
  import {
256
233
  flatMap
257
234
  } from "../chunk-UY76KTPE.mjs";
@@ -271,8 +248,8 @@ import {
271
248
  head
272
249
  } from "../chunk-FZZNWXDM.mjs";
273
250
  import {
274
- countBy
275
- } from "../chunk-Z7HWEOQX.mjs";
251
+ initial
252
+ } from "../chunk-XPSOKBRZ.mjs";
276
253
  import "../chunk-JPUKH67K.mjs";
277
254
  import {
278
255
  differenceBy
@@ -292,6 +269,27 @@ import {
292
269
  import {
293
270
  dropWhile
294
271
  } from "../chunk-LJ2C6MVP.mjs";
272
+ import "../chunk-GTFDDKZ2.mjs";
273
+ import "../chunk-ZA2XI3OV.mjs";
274
+ import {
275
+ negate
276
+ } from "../chunk-BOOQBJN2.mjs";
277
+ import {
278
+ noop
279
+ } from "../chunk-LKXCOLNY.mjs";
280
+ import {
281
+ once
282
+ } from "../chunk-CMBC4MXG.mjs";
283
+ import {
284
+ throttle
285
+ } from "../chunk-QOJGMVVR.mjs";
286
+ import "../chunk-E6C5EZQA.mjs";
287
+ import {
288
+ compact
289
+ } from "../chunk-PJPGJ2O6.mjs";
290
+ import {
291
+ countBy
292
+ } from "../chunk-Z7HWEOQX.mjs";
295
293
  import "../chunk-F47GLYUU.mjs";
296
294
  import {
297
295
  AbortError
@@ -299,10 +297,12 @@ import {
299
297
  import {
300
298
  TimeoutError
301
299
  } from "../chunk-KIOYQRMQ.mjs";
302
- import "../chunk-E6C5EZQA.mjs";
303
300
  import {
304
- compact
305
- } from "../chunk-PJPGJ2O6.mjs";
301
+ after
302
+ } from "../chunk-OGZMEWPR.mjs";
303
+ import {
304
+ debounce
305
+ } from "../chunk-5F26PFZL.mjs";
306
306
  import "../chunk-J5LGTIGS.mjs";
307
307
  export {
308
308
  AbortError,
@@ -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,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":[]}
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: ReturnType<typeof setTimeout> | 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) ;\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,YAAkD;AAEtD,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":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  debounce
3
- } from "../chunk-MSHSKENG.mjs";
3
+ } from "../chunk-5F26PFZL.mjs";
4
4
  import "../chunk-J5LGTIGS.mjs";
5
5
  export {
6
6
  debounce
@@ -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;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AC5D,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":[]}
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: ReturnType<typeof setTimeout> | 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) ;\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,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../chunk-QOJGMVVR.mjs";
5
- import {
6
- after
7
- } from "../chunk-OGZMEWPR.mjs";
8
- import {
9
- debounce
10
- } from "../chunk-MSHSKENG.mjs";
11
2
  import {
12
3
  negate
13
4
  } from "../chunk-BOOQBJN2.mjs";
@@ -17,6 +8,15 @@ import {
17
8
  import {
18
9
  once
19
10
  } from "../chunk-CMBC4MXG.mjs";
11
+ import {
12
+ throttle
13
+ } from "../chunk-QOJGMVVR.mjs";
14
+ import {
15
+ after
16
+ } from "../chunk-OGZMEWPR.mjs";
17
+ import {
18
+ debounce
19
+ } from "../chunk-5F26PFZL.mjs";
20
20
  import "../chunk-J5LGTIGS.mjs";
21
21
  export {
22
22
  after,