@vielzeug/toolkit 1.0.12 → 1.0.13

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 (98) hide show
  1. package/dist/array/chunk.cjs +1 -1
  2. package/dist/array/chunk.cjs.map +1 -1
  3. package/dist/array/chunk.js +15 -12
  4. package/dist/array/chunk.js.map +1 -1
  5. package/dist/array/group.cjs +1 -1
  6. package/dist/array/group.cjs.map +1 -1
  7. package/dist/array/group.js +9 -9
  8. package/dist/array/group.js.map +1 -1
  9. package/dist/array/list.cjs +1 -1
  10. package/dist/array/list.cjs.map +1 -1
  11. package/dist/array/list.js +28 -24
  12. package/dist/array/list.js.map +1 -1
  13. package/dist/array/pick.cjs.map +1 -1
  14. package/dist/array/pick.js.map +1 -1
  15. package/dist/date/timeDiff.cjs +1 -1
  16. package/dist/date/timeDiff.cjs.map +1 -1
  17. package/dist/date/timeDiff.js +10 -12
  18. package/dist/date/timeDiff.js.map +1 -1
  19. package/dist/function/curry.cjs +1 -1
  20. package/dist/function/curry.cjs.map +1 -1
  21. package/dist/function/curry.js +3 -3
  22. package/dist/function/curry.js.map +1 -1
  23. package/dist/function/debounce.cjs +1 -1
  24. package/dist/function/debounce.cjs.map +1 -1
  25. package/dist/function/debounce.js +22 -5
  26. package/dist/function/debounce.js.map +1 -1
  27. package/dist/function/memo.cjs +1 -1
  28. package/dist/function/memo.cjs.map +1 -1
  29. package/dist/function/memo.js +14 -13
  30. package/dist/function/memo.js.map +1 -1
  31. package/dist/function/retry.cjs +1 -1
  32. package/dist/function/retry.cjs.map +1 -1
  33. package/dist/function/retry.js +13 -13
  34. package/dist/function/retry.js.map +1 -1
  35. package/dist/function/sleep.cjs +1 -1
  36. package/dist/function/sleep.cjs.map +1 -1
  37. package/dist/function/sleep.js +8 -3
  38. package/dist/function/sleep.js.map +1 -1
  39. package/dist/function/throttle.cjs +1 -1
  40. package/dist/function/throttle.cjs.map +1 -1
  41. package/dist/function/throttle.js +33 -6
  42. package/dist/function/throttle.js.map +1 -1
  43. package/dist/index.d.ts +62 -51
  44. package/dist/math/average.cjs +1 -1
  45. package/dist/math/average.cjs.map +1 -1
  46. package/dist/math/average.js +18 -12
  47. package/dist/math/average.js.map +1 -1
  48. package/dist/math/median.cjs.map +1 -1
  49. package/dist/math/median.js.map +1 -1
  50. package/dist/math/range.cjs +1 -1
  51. package/dist/math/range.cjs.map +1 -1
  52. package/dist/math/range.js +14 -6
  53. package/dist/math/range.js.map +1 -1
  54. package/dist/math/sum.cjs +1 -1
  55. package/dist/math/sum.cjs.map +1 -1
  56. package/dist/math/sum.js +11 -18
  57. package/dist/math/sum.js.map +1 -1
  58. package/dist/object/clone.cjs +1 -1
  59. package/dist/object/clone.cjs.map +1 -1
  60. package/dist/object/clone.js +13 -3
  61. package/dist/object/clone.js.map +1 -1
  62. package/dist/object/merge.cjs +1 -1
  63. package/dist/object/merge.cjs.map +1 -1
  64. package/dist/object/merge.js +11 -15
  65. package/dist/object/merge.js.map +1 -1
  66. package/dist/object/seek.cjs +1 -1
  67. package/dist/object/seek.cjs.map +1 -1
  68. package/dist/object/seek.js +8 -6
  69. package/dist/object/seek.js.map +1 -1
  70. package/dist/random/uuid.cjs +1 -1
  71. package/dist/random/uuid.cjs.map +1 -1
  72. package/dist/random/uuid.js +6 -3
  73. package/dist/random/uuid.js.map +1 -1
  74. package/dist/string/camelCase.cjs +1 -1
  75. package/dist/string/camelCase.cjs.map +1 -1
  76. package/dist/string/camelCase.js +3 -3
  77. package/dist/string/camelCase.js.map +1 -1
  78. package/dist/string/similarity.cjs +1 -1
  79. package/dist/string/similarity.cjs.map +1 -1
  80. package/dist/string/similarity.js +24 -21
  81. package/dist/string/similarity.js.map +1 -1
  82. package/dist/string/truncate.cjs +1 -1
  83. package/dist/string/truncate.cjs.map +1 -1
  84. package/dist/string/truncate.js +14 -5
  85. package/dist/string/truncate.js.map +1 -1
  86. package/dist/typed/is.cjs +1 -1
  87. package/dist/typed/is.cjs.map +1 -1
  88. package/dist/typed/is.js +30 -31
  89. package/dist/typed/is.js.map +1 -1
  90. package/dist/typed/isEmpty.cjs +1 -1
  91. package/dist/typed/isEmpty.cjs.map +1 -1
  92. package/dist/typed/isEmpty.js +6 -6
  93. package/dist/typed/isEmpty.js.map +1 -1
  94. package/dist/typed/isEqual.cjs +1 -1
  95. package/dist/typed/isEqual.cjs.map +1 -1
  96. package/dist/typed/isEqual.js +22 -17
  97. package/dist/typed/isEqual.js.map +1 -1
  98. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"memo.cjs","sources":["../../src/function/memo.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\nimport type { Fn } from '../types';\n\ntype MemoizeOptions = {\n ttl?: number; // Time-to-live in milliseconds\n maxSize?: number; // Maximum number of items in cache\n};\n\ntype CacheEntry<T extends Fn> = {\n value: ReturnType<T>;\n timestamp: number;\n};\n\n/**\n * Creates a function that memorizes the result of the provided function.\n * Supports expiration (TTL) and limited cache size (LRU).\n *\n * @example\n * ```ts\n * const add = (x, y) => x + y;\n * const memoizedAdd = memo(add, { ttl: 5000, maxSize: 10 });\n *\n * memoizedAdd(1, 2); // 3 (caches the result)\n * memoizedAdd(1, 2); // 3 (from cache)\n * ```\n *\n * @param fn - The function to memorize.\n * @param options - Memoization options.\n * @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).\n * @param [options.maxSize] - (optional) maximum cache size (LRU eviction).\n *\n * @returns A new function that memorizes the input function.\n */\nexport function memo<T extends Fn>(\n fn: T,\n { ttl, maxSize }: MemoizeOptions = {},\n): (...args: Parameters<T>) => ReturnType<T> {\n const cache = new Map<string, CacheEntry<T>>();\n\n const keyGen = (args: Parameters<T>): string => {\n if (args.length === 0) return '__empty__';\n if (args.length === 1) {\n const arg = args[0];\n const argType = typeof arg;\n if (argType === 'string' || argType === 'number' || argType === 'boolean') {\n return `${argType}:${arg}`;\n }\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n }\n return JSON.stringify(args);\n };\n\n return (...args: Parameters<T>): ReturnType<T> => {\n const key = keyGen(args);\n const now = Date.now();\n const cached = cache.get(key);\n\n if (cached && (!ttl || now - cached.timestamp < ttl)) {\n cache.delete(key);\n cache.set(key, cached); // Move to end (most recently used)\n return cached.value;\n }\n\n const result = fn(...args);\n cache.set(key, { timestamp: now, value: result });\n\n if (maxSize && cache.size > maxSize) {\n cache.delete(cache.keys().next().value!); // Remove least recently used\n }\n\n return result;\n };\n}\n"],"names":["memo","fn","ttl","maxSize","cache","keyGen","args","arg","argType","key","now","cached","result"],"mappings":"gFAiCO,SAASA,EACdC,EACA,CAAE,IAAAC,EAAK,QAAAC,CAAA,EAA4B,CAAA,EACQ,CAC3C,MAAMC,MAAY,IAEZC,EAAUC,GAAgC,CAC9C,GAAIA,EAAK,SAAW,EAAG,MAAO,YAC9B,GAAIA,EAAK,SAAW,EAAG,CACrB,MAAMC,EAAMD,EAAK,CAAC,EACZE,EAAU,OAAOD,EACvB,GAAIC,IAAY,UAAYA,IAAY,UAAYA,IAAY,UAC9D,MAAO,GAAGA,CAAO,IAAID,CAAG,GAE1B,GAAIA,IAAQ,KAAM,MAAO,OACzB,GAAIA,IAAQ,OAAW,MAAO,WAChC,CACA,OAAO,KAAK,UAAUD,CAAI,CAC5B,EAEA,MAAO,IAAIA,IAAuC,CAChD,MAAMG,EAAMJ,EAAOC,CAAI,EACjBI,EAAM,KAAK,IAAA,EACXC,EAASP,EAAM,IAAIK,CAAG,EAE5B,GAAIE,IAAW,CAACT,GAAOQ,EAAMC,EAAO,UAAYT,GAC9C,OAAAE,EAAM,OAAOK,CAAG,EAChBL,EAAM,IAAIK,EAAKE,CAAM,EACdA,EAAO,MAGhB,MAAMC,EAASX,EAAG,GAAGK,CAAI,EACzB,OAAAF,EAAM,IAAIK,EAAK,CAAE,UAAWC,EAAK,MAAOE,EAAQ,EAE5CT,GAAWC,EAAM,KAAOD,GAC1BC,EAAM,OAAOA,EAAM,KAAA,EAAO,KAAA,EAAO,KAAM,EAGlCQ,CACT,CACF"}
1
+ {"version":3,"file":"memo.cjs","sources":["../../src/function/memo.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\nimport type { Fn } from '../types';\n\ntype MemoizeOptions<T extends Fn> = {\n ttl?: number; // Time-to-live in milliseconds\n maxSize?: number; // Maximum number of items in cache\n resolver?: (...args: Parameters<T>) => string; // Custom key generator\n};\n\ntype CacheEntry<T extends Fn> = {\n value: ReturnType<T>;\n timestamp: number;\n};\n\n/**\n * Creates a function that memorizes the result of the provided function.\n * Supports expiration (TTL) and limited cache size (LRU).\n *\n * @example\n * ```ts\n * const add = (x, y) => x + y;\n * const memoizedAdd = memo(add, { ttl: 5000, maxSize: 10 });\n *\n * memoizedAdd(1, 2); // 3 (caches the result)\n * memoizedAdd(1, 2); // 3 (from cache)\n * ```\n *\n * @param fn - The function to memorize.\n * @param options - Memoization options.\n * @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).\n * @param [options.maxSize] - (optional) maximum cache size (LRU eviction).\n * @param [options.resolver] - (optional) custom function to resolve the cache key.\n *\n * @returns A new function that memorizes the input function.\n */\nexport function memo<T extends Fn>(\n fn: T,\n { ttl, maxSize, resolver }: MemoizeOptions<T> = {},\n): (...args: Parameters<T>) => ReturnType<T> {\n const cache = new Map<string, CacheEntry<T>>();\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: -\n const keyGen = (args: Parameters<T>): string => {\n if (resolver) return resolver(...args);\n if (args.length === 0) return '__empty__';\n if (args.length === 1) {\n const arg = args[0];\n const argType = typeof arg;\n if (argType === 'string' || argType === 'number' || argType === 'boolean') {\n return `${argType}:${arg}`;\n }\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n }\n return JSON.stringify(args);\n };\n\n return (...args: Parameters<T>): ReturnType<T> => {\n const key = keyGen(args);\n const now = Date.now();\n const cached = cache.get(key);\n\n if (cached && (!ttl || now - cached.timestamp < ttl)) {\n cache.delete(key);\n cache.set(key, cached); // Move to end (most recently used)\n return cached.value;\n }\n\n const result = fn(...args);\n cache.set(key, { timestamp: now, value: result });\n\n if (maxSize && cache.size > maxSize) {\n cache.delete(cache.keys().next().value!); // Remove least recently used\n }\n\n return result;\n };\n}\n"],"names":["memo","fn","ttl","maxSize","resolver","cache","keyGen","args","arg","argType","key","now","cached","result"],"mappings":"gFAmCO,SAASA,EACdC,EACA,CAAE,IAAAC,EAAK,QAAAC,EAAS,SAAAC,CAAA,EAAgC,GACL,CAC3C,MAAMC,MAAY,IAGZC,EAAUC,GAAgC,CAC9C,GAAIH,EAAU,OAAOA,EAAS,GAAGG,CAAI,EACrC,GAAIA,EAAK,SAAW,EAAG,MAAO,YAC9B,GAAIA,EAAK,SAAW,EAAG,CACrB,MAAMC,EAAMD,EAAK,CAAC,EACZE,EAAU,OAAOD,EACvB,GAAIC,IAAY,UAAYA,IAAY,UAAYA,IAAY,UAC9D,MAAO,GAAGA,CAAO,IAAID,CAAG,GAE1B,GAAIA,IAAQ,KAAM,MAAO,OACzB,GAAIA,IAAQ,OAAW,MAAO,WAChC,CACA,OAAO,KAAK,UAAUD,CAAI,CAC5B,EAEA,MAAO,IAAIA,IAAuC,CAChD,MAAMG,EAAMJ,EAAOC,CAAI,EACjBI,EAAM,KAAK,IAAA,EACXC,EAASP,EAAM,IAAIK,CAAG,EAE5B,GAAIE,IAAW,CAACV,GAAOS,EAAMC,EAAO,UAAYV,GAC9C,OAAAG,EAAM,OAAOK,CAAG,EAChBL,EAAM,IAAIK,EAAKE,CAAM,EACdA,EAAO,MAGhB,MAAMC,EAASZ,EAAG,GAAGM,CAAI,EACzB,OAAAF,EAAM,IAAIK,EAAK,CAAE,UAAWC,EAAK,MAAOE,EAAQ,EAE5CV,GAAWE,EAAM,KAAOF,GAC1BE,EAAM,OAAOA,EAAM,KAAA,EAAO,KAAA,EAAO,KAAM,EAGlCQ,CACT,CACF"}
@@ -1,24 +1,25 @@
1
- function f(s, { ttl: u, maxSize: i } = {}) {
2
- const t = /* @__PURE__ */ new Map(), l = (n) => {
3
- if (n.length === 0) return "__empty__";
4
- if (n.length === 1) {
5
- const e = n[0], r = typeof e;
1
+ function m(l, { ttl: i, maxSize: o, resolver: c } = {}) {
2
+ const n = /* @__PURE__ */ new Map(), s = (t) => {
3
+ if (c) return c(...t);
4
+ if (t.length === 0) return "__empty__";
5
+ if (t.length === 1) {
6
+ const e = t[0], r = typeof e;
6
7
  if (r === "string" || r === "number" || r === "boolean")
7
8
  return `${r}:${e}`;
8
9
  if (e === null) return "null";
9
10
  if (e === void 0) return "undefined";
10
11
  }
11
- return JSON.stringify(n);
12
+ return JSON.stringify(t);
12
13
  };
13
- return (...n) => {
14
- const e = l(n), r = Date.now(), o = t.get(e);
15
- if (o && (!u || r - o.timestamp < u))
16
- return t.delete(e), t.set(e, o), o.value;
17
- const c = s(...n);
18
- return t.set(e, { timestamp: r, value: c }), i && t.size > i && t.delete(t.keys().next().value), c;
14
+ return (...t) => {
15
+ const e = s(t), r = Date.now(), u = n.get(e);
16
+ if (u && (!i || r - u.timestamp < i))
17
+ return n.delete(e), n.set(e, u), u.value;
18
+ const f = l(...t);
19
+ return n.set(e, { timestamp: r, value: f }), o && n.size > o && n.delete(n.keys().next().value), f;
19
20
  };
20
21
  }
21
22
  export {
22
- f as memo
23
+ m as memo
23
24
  };
24
25
  //# sourceMappingURL=memo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"memo.js","sources":["../../src/function/memo.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\nimport type { Fn } from '../types';\n\ntype MemoizeOptions = {\n ttl?: number; // Time-to-live in milliseconds\n maxSize?: number; // Maximum number of items in cache\n};\n\ntype CacheEntry<T extends Fn> = {\n value: ReturnType<T>;\n timestamp: number;\n};\n\n/**\n * Creates a function that memorizes the result of the provided function.\n * Supports expiration (TTL) and limited cache size (LRU).\n *\n * @example\n * ```ts\n * const add = (x, y) => x + y;\n * const memoizedAdd = memo(add, { ttl: 5000, maxSize: 10 });\n *\n * memoizedAdd(1, 2); // 3 (caches the result)\n * memoizedAdd(1, 2); // 3 (from cache)\n * ```\n *\n * @param fn - The function to memorize.\n * @param options - Memoization options.\n * @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).\n * @param [options.maxSize] - (optional) maximum cache size (LRU eviction).\n *\n * @returns A new function that memorizes the input function.\n */\nexport function memo<T extends Fn>(\n fn: T,\n { ttl, maxSize }: MemoizeOptions = {},\n): (...args: Parameters<T>) => ReturnType<T> {\n const cache = new Map<string, CacheEntry<T>>();\n\n const keyGen = (args: Parameters<T>): string => {\n if (args.length === 0) return '__empty__';\n if (args.length === 1) {\n const arg = args[0];\n const argType = typeof arg;\n if (argType === 'string' || argType === 'number' || argType === 'boolean') {\n return `${argType}:${arg}`;\n }\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n }\n return JSON.stringify(args);\n };\n\n return (...args: Parameters<T>): ReturnType<T> => {\n const key = keyGen(args);\n const now = Date.now();\n const cached = cache.get(key);\n\n if (cached && (!ttl || now - cached.timestamp < ttl)) {\n cache.delete(key);\n cache.set(key, cached); // Move to end (most recently used)\n return cached.value;\n }\n\n const result = fn(...args);\n cache.set(key, { timestamp: now, value: result });\n\n if (maxSize && cache.size > maxSize) {\n cache.delete(cache.keys().next().value!); // Remove least recently used\n }\n\n return result;\n };\n}\n"],"names":["memo","fn","ttl","maxSize","cache","keyGen","args","arg","argType","key","now","cached","result"],"mappings":"AAiCO,SAASA,EACdC,GACA,EAAE,KAAAC,GAAK,SAAAC,EAAA,IAA4B,CAAA,GACQ;AAC3C,QAAMC,wBAAY,IAAA,GAEZC,IAAS,CAACC,MAAgC;AAC9C,QAAIA,EAAK,WAAW,EAAG,QAAO;AAC9B,QAAIA,EAAK,WAAW,GAAG;AACrB,YAAMC,IAAMD,EAAK,CAAC,GACZE,IAAU,OAAOD;AACvB,UAAIC,MAAY,YAAYA,MAAY,YAAYA,MAAY;AAC9D,eAAO,GAAGA,CAAO,IAAID,CAAG;AAE1B,UAAIA,MAAQ,KAAM,QAAO;AACzB,UAAIA,MAAQ,OAAW,QAAO;AAAA,IAChC;AACA,WAAO,KAAK,UAAUD,CAAI;AAAA,EAC5B;AAEA,SAAO,IAAIA,MAAuC;AAChD,UAAMG,IAAMJ,EAAOC,CAAI,GACjBI,IAAM,KAAK,IAAA,GACXC,IAASP,EAAM,IAAIK,CAAG;AAE5B,QAAIE,MAAW,CAACT,KAAOQ,IAAMC,EAAO,YAAYT;AAC9C,aAAAE,EAAM,OAAOK,CAAG,GAChBL,EAAM,IAAIK,GAAKE,CAAM,GACdA,EAAO;AAGhB,UAAMC,IAASX,EAAG,GAAGK,CAAI;AACzB,WAAAF,EAAM,IAAIK,GAAK,EAAE,WAAWC,GAAK,OAAOE,GAAQ,GAE5CT,KAAWC,EAAM,OAAOD,KAC1BC,EAAM,OAAOA,EAAM,KAAA,EAAO,KAAA,EAAO,KAAM,GAGlCQ;AAAA,EACT;AACF;"}
1
+ {"version":3,"file":"memo.js","sources":["../../src/function/memo.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\nimport type { Fn } from '../types';\n\ntype MemoizeOptions<T extends Fn> = {\n ttl?: number; // Time-to-live in milliseconds\n maxSize?: number; // Maximum number of items in cache\n resolver?: (...args: Parameters<T>) => string; // Custom key generator\n};\n\ntype CacheEntry<T extends Fn> = {\n value: ReturnType<T>;\n timestamp: number;\n};\n\n/**\n * Creates a function that memorizes the result of the provided function.\n * Supports expiration (TTL) and limited cache size (LRU).\n *\n * @example\n * ```ts\n * const add = (x, y) => x + y;\n * const memoizedAdd = memo(add, { ttl: 5000, maxSize: 10 });\n *\n * memoizedAdd(1, 2); // 3 (caches the result)\n * memoizedAdd(1, 2); // 3 (from cache)\n * ```\n *\n * @param fn - The function to memorize.\n * @param options - Memoization options.\n * @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).\n * @param [options.maxSize] - (optional) maximum cache size (LRU eviction).\n * @param [options.resolver] - (optional) custom function to resolve the cache key.\n *\n * @returns A new function that memorizes the input function.\n */\nexport function memo<T extends Fn>(\n fn: T,\n { ttl, maxSize, resolver }: MemoizeOptions<T> = {},\n): (...args: Parameters<T>) => ReturnType<T> {\n const cache = new Map<string, CacheEntry<T>>();\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: -\n const keyGen = (args: Parameters<T>): string => {\n if (resolver) return resolver(...args);\n if (args.length === 0) return '__empty__';\n if (args.length === 1) {\n const arg = args[0];\n const argType = typeof arg;\n if (argType === 'string' || argType === 'number' || argType === 'boolean') {\n return `${argType}:${arg}`;\n }\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n }\n return JSON.stringify(args);\n };\n\n return (...args: Parameters<T>): ReturnType<T> => {\n const key = keyGen(args);\n const now = Date.now();\n const cached = cache.get(key);\n\n if (cached && (!ttl || now - cached.timestamp < ttl)) {\n cache.delete(key);\n cache.set(key, cached); // Move to end (most recently used)\n return cached.value;\n }\n\n const result = fn(...args);\n cache.set(key, { timestamp: now, value: result });\n\n if (maxSize && cache.size > maxSize) {\n cache.delete(cache.keys().next().value!); // Remove least recently used\n }\n\n return result;\n };\n}\n"],"names":["memo","fn","ttl","maxSize","resolver","cache","keyGen","args","arg","argType","key","now","cached","result"],"mappings":"AAmCO,SAASA,EACdC,GACA,EAAE,KAAAC,GAAK,SAAAC,GAAS,UAAAC,EAAA,IAAgC,IACL;AAC3C,QAAMC,wBAAY,IAAA,GAGZC,IAAS,CAACC,MAAgC;AAC9C,QAAIH,EAAU,QAAOA,EAAS,GAAGG,CAAI;AACrC,QAAIA,EAAK,WAAW,EAAG,QAAO;AAC9B,QAAIA,EAAK,WAAW,GAAG;AACrB,YAAMC,IAAMD,EAAK,CAAC,GACZE,IAAU,OAAOD;AACvB,UAAIC,MAAY,YAAYA,MAAY,YAAYA,MAAY;AAC9D,eAAO,GAAGA,CAAO,IAAID,CAAG;AAE1B,UAAIA,MAAQ,KAAM,QAAO;AACzB,UAAIA,MAAQ,OAAW,QAAO;AAAA,IAChC;AACA,WAAO,KAAK,UAAUD,CAAI;AAAA,EAC5B;AAEA,SAAO,IAAIA,MAAuC;AAChD,UAAMG,IAAMJ,EAAOC,CAAI,GACjBI,IAAM,KAAK,IAAA,GACXC,IAASP,EAAM,IAAIK,CAAG;AAE5B,QAAIE,MAAW,CAACV,KAAOS,IAAMC,EAAO,YAAYV;AAC9C,aAAAG,EAAM,OAAOK,CAAG,GAChBL,EAAM,IAAIK,GAAKE,CAAM,GACdA,EAAO;AAGhB,UAAMC,IAASZ,EAAG,GAAGM,CAAI;AACzB,WAAAF,EAAM,IAAIK,GAAK,EAAE,WAAWC,GAAK,OAAOE,GAAQ,GAE5CV,KAAWE,EAAM,OAAOF,KAC1BE,EAAM,OAAOA,EAAM,KAAA,EAAO,KAAA,EAAO,KAAM,GAGlCQ;AAAA,EACT;AACF;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../logit/dist/logit.cjs"),c=require("./sleep.cjs");async function u(n,{times:e=3,delay:i=250,backoff:y=1,signal:l}={}){let t=i;for(let r=1;r<=e;r++){if(l?.aborted)throw a.Logit.warn(`retry() -> Aborted after ${r-1} attempts`),new Error("Retry aborted");try{return await n()}catch(o){if(r===e)throw o;a.Logit.warn(`retry() -> ${o}, attempt ${r}/${e}, retrying in ${t}ms`),t>0&&await c.sleep(t),t*=y}}throw new Error("Retry failed unexpectedly")}exports.retry=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../logit/dist/logit.cjs"),u=require("./sleep.cjs");async function c(i,{times:e=3,delay:y=250,backoff:o=1,signal:l}={}){let t=y;for(let r=1;r<=e;r++){if(l?.aborted)throw a.Logit.warn(`retry() -> Aborted after ${r-1} attempts`),new Error("Retry aborted");try{return await i()}catch(n){if(r===e)throw n;a.Logit.warn(`retry() -> ${n}, attempt ${r}/${e}, retrying in ${t}ms`),t>0&&await u.sleep(t),t=typeof o=="function"?o(r,t):t*o}}throw new Error("Retry failed unexpectedly")}exports.retry=c;
2
2
  //# sourceMappingURL=retry.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"retry.cjs","sources":["../../src/function/retry.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { sleep } from './sleep';\n\n/**\n * Retries an asynchronous function a specified number of times with delay and optional exponential backoff.\n *\n * @example\n * ```ts\n * retry(() => fetchData(), { times: 3, delay: 1000, backoff: 2, signal: abortSignal })\n * .then(result => console.log(result))\n * .catch(error => console.error(error));\n * ```\n *\n * @param fn - The asynchronous function to retry.\n * @param options - (optional) Options for retrying the function.\n * @param [options.times=3] - The number of retry attempts.\n * @param [options.delay=250] - The delay in milliseconds between retries.\n * @param [options.backoff=1] - Exponential backoff factor (default: 1 → no backoff).\n * @param [options.signal] - `AbortSignal` to allow canceling retries.\n *\n * @returns The result of the asynchronous function.\n */\nexport async function retry<T>(\n fn: () => Promise<T>,\n {\n times = 3,\n delay = 250,\n backoff = 1,\n signal,\n }: {\n times?: number;\n delay?: number;\n backoff?: number;\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n let currentDelay = delay;\n\n for (let attempt = 1; attempt <= times; attempt++) {\n if (signal?.aborted) {\n Logit.warn(`retry() -> Aborted after ${attempt - 1} attempts`);\n throw new Error('Retry aborted');\n }\n\n try {\n return await fn();\n } catch (err) {\n if (attempt === times) throw err;\n\n Logit.warn(`retry() -> ${err}, attempt ${attempt}/${times}, retrying in ${currentDelay}ms`);\n if (currentDelay > 0) await sleep(currentDelay);\n currentDelay *= backoff;\n }\n }\n\n throw new Error('Retry failed unexpectedly');\n}\n"],"names":["retry","fn","times","delay","backoff","signal","currentDelay","attempt","Logit","err","sleep"],"mappings":"oJAsBA,eAAsBA,EACpBC,EACA,CACE,MAAAC,EAAQ,EACR,MAAAC,EAAQ,IACR,QAAAC,EAAU,EACV,OAAAC,CACF,EAKI,GACQ,CACZ,IAAIC,EAAeH,EAEnB,QAASI,EAAU,EAAGA,GAAWL,EAAOK,IAAW,CACjD,GAAIF,GAAQ,QACVG,MAAAA,EAAAA,MAAM,KAAK,4BAA4BD,EAAU,CAAC,WAAW,EACvD,IAAI,MAAM,eAAe,EAGjC,GAAI,CACF,OAAO,MAAMN,EAAA,CACf,OAASQ,EAAK,CACZ,GAAIF,IAAYL,EAAO,MAAMO,EAE7BD,EAAAA,MAAM,KAAK,cAAcC,CAAG,aAAaF,CAAO,IAAIL,CAAK,iBAAiBI,CAAY,IAAI,EACtFA,EAAe,GAAG,MAAMI,EAAAA,MAAMJ,CAAY,EAC9CA,GAAgBF,CAClB,CACF,CAEA,MAAM,IAAI,MAAM,2BAA2B,CAC7C"}
1
+ {"version":3,"file":"retry.cjs","sources":["../../src/function/retry.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { sleep } from './sleep';\n\n/**\n * Retries an asynchronous function a specified number of times with delay and optional exponential backoff.\n *\n * @example\n * ```ts\n * retry(() => fetchData(), { times: 3, delay: 1000, backoff: 2, signal: abortSignal })\n * .then(result => console.log(result))\n * .catch(error => console.error(error));\n * ```\n *\n * @param fn - The asynchronous function to retry.\n * @param options - (optional) Options for retrying the function.\n * @param [options.times=3] - The number of retry attempts.\n * @param [options.delay=250] - The delay in milliseconds between retries.\n * @param [options.backoff=1] - Exponential backoff factor (default: 1 → no backoff).\n * @param [options.signal] - `AbortSignal` to allow canceling retries.\n *\n * @returns The result of the asynchronous function.\n */\nexport async function retry<T>(\n fn: () => Promise<T>,\n {\n times = 3,\n delay = 250,\n backoff = 1,\n signal,\n }: {\n times?: number;\n delay?: number;\n backoff?: number | ((attempt: number, delay: number) => number);\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n let currentDelay = delay;\n\n for (let attempt = 1; attempt <= times; attempt++) {\n if (signal?.aborted) {\n Logit.warn(`retry() -> Aborted after ${attempt - 1} attempts`);\n throw new Error('Retry aborted');\n }\n\n try {\n return await fn();\n } catch (err) {\n if (attempt === times) throw err;\n\n Logit.warn(`retry() -> ${err}, attempt ${attempt}/${times}, retrying in ${currentDelay}ms`);\n if (currentDelay > 0) await sleep(currentDelay);\n\n currentDelay = typeof backoff === 'function' ? backoff(attempt, currentDelay) : currentDelay * backoff;\n }\n }\n\n throw new Error('Retry failed unexpectedly');\n}\n"],"names":["retry","fn","times","delay","backoff","signal","currentDelay","attempt","Logit","err","sleep"],"mappings":"oJAsBA,eAAsBA,EACpBC,EACA,CACE,MAAAC,EAAQ,EACR,MAAAC,EAAQ,IACR,QAAAC,EAAU,EACV,OAAAC,CACF,EAKI,GACQ,CACZ,IAAIC,EAAeH,EAEnB,QAASI,EAAU,EAAGA,GAAWL,EAAOK,IAAW,CACjD,GAAIF,GAAQ,QACVG,MAAAA,EAAAA,MAAM,KAAK,4BAA4BD,EAAU,CAAC,WAAW,EACvD,IAAI,MAAM,eAAe,EAGjC,GAAI,CACF,OAAO,MAAMN,EAAA,CACf,OAASQ,EAAK,CACZ,GAAIF,IAAYL,EAAO,MAAMO,EAE7BD,EAAAA,MAAM,KAAK,cAAcC,CAAG,aAAaF,CAAO,IAAIL,CAAK,iBAAiBI,CAAY,IAAI,EACtFA,EAAe,GAAG,MAAMI,EAAAA,MAAMJ,CAAY,EAE9CA,EAAe,OAAOF,GAAY,WAAaA,EAAQG,EAASD,CAAY,EAAIA,EAAeF,CACjG,CACF,CAEA,MAAM,IAAI,MAAM,2BAA2B,CAC7C"}
@@ -1,25 +1,25 @@
1
- import { Logit as o } from "../logit/dist/logit.js";
1
+ import { Logit as n } from "../logit/dist/logit.js";
2
2
  import { sleep as w } from "./sleep.js";
3
- async function l(n, {
3
+ async function m(y, {
4
4
  times: e = 3,
5
- delay: y = 250,
6
- backoff: i = 1,
7
- signal: f
5
+ delay: i = 250,
6
+ backoff: o = 1,
7
+ signal: p
8
8
  } = {}) {
9
- let t = y;
10
- for (let r = 1; r <= e; r++) {
11
- if (f?.aborted)
12
- throw o.warn(`retry() -> Aborted after ${r - 1} attempts`), new Error("Retry aborted");
9
+ let r = i;
10
+ for (let t = 1; t <= e; t++) {
11
+ if (p?.aborted)
12
+ throw n.warn(`retry() -> Aborted after ${t - 1} attempts`), new Error("Retry aborted");
13
13
  try {
14
- return await n();
14
+ return await y();
15
15
  } catch (a) {
16
- if (r === e) throw a;
17
- o.warn(`retry() -> ${a}, attempt ${r}/${e}, retrying in ${t}ms`), t > 0 && await w(t), t *= i;
16
+ if (t === e) throw a;
17
+ n.warn(`retry() -> ${a}, attempt ${t}/${e}, retrying in ${r}ms`), r > 0 && await w(r), r = typeof o == "function" ? o(t, r) : r * o;
18
18
  }
19
19
  }
20
20
  throw new Error("Retry failed unexpectedly");
21
21
  }
22
22
  export {
23
- l as retry
23
+ m as retry
24
24
  };
25
25
  //# sourceMappingURL=retry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"retry.js","sources":["../../src/function/retry.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { sleep } from './sleep';\n\n/**\n * Retries an asynchronous function a specified number of times with delay and optional exponential backoff.\n *\n * @example\n * ```ts\n * retry(() => fetchData(), { times: 3, delay: 1000, backoff: 2, signal: abortSignal })\n * .then(result => console.log(result))\n * .catch(error => console.error(error));\n * ```\n *\n * @param fn - The asynchronous function to retry.\n * @param options - (optional) Options for retrying the function.\n * @param [options.times=3] - The number of retry attempts.\n * @param [options.delay=250] - The delay in milliseconds between retries.\n * @param [options.backoff=1] - Exponential backoff factor (default: 1 → no backoff).\n * @param [options.signal] - `AbortSignal` to allow canceling retries.\n *\n * @returns The result of the asynchronous function.\n */\nexport async function retry<T>(\n fn: () => Promise<T>,\n {\n times = 3,\n delay = 250,\n backoff = 1,\n signal,\n }: {\n times?: number;\n delay?: number;\n backoff?: number;\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n let currentDelay = delay;\n\n for (let attempt = 1; attempt <= times; attempt++) {\n if (signal?.aborted) {\n Logit.warn(`retry() -> Aborted after ${attempt - 1} attempts`);\n throw new Error('Retry aborted');\n }\n\n try {\n return await fn();\n } catch (err) {\n if (attempt === times) throw err;\n\n Logit.warn(`retry() -> ${err}, attempt ${attempt}/${times}, retrying in ${currentDelay}ms`);\n if (currentDelay > 0) await sleep(currentDelay);\n currentDelay *= backoff;\n }\n }\n\n throw new Error('Retry failed unexpectedly');\n}\n"],"names":["retry","fn","times","delay","backoff","signal","currentDelay","attempt","Logit","err","sleep"],"mappings":";;AAsBA,eAAsBA,EACpBC,GACA;AAAA,EACE,OAAAC,IAAQ;AAAA,EACR,OAAAC,IAAQ;AAAA,EACR,SAAAC,IAAU;AAAA,EACV,QAAAC;AACF,IAKI,IACQ;AACZ,MAAIC,IAAeH;AAEnB,WAASI,IAAU,GAAGA,KAAWL,GAAOK,KAAW;AACjD,QAAIF,GAAQ;AACVG,YAAAA,EAAM,KAAK,4BAA4BD,IAAU,CAAC,WAAW,GACvD,IAAI,MAAM,eAAe;AAGjC,QAAI;AACF,aAAO,MAAMN,EAAA;AAAA,IACf,SAASQ,GAAK;AACZ,UAAIF,MAAYL,EAAO,OAAMO;AAE7BD,MAAAA,EAAM,KAAK,cAAcC,CAAG,aAAaF,CAAO,IAAIL,CAAK,iBAAiBI,CAAY,IAAI,GACtFA,IAAe,KAAG,MAAMI,EAAMJ,CAAY,GAC9CA,KAAgBF;AAAA,IAClB;AAAA,EACF;AAEA,QAAM,IAAI,MAAM,2BAA2B;AAC7C;"}
1
+ {"version":3,"file":"retry.js","sources":["../../src/function/retry.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { sleep } from './sleep';\n\n/**\n * Retries an asynchronous function a specified number of times with delay and optional exponential backoff.\n *\n * @example\n * ```ts\n * retry(() => fetchData(), { times: 3, delay: 1000, backoff: 2, signal: abortSignal })\n * .then(result => console.log(result))\n * .catch(error => console.error(error));\n * ```\n *\n * @param fn - The asynchronous function to retry.\n * @param options - (optional) Options for retrying the function.\n * @param [options.times=3] - The number of retry attempts.\n * @param [options.delay=250] - The delay in milliseconds between retries.\n * @param [options.backoff=1] - Exponential backoff factor (default: 1 → no backoff).\n * @param [options.signal] - `AbortSignal` to allow canceling retries.\n *\n * @returns The result of the asynchronous function.\n */\nexport async function retry<T>(\n fn: () => Promise<T>,\n {\n times = 3,\n delay = 250,\n backoff = 1,\n signal,\n }: {\n times?: number;\n delay?: number;\n backoff?: number | ((attempt: number, delay: number) => number);\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n let currentDelay = delay;\n\n for (let attempt = 1; attempt <= times; attempt++) {\n if (signal?.aborted) {\n Logit.warn(`retry() -> Aborted after ${attempt - 1} attempts`);\n throw new Error('Retry aborted');\n }\n\n try {\n return await fn();\n } catch (err) {\n if (attempt === times) throw err;\n\n Logit.warn(`retry() -> ${err}, attempt ${attempt}/${times}, retrying in ${currentDelay}ms`);\n if (currentDelay > 0) await sleep(currentDelay);\n\n currentDelay = typeof backoff === 'function' ? backoff(attempt, currentDelay) : currentDelay * backoff;\n }\n }\n\n throw new Error('Retry failed unexpectedly');\n}\n"],"names":["retry","fn","times","delay","backoff","signal","currentDelay","attempt","Logit","err","sleep"],"mappings":";;AAsBA,eAAsBA,EACpBC,GACA;AAAA,EACE,OAAAC,IAAQ;AAAA,EACR,OAAAC,IAAQ;AAAA,EACR,SAAAC,IAAU;AAAA,EACV,QAAAC;AACF,IAKI,IACQ;AACZ,MAAIC,IAAeH;AAEnB,WAASI,IAAU,GAAGA,KAAWL,GAAOK,KAAW;AACjD,QAAIF,GAAQ;AACVG,YAAAA,EAAM,KAAK,4BAA4BD,IAAU,CAAC,WAAW,GACvD,IAAI,MAAM,eAAe;AAGjC,QAAI;AACF,aAAO,MAAMN,EAAA;AAAA,IACf,SAASQ,GAAK;AACZ,UAAIF,MAAYL,EAAO,OAAMO;AAE7BD,MAAAA,EAAM,KAAK,cAAcC,CAAG,aAAaF,CAAO,IAAIL,CAAK,iBAAiBI,CAAY,IAAI,GACtFA,IAAe,KAAG,MAAMI,EAAMJ,CAAY,GAE9CA,IAAe,OAAOF,KAAY,aAAaA,EAAQG,GAASD,CAAY,IAAIA,IAAeF;AAAA,IACjG;AAAA,EACF;AAEA,QAAM,IAAI,MAAM,2BAA2B;AAC7C;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function n(e){return new Promise(t=>setTimeout(t,e))}exports.sleep=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./assert.cjs");async function s(e){return n.assert(typeof e=="number"&&e>=0&&Number.isFinite(e),"Timeout must be a non-negative finite number",{args:{timeout:e},type:TypeError}),new Promise(r=>setTimeout(r,e))}exports.sleep=s;
2
2
  //# sourceMappingURL=sleep.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"sleep.cjs","sources":["../../src/function/sleep.ts"],"sourcesContent":["/**\n * Creates a Promise that resolves after a specified amount of time.\n *\n * @example\n * ```ts\n * sleep(1000).then(() => console.log('Hello, world!')); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param timeout - The number of milliseconds to wait before resolving the Promise.\n *\n * @returns A Promise that resolves after the specified time.\n */\nexport async function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, timeout));\n}\n"],"names":["sleep","timeout","resolve"],"mappings":"gFAYA,eAAsBA,EAAMC,EAAgC,CAC1D,OAAO,IAAI,QAASC,GAAY,WAAWA,EAASD,CAAO,CAAC,CAC9D"}
1
+ {"version":3,"file":"sleep.cjs","sources":["../../src/function/sleep.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Creates a Promise that resolves after a specified amount of time.\n *\n * @example\n * ```ts\n * sleep(1000).then(() => console.log('Hello, world!')); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param timeout - The number of milliseconds to wait before resolving the Promise.\n *\n * @returns A Promise that resolves after the specified time.\n *\n * @throws {TypeError} If timeout is not a non-negative number.\n */\nexport async function sleep(timeout: number): Promise<void> {\n assert(\n typeof timeout === 'number' && timeout >= 0 && Number.isFinite(timeout),\n 'Timeout must be a non-negative finite number',\n { args: { timeout }, type: TypeError },\n );\n return new Promise((resolve) => setTimeout(resolve, timeout));\n}\n"],"names":["sleep","timeout","assert","resolve"],"mappings":"gHAgBA,eAAsBA,EAAMC,EAAgC,CAC1DC,OAAAA,EAAAA,OACE,OAAOD,GAAY,UAAYA,GAAW,GAAK,OAAO,SAASA,CAAO,EACtE,+CACA,CAAE,KAAM,CAAE,QAAAA,CAAA,EAAW,KAAM,SAAA,CAAU,EAEhC,IAAI,QAASE,GAAY,WAAWA,EAASF,CAAO,CAAC,CAC9D"}
@@ -1,7 +1,12 @@
1
- async function t(e) {
2
- return new Promise((n) => setTimeout(n, e));
1
+ import { assert as n } from "./assert.js";
2
+ async function i(e) {
3
+ return n(
4
+ typeof e == "number" && e >= 0 && Number.isFinite(e),
5
+ "Timeout must be a non-negative finite number",
6
+ { args: { timeout: e }, type: TypeError }
7
+ ), new Promise((r) => setTimeout(r, e));
3
8
  }
4
9
  export {
5
- t as sleep
10
+ i as sleep
6
11
  };
7
12
  //# sourceMappingURL=sleep.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sleep.js","sources":["../../src/function/sleep.ts"],"sourcesContent":["/**\n * Creates a Promise that resolves after a specified amount of time.\n *\n * @example\n * ```ts\n * sleep(1000).then(() => console.log('Hello, world!')); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param timeout - The number of milliseconds to wait before resolving the Promise.\n *\n * @returns A Promise that resolves after the specified time.\n */\nexport async function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, timeout));\n}\n"],"names":["sleep","timeout","resolve"],"mappings":"AAYA,eAAsBA,EAAMC,GAAgC;AAC1D,SAAO,IAAI,QAAQ,CAACC,MAAY,WAAWA,GAASD,CAAO,CAAC;AAC9D;"}
1
+ {"version":3,"file":"sleep.js","sources":["../../src/function/sleep.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Creates a Promise that resolves after a specified amount of time.\n *\n * @example\n * ```ts\n * sleep(1000).then(() => console.log('Hello, world!')); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param timeout - The number of milliseconds to wait before resolving the Promise.\n *\n * @returns A Promise that resolves after the specified time.\n *\n * @throws {TypeError} If timeout is not a non-negative number.\n */\nexport async function sleep(timeout: number): Promise<void> {\n assert(\n typeof timeout === 'number' && timeout >= 0 && Number.isFinite(timeout),\n 'Timeout must be a non-negative finite number',\n { args: { timeout }, type: TypeError },\n );\n return new Promise((resolve) => setTimeout(resolve, timeout));\n}\n"],"names":["sleep","timeout","assert","resolve"],"mappings":";AAgBA,eAAsBA,EAAMC,GAAgC;AAC1D,SAAAC;AAAA,IACE,OAAOD,KAAY,YAAYA,KAAW,KAAK,OAAO,SAASA,CAAO;AAAA,IACtE;AAAA,IACA,EAAE,MAAM,EAAE,SAAAA,EAAA,GAAW,MAAM,UAAA;AAAA,EAAU,GAEhC,IAAI,QAAQ,CAACE,MAAY,WAAWA,GAASF,CAAO,CAAC;AAC9D;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(o,n=700){let t=0;return(...r)=>{const e=Date.now();e-t>=n&&(t=e,o(...r))}}exports.throttle=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./assert.cjs");function b(u,o=700,f={leading:!0,trailing:!0}){p.assert(typeof u=="function","First argument must be a function",{args:{fn:u},type:TypeError}),p.assert(typeof o=="number"&&o>=0,"Delay must be a non-negative number",{args:{delay:o},type:TypeError});const T=f.leading??!0,y=f.trailing??!1;let n,i=0,e,s,m;const c=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},g=t=>{if(i=t,c(),!e)return;const r=e,l=s;return e=void 0,s=void 0,m=u.apply(l,r),m},d=t=>o-(t-i),v=()=>{const t=Date.now();e&&d(t)<=0?g(t):e?n=setTimeout(v,d(t)):c()},a=function(...t){const r=Date.now();i===0&&!T&&(i=r),e=t,s=this;const l=d(r);l<=0?g(r):y&&!n&&(n=setTimeout(v,l))};return a.cancel=()=>{c(),e=void 0,s=void 0,i=0},a.flush=()=>{if(!e)return;const t=Date.now();return g(t)},a.pending=()=>e!==void 0||n!==void 0,a}exports.throttle=b;
2
2
  //# sourceMappingURL=throttle.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"throttle.cjs","sources":["../../src/function/throttle.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Creates a throttled function that only invokes the provided function at most once per every specified milliseconds.\n *\n * @example\n * ```ts\n * const log = () => console.log('Hello, world!');\n * const throttledLog = throttle(log, 1000);\n *\n * throttledLog(); // logs 'Hello, world!' immediately\n * throttledLog(); // does nothing because less than 1 second has passed since the last invocation\n * setTimeout(throttledLog, 1000); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param fn - The function to throttle.\n * @param [delay=700] - The number of milliseconds to wait before invoking the function again.\n *\n * @returns A new function that throttles the input function.\n */\nexport function throttle<T extends Fn>(fn: T, delay = 700): (...args: Parameters<T>) => void {\n let elapsed = 0;\n\n return (...args: Parameters<T>) => {\n const now = Date.now();\n\n if (now - elapsed >= delay) {\n elapsed = now;\n fn(...args);\n }\n };\n}\n"],"names":["throttle","fn","delay","elapsed","args","now"],"mappings":"gFAoBO,SAASA,EAAuBC,EAAOC,EAAQ,IAAuC,CAC3F,IAAIC,EAAU,EAEd,MAAO,IAAIC,IAAwB,CACjC,MAAMC,EAAM,KAAK,IAAA,EAEbA,EAAMF,GAAWD,IACnBC,EAAUE,EACVJ,EAAG,GAAGG,CAAI,EAEd,CACF"}
1
+ {"version":3,"file":"throttle.cjs","sources":["../../src/function/throttle.ts"],"sourcesContent":["import type { Fn } from '../types';\nimport { assert } from './assert';\n\nexport type ThrottleOptions = {\n leading?: boolean; // invoke at the start of the window\n trailing?: boolean; // invoke at the end with the last args\n};\n\nexport type Throttled<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {\n cancel(): void;\n flush(): ReturnType<T> | undefined;\n pending(): boolean; // whether there's a pending call that flush() would execute\n};\n\n/**\n * Throttles a function. By default, leading and trailing are both true (lodash-like behavior).\n * The function is invoked at the leading edge and trailing edge of the throttle period.\n *\n * Example:\n * const fn = () => ...\n * const t = throttle(fn, 700);\n * const leadingOnly = throttle(fn, 700, { trailing: false });\n */\nexport function throttle<T extends Fn>(\n fn: T,\n delay = 700,\n options: ThrottleOptions = { leading: true, trailing: true },\n): Throttled<T> {\n assert(typeof fn === 'function', 'First argument must be a function', {\n args: { fn },\n type: TypeError,\n });\n assert(typeof delay === 'number' && delay >= 0, 'Delay must be a non-negative number', {\n args: { delay },\n type: TypeError,\n });\n\n const leading = options.leading ?? true;\n const trailing = options.trailing ?? false;\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n let lastInvokeTime = 0;\n let lastArgs: Parameters<T> | undefined;\n let lastThis: ThisParameterType<T> | undefined;\n let lastResult: ReturnType<T> | undefined;\n\n const clearTimer = () => {\n if (timer !== undefined) {\n clearTimeout(timer);\n timer = undefined;\n }\n };\n\n const invoke = (now: number) => {\n lastInvokeTime = now;\n clearTimer();\n if (!lastArgs) return undefined;\n const args = lastArgs;\n const ctx = lastThis as ThisParameterType<T>;\n lastArgs = undefined;\n lastThis = undefined;\n // biome-ignore lint/suspicious/noExplicitAny: -\n lastResult = fn.apply(ctx as any, args);\n return lastResult;\n };\n\n const remaining = (now: number) => delay - (now - lastInvokeTime);\n\n const timerExpired = () => {\n const now = Date.now();\n if (lastArgs && remaining(now) <= 0) {\n // trailing edge invoke\n invoke(now);\n } else if (lastArgs) {\n // reschedule until a window elapses\n timer = setTimeout(timerExpired, remaining(now));\n } else {\n clearTimer();\n }\n };\n\n const throttled = function (this: ThisParameterType<T>, ...args: Parameters<T>) {\n const now = Date.now();\n if (lastInvokeTime === 0 && !leading) {\n // If leading is false, start the window now but don't invoke immediately\n lastInvokeTime = now;\n }\n\n lastArgs = args;\n lastThis = this;\n\n const rem = remaining(now);\n\n if (rem <= 0) {\n // Window elapsed: invoke now\n invoke(now);\n } else if (trailing && !timer) {\n // Schedule trailing call if not already scheduled\n timer = setTimeout(timerExpired, rem);\n }\n } as Throttled<T>;\n\n throttled.cancel = () => {\n clearTimer();\n lastArgs = undefined;\n lastThis = undefined;\n lastInvokeTime = 0;\n };\n\n throttled.flush = () => {\n if (!lastArgs) return undefined;\n const now = Date.now();\n return invoke(now) as ReturnType<T> | undefined;\n };\n\n // Pending if a trailing call is scheduled OR there are queued args.\n throttled.pending = () => lastArgs !== undefined || timer !== undefined;\n\n return throttled;\n}\n"],"names":["throttle","fn","delay","options","assert","leading","trailing","timer","lastInvokeTime","lastArgs","lastThis","lastResult","clearTimer","invoke","now","args","ctx","remaining","timerExpired","throttled","rem"],"mappings":"gHAuBO,SAASA,EACdC,EACAC,EAAQ,IACRC,EAA2B,CAAE,QAAS,GAAM,SAAU,IACxC,CACdC,EAAAA,OAAO,OAAOH,GAAO,WAAY,oCAAqC,CACpE,KAAM,CAAE,GAAAA,CAAA,EACR,KAAM,SAAA,CACP,EACDG,EAAAA,OAAO,OAAOF,GAAU,UAAYA,GAAS,EAAG,sCAAuC,CACrF,KAAM,CAAE,MAAAA,CAAA,EACR,KAAM,SAAA,CACP,EAED,MAAMG,EAAUF,EAAQ,SAAW,GAC7BG,EAAWH,EAAQ,UAAY,GAErC,IAAII,EACAC,EAAiB,EACjBC,EACAC,EACAC,EAEJ,MAAMC,EAAa,IAAM,CACnBL,IAAU,SACZ,aAAaA,CAAK,EAClBA,EAAQ,OAEZ,EAEMM,EAAUC,GAAgB,CAG9B,GAFAN,EAAiBM,EACjBF,EAAA,EACI,CAACH,EAAU,OACf,MAAMM,EAAON,EACPO,EAAMN,EACZ,OAAAD,EAAW,OACXC,EAAW,OAEXC,EAAaV,EAAG,MAAMe,EAAYD,CAAI,EAC/BJ,CACT,EAEMM,EAAaH,GAAgBZ,GAASY,EAAMN,GAE5CU,EAAe,IAAM,CACzB,MAAMJ,EAAM,KAAK,IAAA,EACbL,GAAYQ,EAAUH,CAAG,GAAK,EAEhCD,EAAOC,CAAG,EACDL,EAETF,EAAQ,WAAWW,EAAcD,EAAUH,CAAG,CAAC,EAE/CF,EAAA,CAEJ,EAEMO,EAAY,YAAyCJ,EAAqB,CAC9E,MAAMD,EAAM,KAAK,IAAA,EACbN,IAAmB,GAAK,CAACH,IAE3BG,EAAiBM,GAGnBL,EAAWM,EACXL,EAAW,KAEX,MAAMU,EAAMH,EAAUH,CAAG,EAErBM,GAAO,EAETP,EAAOC,CAAG,EACDR,GAAY,CAACC,IAEtBA,EAAQ,WAAWW,EAAcE,CAAG,EAExC,EAEA,OAAAD,EAAU,OAAS,IAAM,CACvBP,EAAA,EACAH,EAAW,OACXC,EAAW,OACXF,EAAiB,CACnB,EAEAW,EAAU,MAAQ,IAAM,CACtB,GAAI,CAACV,EAAU,OACf,MAAMK,EAAM,KAAK,IAAA,EACjB,OAAOD,EAAOC,CAAG,CACnB,EAGAK,EAAU,QAAU,IAAMV,IAAa,QAAaF,IAAU,OAEvDY,CACT"}
@@ -1,11 +1,38 @@
1
- function l(n, o = 700) {
2
- let t = 0;
3
- return (...r) => {
4
- const e = Date.now();
5
- e - t >= o && (t = e, n(...r));
1
+ import { assert as p } from "./assert.js";
2
+ function y(c, r = 700, g = { leading: !0, trailing: !0 }) {
3
+ p(typeof c == "function", "First argument must be a function", {
4
+ args: { fn: c },
5
+ type: TypeError
6
+ }), p(typeof r == "number" && r >= 0, "Delay must be a non-negative number", {
7
+ args: { delay: r },
8
+ type: TypeError
9
+ });
10
+ const T = g.leading ?? !0, w = g.trailing ?? !1;
11
+ let n, i = 0, e, s, d;
12
+ const u = () => {
13
+ n !== void 0 && (clearTimeout(n), n = void 0);
14
+ }, m = (t) => {
15
+ if (i = t, u(), !e) return;
16
+ const o = e, l = s;
17
+ return e = void 0, s = void 0, d = c.apply(l, o), d;
18
+ }, f = (t) => r - (t - i), v = () => {
19
+ const t = Date.now();
20
+ e && f(t) <= 0 ? m(t) : e ? n = setTimeout(v, f(t)) : u();
21
+ }, a = function(...t) {
22
+ const o = Date.now();
23
+ i === 0 && !T && (i = o), e = t, s = this;
24
+ const l = f(o);
25
+ l <= 0 ? m(o) : w && !n && (n = setTimeout(v, l));
6
26
  };
27
+ return a.cancel = () => {
28
+ u(), e = void 0, s = void 0, i = 0;
29
+ }, a.flush = () => {
30
+ if (!e) return;
31
+ const t = Date.now();
32
+ return m(t);
33
+ }, a.pending = () => e !== void 0 || n !== void 0, a;
7
34
  }
8
35
  export {
9
- l as throttle
36
+ y as throttle
10
37
  };
11
38
  //# sourceMappingURL=throttle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"throttle.js","sources":["../../src/function/throttle.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Creates a throttled function that only invokes the provided function at most once per every specified milliseconds.\n *\n * @example\n * ```ts\n * const log = () => console.log('Hello, world!');\n * const throttledLog = throttle(log, 1000);\n *\n * throttledLog(); // logs 'Hello, world!' immediately\n * throttledLog(); // does nothing because less than 1 second has passed since the last invocation\n * setTimeout(throttledLog, 1000); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param fn - The function to throttle.\n * @param [delay=700] - The number of milliseconds to wait before invoking the function again.\n *\n * @returns A new function that throttles the input function.\n */\nexport function throttle<T extends Fn>(fn: T, delay = 700): (...args: Parameters<T>) => void {\n let elapsed = 0;\n\n return (...args: Parameters<T>) => {\n const now = Date.now();\n\n if (now - elapsed >= delay) {\n elapsed = now;\n fn(...args);\n }\n };\n}\n"],"names":["throttle","fn","delay","elapsed","args","now"],"mappings":"AAoBO,SAASA,EAAuBC,GAAOC,IAAQ,KAAuC;AAC3F,MAAIC,IAAU;AAEd,SAAO,IAAIC,MAAwB;AACjC,UAAMC,IAAM,KAAK,IAAA;AAEjB,IAAIA,IAAMF,KAAWD,MACnBC,IAAUE,GACVJ,EAAG,GAAGG,CAAI;AAAA,EAEd;AACF;"}
1
+ {"version":3,"file":"throttle.js","sources":["../../src/function/throttle.ts"],"sourcesContent":["import type { Fn } from '../types';\nimport { assert } from './assert';\n\nexport type ThrottleOptions = {\n leading?: boolean; // invoke at the start of the window\n trailing?: boolean; // invoke at the end with the last args\n};\n\nexport type Throttled<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {\n cancel(): void;\n flush(): ReturnType<T> | undefined;\n pending(): boolean; // whether there's a pending call that flush() would execute\n};\n\n/**\n * Throttles a function. By default, leading and trailing are both true (lodash-like behavior).\n * The function is invoked at the leading edge and trailing edge of the throttle period.\n *\n * Example:\n * const fn = () => ...\n * const t = throttle(fn, 700);\n * const leadingOnly = throttle(fn, 700, { trailing: false });\n */\nexport function throttle<T extends Fn>(\n fn: T,\n delay = 700,\n options: ThrottleOptions = { leading: true, trailing: true },\n): Throttled<T> {\n assert(typeof fn === 'function', 'First argument must be a function', {\n args: { fn },\n type: TypeError,\n });\n assert(typeof delay === 'number' && delay >= 0, 'Delay must be a non-negative number', {\n args: { delay },\n type: TypeError,\n });\n\n const leading = options.leading ?? true;\n const trailing = options.trailing ?? false;\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n let lastInvokeTime = 0;\n let lastArgs: Parameters<T> | undefined;\n let lastThis: ThisParameterType<T> | undefined;\n let lastResult: ReturnType<T> | undefined;\n\n const clearTimer = () => {\n if (timer !== undefined) {\n clearTimeout(timer);\n timer = undefined;\n }\n };\n\n const invoke = (now: number) => {\n lastInvokeTime = now;\n clearTimer();\n if (!lastArgs) return undefined;\n const args = lastArgs;\n const ctx = lastThis as ThisParameterType<T>;\n lastArgs = undefined;\n lastThis = undefined;\n // biome-ignore lint/suspicious/noExplicitAny: -\n lastResult = fn.apply(ctx as any, args);\n return lastResult;\n };\n\n const remaining = (now: number) => delay - (now - lastInvokeTime);\n\n const timerExpired = () => {\n const now = Date.now();\n if (lastArgs && remaining(now) <= 0) {\n // trailing edge invoke\n invoke(now);\n } else if (lastArgs) {\n // reschedule until a window elapses\n timer = setTimeout(timerExpired, remaining(now));\n } else {\n clearTimer();\n }\n };\n\n const throttled = function (this: ThisParameterType<T>, ...args: Parameters<T>) {\n const now = Date.now();\n if (lastInvokeTime === 0 && !leading) {\n // If leading is false, start the window now but don't invoke immediately\n lastInvokeTime = now;\n }\n\n lastArgs = args;\n lastThis = this;\n\n const rem = remaining(now);\n\n if (rem <= 0) {\n // Window elapsed: invoke now\n invoke(now);\n } else if (trailing && !timer) {\n // Schedule trailing call if not already scheduled\n timer = setTimeout(timerExpired, rem);\n }\n } as Throttled<T>;\n\n throttled.cancel = () => {\n clearTimer();\n lastArgs = undefined;\n lastThis = undefined;\n lastInvokeTime = 0;\n };\n\n throttled.flush = () => {\n if (!lastArgs) return undefined;\n const now = Date.now();\n return invoke(now) as ReturnType<T> | undefined;\n };\n\n // Pending if a trailing call is scheduled OR there are queued args.\n throttled.pending = () => lastArgs !== undefined || timer !== undefined;\n\n return throttled;\n}\n"],"names":["throttle","fn","delay","options","assert","leading","trailing","timer","lastInvokeTime","lastArgs","lastThis","lastResult","clearTimer","invoke","now","args","ctx","remaining","timerExpired","throttled","rem"],"mappings":";AAuBO,SAASA,EACdC,GACAC,IAAQ,KACRC,IAA2B,EAAE,SAAS,IAAM,UAAU,MACxC;AACd,EAAAC,EAAO,OAAOH,KAAO,YAAY,qCAAqC;AAAA,IACpE,MAAM,EAAE,IAAAA,EAAA;AAAA,IACR,MAAM;AAAA,EAAA,CACP,GACDG,EAAO,OAAOF,KAAU,YAAYA,KAAS,GAAG,uCAAuC;AAAA,IACrF,MAAM,EAAE,OAAAA,EAAA;AAAA,IACR,MAAM;AAAA,EAAA,CACP;AAED,QAAMG,IAAUF,EAAQ,WAAW,IAC7BG,IAAWH,EAAQ,YAAY;AAErC,MAAII,GACAC,IAAiB,GACjBC,GACAC,GACAC;AAEJ,QAAMC,IAAa,MAAM;AACvB,IAAIL,MAAU,WACZ,aAAaA,CAAK,GAClBA,IAAQ;AAAA,EAEZ,GAEMM,IAAS,CAACC,MAAgB;AAG9B,QAFAN,IAAiBM,GACjBF,EAAA,GACI,CAACH,EAAU;AACf,UAAMM,IAAON,GACPO,IAAMN;AACZ,WAAAD,IAAW,QACXC,IAAW,QAEXC,IAAaV,EAAG,MAAMe,GAAYD,CAAI,GAC/BJ;AAAA,EACT,GAEMM,IAAY,CAACH,MAAgBZ,KAASY,IAAMN,IAE5CU,IAAe,MAAM;AACzB,UAAMJ,IAAM,KAAK,IAAA;AACjB,IAAIL,KAAYQ,EAAUH,CAAG,KAAK,IAEhCD,EAAOC,CAAG,IACDL,IAETF,IAAQ,WAAWW,GAAcD,EAAUH,CAAG,CAAC,IAE/CF,EAAA;AAAA,EAEJ,GAEMO,IAAY,YAAyCJ,GAAqB;AAC9E,UAAMD,IAAM,KAAK,IAAA;AACjB,IAAIN,MAAmB,KAAK,CAACH,MAE3BG,IAAiBM,IAGnBL,IAAWM,GACXL,IAAW;AAEX,UAAMU,IAAMH,EAAUH,CAAG;AAEzB,IAAIM,KAAO,IAETP,EAAOC,CAAG,IACDR,KAAY,CAACC,MAEtBA,IAAQ,WAAWW,GAAcE,CAAG;AAAA,EAExC;AAEA,SAAAD,EAAU,SAAS,MAAM;AACvB,IAAAP,EAAA,GACAH,IAAW,QACXC,IAAW,QACXF,IAAiB;AAAA,EACnB,GAEAW,EAAU,QAAQ,MAAM;AACtB,QAAI,CAACV,EAAU;AACf,UAAMK,IAAM,KAAK,IAAA;AACjB,WAAOD,EAAOC,CAAG;AAAA,EACnB,GAGAK,EAAU,UAAU,MAAMV,MAAa,UAAaF,MAAU,QAEvDY;AACT;"}
package/dist/index.d.ts CHANGED
@@ -264,6 +264,8 @@ export declare function clamp(n: number, min: number, max: number): number;
264
264
  * @param item - The data to clone.
265
265
  *
266
266
  * @returns A deep copy of the provided data.
267
+ *
268
+ * @throws {Error} If the item cannot be cloned.
267
269
  */
268
270
  export declare function clone<T>(item: T): T;
269
271
 
@@ -388,42 +390,23 @@ export declare namespace contains {
388
390
  var fp: boolean;
389
391
  }
390
392
 
391
- declare type CurriedFunction<Params extends any[], R> = Params extends [infer A, ...infer Rest] ? (arg: A) => CurriedFunction<Rest, R> : R;
393
+ export declare type Curried<P extends readonly unknown[], R> = P extends readonly [] ? () => R : <A extends readonly [unknown, ...(readonly unknown[])]>(...args: A) => P extends readonly [...A, ...infer Rest] ? (Rest extends readonly [] ? R : Curried<Rest, R>) : never;
392
394
 
393
- /**
394
- * Curries a function, allowing it to be called with partial arguments.
395
- *
396
- * @example
397
- * ```ts
398
- * const add = (a: number, b: number) => a + b;
399
- * const curriedAdd = curry(add);
400
- * curriedAdd(1)(2) // 3;
401
- * ```
402
- *
403
- * @param fn - The function to curry.
404
- *
405
- * @returns A curried version of the function.
406
- */
407
- export declare const curry: <T extends (...args: any[]) => any>(fn: T) => T extends (...args: infer P) => infer R ? CurriedFunction<P, R> : never;
395
+ export declare function curry<T extends (...args: any[]) => any>(fn: T): Curried<Parameters<T>, ReturnType<T>>;
396
+
397
+ export declare function curry<T extends (...args: any[]) => any, N extends number>(fn: T, arity: N): Curried<Take<N, Parameters<T>>, ReturnType<T>>;
408
398
 
409
399
  /**
410
- * Creates a debounced function that delays invoking the provided function until after
411
- * a specified wait time has elapsed since the last invocation.
412
- *
413
- * @example
414
- * ```ts
415
- * const debouncedLog = debounce(console.log, 1000);
416
- *
417
- * debouncedLog('Hello'); // Will log after 1 second if not called again
418
- * debouncedLog('World'); // Resets the timer, will log 'World' after 1 second
419
- * ```
420
- *
421
- * @param fn - The function to debounce.
422
- * @param [delay=300] - - The number of milliseconds to delay invoking the function.
423
- *
424
- * @returns - A debounced function
400
+ * Debounce a function (trailing). Use `flush` to invoke immediately,
401
+ * `cancel` to clear, and `pending` to check if an invocation is scheduled.
425
402
  */
426
- export declare function debounce<T extends Fn>(fn: T, delay?: number): (...args: Parameters<T>) => void;
403
+ export declare function debounce<T extends Fn>(fn: T, delay?: number): Debounced<T>;
404
+
405
+ export declare type Debounced<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {
406
+ cancel(): void;
407
+ flush(): ReturnType<T> | undefined;
408
+ pending(): boolean;
409
+ };
427
410
 
428
411
  declare type DeepMerge<T, U> = T extends Obj ? U extends Obj ? {
429
412
  [K in keyof T | keyof U]: K extends keyof T ? K extends keyof U ? DeepMerge<T[K], U[K]> : T[K] : K extends keyof U ? U[K] : never;
@@ -718,7 +701,7 @@ export declare function ge(a: unknown, b: unknown): boolean;
718
701
  *
719
702
  * @throws {TypeError} If the provided array is not an array.
720
703
  */
721
- export declare function group<T, K extends keyof T, R extends T[K] extends string ? T[K] : never>(array: T[], selector: Selector<T>): Record<R, T[]>;
704
+ export declare function group<T, _K extends keyof T, R extends string | number | symbol>(array: T[], selector: Selector<T>): Record<R, T[]>;
722
705
 
723
706
  export declare namespace group {
724
707
  var fp: boolean;
@@ -1335,7 +1318,7 @@ export declare function list<T>(initialData: T[], config?: Config<T>): {
1335
1318
  readonly pages: T[][];
1336
1319
  prev(): void;
1337
1320
  reset(): T[];
1338
- search: (str: string) => void;
1321
+ search: Debounced<(str: string) => T[]>;
1339
1322
  sort(fn?: (a: T, b: T) => number): T[];
1340
1323
  [Symbol.iterator](): Generator<T[], void, unknown>;
1341
1324
  };
@@ -1438,14 +1421,16 @@ export declare function median<T>(arr: T[], callback?: (item: T) => number | Dat
1438
1421
  * @param options - Memoization options.
1439
1422
  * @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).
1440
1423
  * @param [options.maxSize] - (optional) maximum cache size (LRU eviction).
1424
+ * @param [options.resolver] - (optional) custom function to resolve the cache key.
1441
1425
  *
1442
1426
  * @returns A new function that memorizes the input function.
1443
1427
  */
1444
- export declare function memo<T extends Fn>(fn: T, { ttl, maxSize }?: MemoizeOptions): (...args: Parameters<T>) => ReturnType<T>;
1428
+ export declare function memo<T extends Fn>(fn: T, { ttl, maxSize, resolver }?: MemoizeOptions<T>): (...args: Parameters<T>) => ReturnType<T>;
1445
1429
 
1446
- declare type MemoizeOptions = {
1430
+ declare type MemoizeOptions<T extends Fn> = {
1447
1431
  ttl?: number;
1448
1432
  maxSize?: number;
1433
+ resolver?: (...args: Parameters<T>) => string;
1449
1434
  };
1450
1435
 
1451
1436
  declare type Merge<T extends Obj[]> = T extends [infer First, ...infer Rest] ? First extends Obj ? Rest extends Obj[] ? DeepMerge<First, Merge<Rest>> : First : Obj : Obj;
@@ -1615,7 +1600,7 @@ declare type PathValue<T, P extends string> = P extends `${infer Key}.${infer Re
1615
1600
  *
1616
1601
  * @throws {TypeError} If the first argument is not an array.
1617
1602
  */
1618
- export declare function pick<T, R, C extends CallbackDynamic<T, R>>(array: T[], callback: C, predicate?: Predicate<T>): Result<C> | undefined;
1603
+ export declare function pick<T, R = T>(array: T[], callback: (item: T, index: number, array: T[]) => R, predicate?: (item: T, index: number, array: T[]) => boolean): R | undefined;
1619
1604
 
1620
1605
  export declare namespace pick {
1621
1606
  var fp: boolean;
@@ -1739,6 +1724,9 @@ export declare function random(min: number, max: number): number;
1739
1724
  * @param step - The value to increment or decrement by.
1740
1725
  *
1741
1726
  * @returns The range of numbers.
1727
+ *
1728
+ * @throws {TypeError} If start, stop, or step are not finite numbers.
1729
+ * @throws {Error} If step is 0 or if range exceeds maximum size.
1742
1730
  */
1743
1731
  export declare function range(start: number, stop: number, step: number): number[];
1744
1732
 
@@ -1817,7 +1805,7 @@ export declare type ResultArray<C extends FnDynamic> = C extends FnAsync ? Promi
1817
1805
  export declare function retry<T>(fn: () => Promise<T>, { times, delay, backoff, signal, }?: {
1818
1806
  times?: number;
1819
1807
  delay?: number;
1820
- backoff?: number;
1808
+ backoff?: number | ((attempt: number, delay: number) => number);
1821
1809
  signal?: AbortSignal;
1822
1810
  }): Promise<T>;
1823
1811
 
@@ -1984,6 +1972,8 @@ export declare function similarity(str1: unknown, str2: unknown): number;
1984
1972
  * @param timeout - The number of milliseconds to wait before resolving the Promise.
1985
1973
  *
1986
1974
  * @returns A Promise that resolves after the specified time.
1975
+ *
1976
+ * @throws {TypeError} If timeout is not a non-negative number.
1987
1977
  */
1988
1978
  export declare function sleep(timeout: number): Promise<void>;
1989
1979
 
@@ -2097,7 +2087,6 @@ export declare namespace substitute {
2097
2087
  * sum([1, 2, 3]) // 6
2098
2088
  * sum([{value: 1}, {value: 2}, {value: 3}], (item) => item.value) // 6
2099
2089
  * sum(['apple', 'banana', 'cherry']) // TypeError
2100
- * sum([new Date('2023-01-01'), new Date('2022-01-01')]) // 467308800000
2101
2090
  * ```
2102
2091
  *
2103
2092
  * @param array - The array to sum.
@@ -2105,29 +2094,49 @@ export declare namespace substitute {
2105
2094
  *
2106
2095
  * @returns The sum of the numbers in the array or the sum of the mapped values.
2107
2096
  */
2108
- export declare function sum<T>(array: T[], callback?: (item: T) => number | Date): number | Date | undefined;
2097
+ export declare function sum<T>(array: T[], callback?: (item: T) => number): number | undefined;
2109
2098
 
2110
2099
  declare type SyncCallback<R, T> = (prev: R, curr: T, index: number, array: T[]) => R;
2111
2100
 
2101
+ /** biome-ignore-all lint/suspicious/noExplicitAny: - */
2112
2102
  /**
2113
- * Creates a throttled function that only invokes the provided function at most once per every specified milliseconds.
2103
+ * Curries a function, allowing it to be called with partial arguments.
2114
2104
  *
2115
2105
  * @example
2116
2106
  * ```ts
2117
- * const log = () => console.log('Hello, world!');
2118
- * const throttledLog = throttle(log, 1000);
2119
- *
2120
- * throttledLog(); // logs 'Hello, world!' immediately
2121
- * throttledLog(); // does nothing because less than 1 second has passed since the last invocation
2122
- * setTimeout(throttledLog, 1000); // logs 'Hello, world!' after 1 second
2107
+ * const add = (a: number, b: number) => a + b;
2108
+ * const curriedAdd = curry(add);
2109
+ * curriedAdd(1)(2) // 3;
2123
2110
  * ```
2124
2111
  *
2125
- * @param fn - The function to throttle.
2126
- * @param [delay=700] - The number of milliseconds to wait before invoking the function again.
2112
+ * @param fn - The function to curry.
2113
+ * @param arity - The number of arguments the function expects. Defaults to the function's length.
2127
2114
  *
2128
- * @returns A new function that throttles the input function.
2115
+ * @returns A curried version of the function.
2129
2116
  */
2130
- export declare function throttle<T extends Fn>(fn: T, delay?: number): (...args: Parameters<T>) => void;
2117
+ declare type Take<N extends number, T extends readonly unknown[], Acc extends readonly unknown[] = []> = Acc['length'] extends N ? Acc : T extends readonly [infer H, ...infer R] ? Take<N, R, readonly [...Acc, H]> : Acc;
2118
+
2119
+ /**
2120
+ * Throttles a function. By default, leading and trailing are both true (lodash-like behavior).
2121
+ * The function is invoked at the leading edge and trailing edge of the throttle period.
2122
+ *
2123
+ * Example:
2124
+ * const fn = () => ...
2125
+ * const t = throttle(fn, 700);
2126
+ * const leadingOnly = throttle(fn, 700, { trailing: false });
2127
+ */
2128
+ export declare function throttle<T extends Fn>(fn: T, delay?: number, options?: ThrottleOptions): Throttled<T>;
2129
+
2130
+ export declare type Throttled<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {
2131
+ cancel(): void;
2132
+ flush(): ReturnType<T> | undefined;
2133
+ pending(): boolean;
2134
+ };
2135
+
2136
+ export declare type ThrottleOptions = {
2137
+ leading?: boolean;
2138
+ trailing?: boolean;
2139
+ };
2131
2140
 
2132
2141
  /**
2133
2142
  * Calculates the remaining time until a target date.
@@ -2178,6 +2187,8 @@ export declare type TimeUnit = 'YEAR' | 'MONTH' | 'WEEK' | 'DAY' | 'HOUR' | 'MIN
2178
2187
  * @param ellipsis - The characters to end the truncated string with.
2179
2188
  *
2180
2189
  * @returns The truncated string.
2190
+ *
2191
+ * @throws {TypeError} If str is not a string or limit is not a positive number.
2181
2192
  */
2182
2193
  export declare function truncate(str: string, limit?: number, completeWords?: boolean, ellipsis?: string): string;
2183
2194
 
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./sum.cjs");function o(t,n){if(t.length===0)return;let e;try{e=i.sum(t,n)}catch(r){if(r instanceof TypeError)return;throw r}if(typeof e=="number")return e/t.length;if(e instanceof Date)return new Date(e.getTime()/t.length)}exports.average=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./sum.cjs");function u(e,n){if(e.length===0)return;if((n?n(e[0]):e[0])instanceof Date){const t=e.reduce((i,o)=>{const r=n?n(o):o;if(!(r instanceof Date))throw new TypeError("average expected all items to be Date objects");return i+r.getTime()},0);return new Date(t/e.length)}try{const t=s.sum(e,n);if(typeof t=="number")return t/e.length}catch(t){if(t instanceof TypeError)return;throw t}}exports.average=u;
2
2
  //# sourceMappingURL=average.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"average.cjs","sources":["../../src/math/average.ts"],"sourcesContent":["import { sum } from './sum';\n\n/**\n * Calculates the average of an array of numbers or dates.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4, 5];\n * average(arr); // 3\n * average(arr, (num) => num * 2); // 6\n * average(arr, (num) => new Date(Date.now() + 1000 * 60 * 60 * 24 * num); // Date object representing 3 days from now\n * ```\n *\n * @param array - The array of numbers or dates to average.\n * @param callback - (optional) A callback function to map the values.\n * @returns The average of the numbers or dates in the array.\n */\n\nexport function average<T>(array: T[], callback?: (item: T) => number | Date): number | Date | undefined {\n if (array.length === 0) return undefined;\n let total: number | Date | undefined;\n try {\n total = sum(array, callback);\n } catch (err) {\n if (err instanceof TypeError) return undefined;\n throw err;\n }\n if (typeof total === 'number') {\n return total / array.length;\n }\n if (total instanceof Date) {\n // For dates, average by dividing the timestamp sum by array length\n return new Date(total.getTime() / array.length);\n }\n return undefined;\n}\n"],"names":["average","array","callback","total","sum","err"],"mappings":"6GAkBO,SAASA,EAAWC,EAAYC,EAAkE,CACvG,GAAID,EAAM,SAAW,EAAG,OACxB,IAAIE,EACJ,GAAI,CACFA,EAAQC,EAAAA,IAAIH,EAAOC,CAAQ,CAC7B,OAASG,EAAK,CACZ,GAAIA,aAAe,UAAW,OAC9B,MAAMA,CACR,CACA,GAAI,OAAOF,GAAU,SACnB,OAAOA,EAAQF,EAAM,OAEvB,GAAIE,aAAiB,KAEnB,OAAO,IAAI,KAAKA,EAAM,QAAA,EAAYF,EAAM,MAAM,CAGlD"}
1
+ {"version":3,"file":"average.cjs","sources":["../../src/math/average.ts"],"sourcesContent":["import { sum } from './sum';\n\n/**\n * Calculates the average of an array of numbers or dates.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4, 5];\n * average(arr); // 3\n * average(arr, (num) => num * 2); // 6\n * average(arr, (num) => new Date(Date.now() + 1000 * 60 * 60 * 24 * num); // Date object representing 3 days from now\n * ```\n *\n * @param array - The array of numbers or dates to average.\n * @param callback - (optional) A callback function to map the values.\n * @returns The average of the numbers or dates in the array.\n */\n\nexport function average<T>(array: T[], callback?: (item: T) => number | Date): number | Date | undefined {\n if (array.length === 0) return undefined;\n\n // Check if we are dealing with Dates (either directly or via callback)\n const firstItem = callback ? callback(array[0]) : array[0];\n const isDate = firstItem instanceof Date;\n\n if (isDate) {\n const totalTimestamp = array.reduce<number>((acc, item) => {\n const val = callback ? callback(item) : item;\n if (!(val instanceof Date)) {\n throw new TypeError('average expected all items to be Date objects');\n }\n return acc + val.getTime();\n }, 0);\n return new Date(totalTimestamp / array.length);\n }\n\n // Handle numbers\n try {\n const total = sum(array, callback as (item: T) => number);\n if (typeof total === 'number') {\n return total / array.length;\n }\n } catch (err) {\n if (err instanceof TypeError) return undefined;\n throw err;\n }\n\n return undefined;\n}\n"],"names":["average","array","callback","totalTimestamp","acc","item","val","total","sum","err"],"mappings":"6GAkBO,SAASA,EAAWC,EAAYC,EAAkE,CACvG,GAAID,EAAM,SAAW,EAAG,OAMxB,IAHkBC,EAAWA,EAASD,EAAM,CAAC,CAAC,EAAIA,EAAM,CAAC,aACrB,KAExB,CACV,MAAME,EAAiBF,EAAM,OAAe,CAACG,EAAKC,IAAS,CACzD,MAAMC,EAAMJ,EAAWA,EAASG,CAAI,EAAIA,EACxC,GAAI,EAAEC,aAAe,MACnB,MAAM,IAAI,UAAU,+CAA+C,EAErE,OAAOF,EAAME,EAAI,QAAA,CACnB,EAAG,CAAC,EACJ,OAAO,IAAI,KAAKH,EAAiBF,EAAM,MAAM,CAC/C,CAGA,GAAI,CACF,MAAMM,EAAQC,EAAAA,IAAIP,EAAOC,CAA+B,EACxD,GAAI,OAAOK,GAAU,SACnB,OAAOA,EAAQN,EAAM,MAEzB,OAASQ,EAAK,CACZ,GAAIA,aAAe,UAAW,OAC9B,MAAMA,CACR,CAGF"}
@@ -1,19 +1,25 @@
1
- import { sum as o } from "./sum.js";
2
- function f(t, r) {
1
+ import { sum as s } from "./sum.js";
2
+ function p(t, n) {
3
3
  if (t.length === 0) return;
4
- let e;
4
+ if ((n ? n(t[0]) : t[0]) instanceof Date) {
5
+ const e = t.reduce((i, o) => {
6
+ const r = n ? n(o) : o;
7
+ if (!(r instanceof Date))
8
+ throw new TypeError("average expected all items to be Date objects");
9
+ return i + r.getTime();
10
+ }, 0);
11
+ return new Date(e / t.length);
12
+ }
5
13
  try {
6
- e = o(t, r);
7
- } catch (n) {
8
- if (n instanceof TypeError) return;
9
- throw n;
14
+ const e = s(t, n);
15
+ if (typeof e == "number")
16
+ return e / t.length;
17
+ } catch (e) {
18
+ if (e instanceof TypeError) return;
19
+ throw e;
10
20
  }
11
- if (typeof e == "number")
12
- return e / t.length;
13
- if (e instanceof Date)
14
- return new Date(e.getTime() / t.length);
15
21
  }
16
22
  export {
17
- f as average
23
+ p as average
18
24
  };
19
25
  //# sourceMappingURL=average.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"average.js","sources":["../../src/math/average.ts"],"sourcesContent":["import { sum } from './sum';\n\n/**\n * Calculates the average of an array of numbers or dates.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4, 5];\n * average(arr); // 3\n * average(arr, (num) => num * 2); // 6\n * average(arr, (num) => new Date(Date.now() + 1000 * 60 * 60 * 24 * num); // Date object representing 3 days from now\n * ```\n *\n * @param array - The array of numbers or dates to average.\n * @param callback - (optional) A callback function to map the values.\n * @returns The average of the numbers or dates in the array.\n */\n\nexport function average<T>(array: T[], callback?: (item: T) => number | Date): number | Date | undefined {\n if (array.length === 0) return undefined;\n let total: number | Date | undefined;\n try {\n total = sum(array, callback);\n } catch (err) {\n if (err instanceof TypeError) return undefined;\n throw err;\n }\n if (typeof total === 'number') {\n return total / array.length;\n }\n if (total instanceof Date) {\n // For dates, average by dividing the timestamp sum by array length\n return new Date(total.getTime() / array.length);\n }\n return undefined;\n}\n"],"names":["average","array","callback","total","sum","err"],"mappings":";AAkBO,SAASA,EAAWC,GAAYC,GAAkE;AACvG,MAAID,EAAM,WAAW,EAAG;AACxB,MAAIE;AACJ,MAAI;AACF,IAAAA,IAAQC,EAAIH,GAAOC,CAAQ;AAAA,EAC7B,SAASG,GAAK;AACZ,QAAIA,aAAe,UAAW;AAC9B,UAAMA;AAAA,EACR;AACA,MAAI,OAAOF,KAAU;AACnB,WAAOA,IAAQF,EAAM;AAEvB,MAAIE,aAAiB;AAEnB,WAAO,IAAI,KAAKA,EAAM,QAAA,IAAYF,EAAM,MAAM;AAGlD;"}
1
+ {"version":3,"file":"average.js","sources":["../../src/math/average.ts"],"sourcesContent":["import { sum } from './sum';\n\n/**\n * Calculates the average of an array of numbers or dates.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4, 5];\n * average(arr); // 3\n * average(arr, (num) => num * 2); // 6\n * average(arr, (num) => new Date(Date.now() + 1000 * 60 * 60 * 24 * num); // Date object representing 3 days from now\n * ```\n *\n * @param array - The array of numbers or dates to average.\n * @param callback - (optional) A callback function to map the values.\n * @returns The average of the numbers or dates in the array.\n */\n\nexport function average<T>(array: T[], callback?: (item: T) => number | Date): number | Date | undefined {\n if (array.length === 0) return undefined;\n\n // Check if we are dealing with Dates (either directly or via callback)\n const firstItem = callback ? callback(array[0]) : array[0];\n const isDate = firstItem instanceof Date;\n\n if (isDate) {\n const totalTimestamp = array.reduce<number>((acc, item) => {\n const val = callback ? callback(item) : item;\n if (!(val instanceof Date)) {\n throw new TypeError('average expected all items to be Date objects');\n }\n return acc + val.getTime();\n }, 0);\n return new Date(totalTimestamp / array.length);\n }\n\n // Handle numbers\n try {\n const total = sum(array, callback as (item: T) => number);\n if (typeof total === 'number') {\n return total / array.length;\n }\n } catch (err) {\n if (err instanceof TypeError) return undefined;\n throw err;\n }\n\n return undefined;\n}\n"],"names":["average","array","callback","totalTimestamp","acc","item","val","total","sum","err"],"mappings":";AAkBO,SAASA,EAAWC,GAAYC,GAAkE;AACvG,MAAID,EAAM,WAAW,EAAG;AAMxB,OAHkBC,IAAWA,EAASD,EAAM,CAAC,CAAC,IAAIA,EAAM,CAAC,cACrB,MAExB;AACV,UAAME,IAAiBF,EAAM,OAAe,CAACG,GAAKC,MAAS;AACzD,YAAMC,IAAMJ,IAAWA,EAASG,CAAI,IAAIA;AACxC,UAAI,EAAEC,aAAe;AACnB,cAAM,IAAI,UAAU,+CAA+C;AAErE,aAAOF,IAAME,EAAI,QAAA;AAAA,IACnB,GAAG,CAAC;AACJ,WAAO,IAAI,KAAKH,IAAiBF,EAAM,MAAM;AAAA,EAC/C;AAGA,MAAI;AACF,UAAMM,IAAQC,EAAIP,GAAOC,CAA+B;AACxD,QAAI,OAAOK,KAAU;AACnB,aAAOA,IAAQN,EAAM;AAAA,EAEzB,SAASQ,GAAK;AACZ,QAAIA,aAAe,UAAW;AAC9B,UAAMA;AAAA,EACR;AAGF;"}