es-toolkit 1.13.1-dev.326 → 1.13.1-dev.328

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-EEHJ656S.mjs → chunk-GMNIATN3.mjs} +40 -40
  16. package/dist/chunk-GMNIATN3.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 +1 -1
  32. package/umd/browser.global.js +1 -1
  33. package/dist/chunk-EEHJ656S.mjs.map +0 -1
  34. package/dist/chunk-JYSV56US.mjs.map +0 -1
@@ -13,7 +13,7 @@ import {
13
13
  set,
14
14
  startsWith,
15
15
  zipObjectDeep
16
- } from "../chunk-EEHJ656S.mjs";
16
+ } from "../chunk-GMNIATN3.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,7 +123,29 @@ 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-5F26PFZL.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";
126
145
  import "../chunk-DDH7K4QM.mjs";
146
+ import {
147
+ zipObject
148
+ } from "../chunk-BGWHVWY4.mjs";
127
149
  import {
128
150
  zipWith
129
151
  } from "../chunk-MJ7LNBI6.mjs";
@@ -149,8 +171,8 @@ import {
149
171
  zip
150
172
  } from "../chunk-OLORW442.mjs";
151
173
  import {
152
- zipObject
153
- } from "../chunk-6GWEY5EL.mjs";
174
+ takeRightWhile
175
+ } from "../chunk-NTLX2MPV.mjs";
154
176
  import {
155
177
  takeWhile
156
178
  } from "../chunk-2IXFGSUA.mjs";
@@ -166,6 +188,9 @@ import {
166
188
  import {
167
189
  unionWith
168
190
  } from "../chunk-2ZCITDMK.mjs";
191
+ import {
192
+ uniqWith
193
+ } from "../chunk-237HGSZS.mjs";
169
194
  import {
170
195
  uniq
171
196
  } from "../chunk-DVK2N4KC.mjs";
@@ -173,8 +198,8 @@ import {
173
198
  uniqBy
174
199
  } from "../chunk-B4COTK4K.mjs";
175
200
  import {
176
- uniqWith
177
- } from "../chunk-237HGSZS.mjs";
201
+ orderBy
202
+ } from "../chunk-7B7W36UP.mjs";
178
203
  import {
179
204
  partition
180
205
  } from "../chunk-DN3NOZ3H.mjs";
@@ -203,8 +228,8 @@ import {
203
228
  takeRight
204
229
  } from "../chunk-N3QYJX4T.mjs";
205
230
  import {
206
- takeRightWhile
207
- } from "../chunk-NTLX2MPV.mjs";
231
+ initial
232
+ } from "../chunk-XPSOKBRZ.mjs";
208
233
  import {
209
234
  intersection
210
235
  } from "../chunk-FVVSE2F2.mjs";
@@ -226,9 +251,7 @@ import {
226
251
  import {
227
252
  minBy
228
253
  } from "../chunk-IJD7FE2Z.mjs";
229
- import {
230
- orderBy
231
- } from "../chunk-7B7W36UP.mjs";
254
+ import "../chunk-GTFDDKZ2.mjs";
232
255
  import {
233
256
  flatMap
234
257
  } from "../chunk-UY76KTPE.mjs";
@@ -248,8 +271,8 @@ import {
248
271
  head
249
272
  } from "../chunk-FZZNWXDM.mjs";
250
273
  import {
251
- initial
252
- } from "../chunk-XPSOKBRZ.mjs";
274
+ countBy
275
+ } from "../chunk-Z7HWEOQX.mjs";
253
276
  import "../chunk-JPUKH67K.mjs";
254
277
  import {
255
278
  differenceBy
@@ -269,27 +292,6 @@ import {
269
292
  import {
270
293
  dropWhile
271
294
  } 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";
293
295
  import "../chunk-F47GLYUU.mjs";
294
296
  import {
295
297
  AbortError
@@ -297,12 +299,10 @@ import {
297
299
  import {
298
300
  TimeoutError
299
301
  } from "../chunk-KIOYQRMQ.mjs";
302
+ import "../chunk-E6C5EZQA.mjs";
300
303
  import {
301
- after
302
- } from "../chunk-OGZMEWPR.mjs";
303
- import {
304
- debounce
305
- } from "../chunk-MSHSKENG.mjs";
304
+ compact
305
+ } from "../chunk-PJPGJ2O6.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;AAAA;A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BAAe;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,aAAO,K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k-QOJGMVVR.mjs";
5
+ import {
6
+ after
7
+ } from "../chunk-OGZMEWPR.mjs";
8
+ import {
9
+ debounce
10
+ } from "../chunk-5F26PFZL.mjs";
2
11
  import {
3
12
  negate
4
13
  } from "../chunk-BOOQBJN2.mjs";
@@ -8,15 +17,6 @@ import {
8
17
  import {
9
18
  once
10
19
  } 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-MSHSKENG.mjs";
20
20
  import "../chunk-J5LGTIGS.mjs";
21
21
  export {
22
22
  after,