@kikiutils/shared 15.0.1 → 15.0.2

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 (69) hide show
  1. package/README.md +46 -119
  2. package/dist/crypto-hash.d.ts +145 -0
  3. package/dist/crypto-hash.d.ts.map +1 -1
  4. package/dist/crypto-hash.js +137 -7
  5. package/dist/crypto-hash.js.map +1 -1
  6. package/dist/datetime.d.ts +0 -2
  7. package/dist/datetime.d.ts.map +1 -1
  8. package/dist/datetime.js +0 -2
  9. package/dist/datetime.js.map +1 -1
  10. package/dist/env.d.ts +2 -0
  11. package/dist/env.d.ts.map +1 -1
  12. package/dist/env.js +2 -0
  13. package/dist/env.js.map +1 -1
  14. package/dist/event-awaiter.js +1 -1
  15. package/dist/event-awaiter.js.map +1 -1
  16. package/dist/hash.d.ts +48 -5
  17. package/dist/hash.d.ts.map +1 -1
  18. package/dist/hash.js +49 -6
  19. package/dist/hash.js.map +1 -1
  20. package/dist/math.js +1 -1
  21. package/dist/math.js.map +1 -1
  22. package/dist/object.d.ts +4 -0
  23. package/dist/object.d.ts.map +1 -1
  24. package/dist/object.js +4 -0
  25. package/dist/object.js.map +1 -1
  26. package/dist/random.js +2 -0
  27. package/dist/random.js.map +1 -1
  28. package/dist/storages/lru/keyed-store.d.ts +22 -0
  29. package/dist/storages/lru/keyed-store.d.ts.map +1 -1
  30. package/dist/storages/lru/keyed-store.js +22 -0
  31. package/dist/storages/lru/keyed-store.js.map +1 -1
  32. package/dist/storages/redis/keyed-store.d.ts +25 -0
  33. package/dist/storages/redis/keyed-store.d.ts.map +1 -1
  34. package/dist/storages/redis/keyed-store.js +25 -0
  35. package/dist/storages/redis/keyed-store.js.map +1 -1
  36. package/dist/storages/redis/msgpack.d.ts +20 -0
  37. package/dist/storages/redis/msgpack.d.ts.map +1 -1
  38. package/dist/storages/redis/msgpack.js +20 -0
  39. package/dist/storages/redis/msgpack.js.map +1 -1
  40. package/dist/storages/redis/types.d.ts +42 -0
  41. package/dist/storages/redis/types.d.ts.map +1 -1
  42. package/dist/time.d.ts +17 -0
  43. package/dist/time.d.ts.map +1 -1
  44. package/dist/time.js +17 -0
  45. package/dist/time.js.map +1 -1
  46. package/dist/url.d.ts +3 -0
  47. package/dist/url.d.ts.map +1 -1
  48. package/dist/url.js +8 -2
  49. package/dist/url.js.map +1 -1
  50. package/dist/vue.d.ts +6 -0
  51. package/dist/vue.d.ts.map +1 -1
  52. package/dist/vue.js +6 -0
  53. package/dist/vue.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/crypto-hash.ts +143 -14
  56. package/src/datetime.ts +0 -2
  57. package/src/env.ts +2 -0
  58. package/src/event-awaiter.ts +1 -1
  59. package/src/hash.ts +56 -14
  60. package/src/math.ts +2 -1
  61. package/src/object.ts +4 -0
  62. package/src/random.ts +3 -0
  63. package/src/storages/lru/keyed-store.ts +22 -0
  64. package/src/storages/redis/keyed-store.ts +25 -0
  65. package/src/storages/redis/msgpack.ts +20 -0
  66. package/src/storages/redis/types.ts +52 -0
  67. package/src/time.ts +17 -0
  68. package/src/url.ts +13 -2
  69. package/src/vue.ts +6 -0
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/storages/redis/types.ts"],"mappings":";;;UAEiB,gBAAA;EACb,MAAA,GAAS,GAAA,aAAgB,OAAA;EACzB,SAAA,GAAY,GAAA,aAAgB,OAAA,CAAQ,QAAA,CAAS,UAAA;EAC7C,GAAA,GAAM,GAAA,aAAgB,OAAA;EACtB,SAAA,GAAY,GAAA,UAAa,KAAA,EAAO,UAAA,KAAe,OAAA;EAC/C,WAAA,GAAc,GAAA,UAAa,UAAA,UAAoB,KAAA,EAAO,UAAA,KAAe,OAAA;EACrE,GAAA,GAAM,GAAA,aAAgB,OAAA;AAAA;AAAA,UAGT,gBAAA;EACb,OAAA,gBAAuB,GAAA,aAAgB,OAAA,CAAQ,QAAA,CAAS,CAAA;EACxD,UAAA,GAAa,GAAA,aAAgB,OAAA;EAC7B,OAAA,GAAU,GAAA,aAAgB,OAAA;EAC1B,UAAA,GAAa,GAAA,aAAgB,OAAA;EAC7B,OAAA,GAAU,GAAA,UAAa,KAAA,UAAe,OAAA;EACtC,cAAA,GAAiB,GAAA,UAAa,UAAA,UAAoB,KAAA,UAAe,OAAA;AAAA"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/storages/redis/types.ts"],"mappings":";;;;;AAKA;UAAiB,gBAAA;;;;EAIb,MAAA,GAAS,GAAA,aAAgB,OAAA;EAKG;;;EAA5B,SAAA,GAAY,GAAA,aAAgB,OAAA,CAAQ,QAAA,CAAS,UAAA;EAeS;;;EAVtD,GAAA,GAAM,GAAA,aAAgB,OAAA;EAeO;;;EAV7B,SAAA,GAAY,GAAA,UAAa,KAAA,EAAO,UAAA,KAAe,OAAA;EAV/C;;;EAeA,WAAA,GAAc,GAAA,UAAa,UAAA,UAAoB,KAAA,EAAO,UAAA,KAAe,OAAA;EAfxB;;;EAoB7C,GAAA,GAAM,GAAA,aAAgB,OAAA;AAAA;;;;UAMT,gBAAA;EAXb;;;EAeA,OAAA,gBAAuB,GAAA,aAAgB,OAAA,CAAQ,QAAA,CAAS,CAAA;EAfT;;;EAoB/C,UAAA,GAAa,GAAA,aAAgB,OAAA;EAfP;;;EAoBtB,OAAA,GAAU,GAAA,aAAgB,OAAA;EAdG;;;EAmB7B,UAAA,GAAa,GAAA,aAAgB,OAAA;EAfU;;;EAoBvC,OAAA,GAAU,GAAA,UAAa,KAAA,UAAe,OAAA;EAAA;;;EAKtC,cAAA,GAAiB,GAAA,UAAa,UAAA,UAAoB,KAAA,UAAe,OAAA;AAAA"}
package/dist/time.d.ts CHANGED
@@ -1,4 +1,21 @@
1
1
  //#region src/time.d.ts
2
+ /**
3
+ * Creates a delay that can be aborted via AbortSignal.
4
+ *
5
+ * @param {number} ms - Delay duration in milliseconds
6
+ * @param {AbortSignal} [signal] - Optional AbortSignal to cancel the delay
7
+ *
8
+ * @returns {Promise<undefined>} A promise that resolves after ms or resolves immediately on abort
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { abortableDelay } from '@kikiutils/shared/time';
13
+ *
14
+ * const controller = new AbortController();
15
+ * setTimeout(() => controller.abort(), 1000);
16
+ * await abortableDelay(5000, controller.signal); // resolves after ~1s when aborted
17
+ * ```
18
+ */
2
19
  declare function abortableDelay(ms: number, signal?: AbortSignal): Promise<unknown>;
3
20
  //#endregion
4
21
  export { abortableDelay };
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.ts","names":[],"sources":["../src/time.ts"],"mappings":";iBAAgB,cAAA,CAAe,EAAA,UAAY,MAAA,GAAS,WAAA,GAAW,OAAA"}
1
+ {"version":3,"file":"time.d.ts","names":[],"sources":["../src/time.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;;;iBAAgB,cAAA,CAAe,EAAA,UAAY,MAAA,GAAS,WAAA,GAAW,OAAA"}
package/dist/time.js CHANGED
@@ -1,4 +1,21 @@
1
1
  //#region src/time.ts
2
+ /**
3
+ * Creates a delay that can be aborted via AbortSignal.
4
+ *
5
+ * @param {number} ms - Delay duration in milliseconds
6
+ * @param {AbortSignal} [signal] - Optional AbortSignal to cancel the delay
7
+ *
8
+ * @returns {Promise<undefined>} A promise that resolves after ms or resolves immediately on abort
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { abortableDelay } from '@kikiutils/shared/time';
13
+ *
14
+ * const controller = new AbortController();
15
+ * setTimeout(() => controller.abort(), 1000);
16
+ * await abortableDelay(5000, controller.signal); // resolves after ~1s when aborted
17
+ * ```
18
+ */
2
19
  function abortableDelay(ms, signal) {
3
20
  return new Promise((resolve) => {
4
21
  const timeout = setTimeout(resolve, ms);
package/dist/time.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"time.js","names":[],"sources":["../src/time.ts"],"sourcesContent":["export function abortableDelay(ms: number, signal?: AbortSignal) {\n return new Promise((resolve) => {\n const timeout = setTimeout(resolve, ms);\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n clearTimeout(timeout);\n resolve(undefined);\n },\n );\n }\n });\n}\n"],"mappings":";AAAA,SAAgB,eAAe,IAAY,QAAsB;AAC7D,QAAO,IAAI,SAAS,YAAY;EAC5B,MAAM,UAAU,WAAW,SAAS,GAAG;AACvC,MAAI,OACA,QAAO,iBACH,eACM;AACF,gBAAa,QAAQ;AACrB,WAAQ,KAAA,EAAU;IAEzB;GAEP"}
1
+ {"version":3,"file":"time.js","names":[],"sources":["../src/time.ts"],"sourcesContent":["/**\n * Creates a delay that can be aborted via AbortSignal.\n *\n * @param {number} ms - Delay duration in milliseconds\n * @param {AbortSignal} [signal] - Optional AbortSignal to cancel the delay\n *\n * @returns {Promise<undefined>} A promise that resolves after ms or resolves immediately on abort\n *\n * @example\n * ```typescript\n * import { abortableDelay } from '@kikiutils/shared/time';\n *\n * const controller = new AbortController();\n * setTimeout(() => controller.abort(), 1000);\n * await abortableDelay(5000, controller.signal); // resolves after ~1s when aborted\n * ```\n */\nexport function abortableDelay(ms: number, signal?: AbortSignal) {\n return new Promise((resolve) => {\n const timeout = setTimeout(resolve, ms);\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n clearTimeout(timeout);\n resolve(undefined);\n },\n );\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,SAAgB,eAAe,IAAY,QAAsB;AAC7D,QAAO,IAAI,SAAS,YAAY;EAC5B,MAAM,UAAU,WAAW,SAAS,GAAG;AACvC,MAAI,OACA,QAAO,iBACH,eACM;AACF,gBAAa,QAAQ;AACrB,WAAQ,KAAA,EAAU;IAEzB;GAEP"}
package/dist/url.d.ts CHANGED
@@ -6,8 +6,11 @@
6
6
  *
7
7
  * @param {string} url - The target URL to modify
8
8
  * @param {string} redirectPath - The path to use as the redirect destination
9
+ * (must be an absolute path starting with '/')
9
10
  *
10
11
  * @returns {string} A new URL string with the `redirect` query parameter
12
+ *
13
+ * @throws {Error} If redirectPath is not a valid relative path (must start with '/')
11
14
  */
12
15
  declare function appendRedirectParamToUrl(url: string, redirectPath: string): string;
13
16
  //#endregion
package/dist/url.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","names":[],"sources":["../src/url.ts"],"mappings":";;AAUA;;;;;;;;;iBAAgB,wBAAA,CAAyB,GAAA,UAAa,YAAA"}
1
+ {"version":3,"file":"url.d.ts","names":[],"sources":["../src/url.ts"],"mappings":";;AAaA;;;;;;;;;;;;iBAAgB,wBAAA,CAAyB,GAAA,UAAa,YAAA"}
package/dist/url.js CHANGED
@@ -6,14 +6,20 @@
6
6
  *
7
7
  * @param {string} url - The target URL to modify
8
8
  * @param {string} redirectPath - The path to use as the redirect destination
9
+ * (must be an absolute path starting with '/')
9
10
  *
10
11
  * @returns {string} A new URL string with the `redirect` query parameter
12
+ *
13
+ * @throws {Error} If redirectPath is not a valid relative path (must start with '/')
11
14
  */
12
15
  function appendRedirectParamToUrl(url, redirectPath) {
13
- const [base, rawQuery = ""] = url.split("?");
16
+ if (!redirectPath.startsWith("/")) throw new Error(`Invalid redirect path: "${redirectPath}". Redirect paths must be absolute paths starting with '/'.`);
17
+ const [baseAndHash, rawQuery = ""] = url.split("?");
18
+ const [base, hash] = (baseAndHash || "").split("#");
14
19
  const searchParams = new URLSearchParams(rawQuery);
15
20
  searchParams.set("redirect", redirectPath);
16
- return `${base}?${searchParams.toString()}`;
21
+ const queryString = searchParams.toString();
22
+ return hash ? `${base}?${queryString}#${hash}` : `${base}?${queryString}`;
17
23
  }
18
24
  //#endregion
19
25
  export { appendRedirectParamToUrl };
package/dist/url.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"url.js","names":[],"sources":["../src/url.ts"],"sourcesContent":["/**\n * Appends or updates the `redirect` query parameter on a given URL.\n *\n * Typically used to preserve the user's current path for post-login navigation.\n *\n * @param {string} url - The target URL to modify\n * @param {string} redirectPath - The path to use as the redirect destination\n *\n * @returns {string} A new URL string with the `redirect` query parameter\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n const [base, rawQuery = ''] = url.split('?');\n const searchParams = new URLSearchParams(rawQuery);\n searchParams.set('redirect', redirectPath);\n return `${base}?${searchParams.toString()}`;\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,yBAAyB,KAAa,cAAsB;CACxE,MAAM,CAAC,MAAM,WAAW,MAAM,IAAI,MAAM,IAAI;CAC5C,MAAM,eAAe,IAAI,gBAAgB,SAAS;AAClD,cAAa,IAAI,YAAY,aAAa;AAC1C,QAAO,GAAG,KAAK,GAAG,aAAa,UAAU"}
1
+ {"version":3,"file":"url.js","names":[],"sources":["../src/url.ts"],"sourcesContent":["/**\n * Appends or updates the `redirect` query parameter on a given URL.\n *\n * Typically used to preserve the user's current path for post-login navigation.\n *\n * @param {string} url - The target URL to modify\n * @param {string} redirectPath - The path to use as the redirect destination\n * (must be an absolute path starting with '/')\n *\n * @returns {string} A new URL string with the `redirect` query parameter\n *\n * @throws {Error} If redirectPath is not a valid relative path (must start with '/')\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n if (!redirectPath.startsWith('/')) {\n throw new Error(\n `Invalid redirect path: \"${redirectPath}\". Redirect paths must be absolute paths starting with '/'.`,\n );\n }\n\n const [baseAndHash, rawQuery = ''] = url.split('?');\n const [base, hash] = (baseAndHash || '').split('#');\n const searchParams = new URLSearchParams(rawQuery);\n searchParams.set('redirect', redirectPath);\n const queryString = searchParams.toString();\n return hash ? `${base}?${queryString}#${hash}` : `${base}?${queryString}`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,yBAAyB,KAAa,cAAsB;AACxE,KAAI,CAAC,aAAa,WAAW,IAAI,CAC7B,OAAM,IAAI,MACN,2BAA2B,aAAa,6DAC3C;CAGL,MAAM,CAAC,aAAa,WAAW,MAAM,IAAI,MAAM,IAAI;CACnD,MAAM,CAAC,MAAM,SAAS,eAAe,IAAI,MAAM,IAAI;CACnD,MAAM,eAAe,IAAI,gBAAgB,SAAS;AAClD,cAAa,IAAI,YAAY,aAAa;CAC1C,MAAM,cAAc,aAAa,UAAU;AAC3C,QAAO,OAAO,GAAG,KAAK,GAAG,YAAY,GAAG,SAAS,GAAG,KAAK,GAAG"}
package/dist/vue.d.ts CHANGED
@@ -26,6 +26,12 @@ declare function clearTimeoutRef(timeoutRef: Ref<Nullable<ReturnType<typeof setT
26
26
  * A Vue composition function that remembers and restores scroll position
27
27
  * of a scrollable container across route changes and keep-alive activation.
28
28
  *
29
+ * Designed for use with `<KeepAlive>` components. Scroll state is saved on
30
+ * route leave and restored when the component is activated again.
31
+ *
32
+ * Note: Without `<KeepAlive>`, the component state is destroyed on unmount,
33
+ * so scroll position will not be preserved.
34
+ *
29
35
  * @template T - The type of the scrollable element (defaults to HTMLElement)
30
36
  *
31
37
  * @param {Ref<Nullable<T>>} containerRef - A ref to the scrollable HTML element
package/dist/vue.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":";;;;;;AAiBA;;;;;iBAAgB,wCAAA,CAAyC,GAAA;;;;;;iBASzC,gBAAA,CAAiB,WAAA,EAAa,GAAA,CAAI,QAAA,CAAS,UAAA,QAAkB,WAAA;;;;;;iBAU7D,eAAA,CAAgB,UAAA,EAAY,GAAA,CAAI,QAAA,CAAS,UAAA,QAAkB,UAAA;;;;AAA3E;;;;;iBAagB,iBAAA,WAA4B,OAAA,GAAU,WAAA,CAAA,CAAa,YAAA,EAAc,GAAA,CAAI,QAAA,CAAS,CAAA"}
1
+ {"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":";;;;;;AAiBA;;;;;iBAAgB,wCAAA,CAAyC,GAAA;;;;;;iBASzC,gBAAA,CAAiB,WAAA,EAAa,GAAA,CAAI,QAAA,CAAS,UAAA,QAAkB,WAAA;;;;;;iBAU7D,eAAA,CAAgB,UAAA,EAAY,GAAA,CAAI,QAAA,CAAS,UAAA,QAAkB,UAAA;;;;AAA3E;;;;;;;;;;;iBAmBgB,iBAAA,WAA4B,OAAA,GAAU,WAAA,CAAA,CAAa,YAAA,EAAc,GAAA,CAAI,QAAA,CAAS,CAAA"}
package/dist/vue.js CHANGED
@@ -34,6 +34,12 @@ function clearTimeoutRef(timeoutRef) {
34
34
  * A Vue composition function that remembers and restores scroll position
35
35
  * of a scrollable container across route changes and keep-alive activation.
36
36
  *
37
+ * Designed for use with `<KeepAlive>` components. Scroll state is saved on
38
+ * route leave and restored when the component is activated again.
39
+ *
40
+ * Note: Without `<KeepAlive>`, the component state is destroyed on unmount,
41
+ * so scroll position will not be preserved.
42
+ *
37
43
  * @template T - The type of the scrollable element (defaults to HTMLElement)
38
44
  *
39
45
  * @param {Ref<Nullable<T>>} containerRef - A ref to the scrollable HTML element
package/dist/vue.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vue.js","names":[],"sources":["../src/vue.ts"],"sourcesContent":["import { onActivated } from 'vue';\nimport type { Ref } from 'vue';\nimport {\n onBeforeRouteLeave,\n useRoute,\n} from 'vue-router';\n\nimport type { Nullable } from './types';\nimport { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify\n *\n * @returns {string} A new URL with the current route fullPath as the `redirect` parameter\n */\nexport function appendRedirectParamFromCurrentRouteToUrl(url: string) {\n return appendRedirectParamToUrl(url, useRoute().fullPath);\n}\n\n/**\n * Clears an interval referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<Nullable<ReturnType<typeof setInterval>>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearIntervalRef(intervalRef: Ref<Nullable<ReturnType<typeof setInterval>>>) {\n if (intervalRef.value) clearInterval(intervalRef.value);\n intervalRef.value = null;\n}\n\n/**\n * Clears a timeout referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<Nullable<ReturnType<typeof setTimeout>>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearTimeoutRef(timeoutRef: Ref<Nullable<ReturnType<typeof setTimeout>>>) {\n if (timeoutRef.value) clearTimeout(timeoutRef.value);\n timeoutRef.value = null;\n}\n\n/**\n * A Vue composition function that remembers and restores scroll position\n * of a scrollable container across route changes and keep-alive activation.\n *\n * @template T - The type of the scrollable element (defaults to HTMLElement)\n *\n * @param {Ref<Nullable<T>>} containerRef - A ref to the scrollable HTML element\n */\nexport function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<Nullable<T>>) {\n let scrollLeft = 0;\n let scrollTop = 0;\n onActivated(() => {\n if (!containerRef.value) return;\n containerRef.value.scrollLeft = scrollLeft;\n containerRef.value.scrollTop = scrollTop;\n });\n\n onBeforeRouteLeave(() => {\n scrollLeft = containerRef.value?.scrollLeft || 0;\n scrollTop = containerRef.value?.scrollTop || 0;\n });\n}\n"],"mappings":";;;;;;;;;;;AAiBA,SAAgB,yCAAyC,KAAa;AAClE,QAAO,yBAAyB,KAAK,UAAU,CAAC,SAAS;;;;;;;AAQ7D,SAAgB,iBAAiB,aAA4D;AACzF,KAAI,YAAY,MAAO,eAAc,YAAY,MAAM;AACvD,aAAY,QAAQ;;;;;;;AAQxB,SAAgB,gBAAgB,YAA0D;AACtF,KAAI,WAAW,MAAO,cAAa,WAAW,MAAM;AACpD,YAAW,QAAQ;;;;;;;;;;AAWvB,SAAgB,kBAAmD,cAAgC;CAC/F,IAAI,aAAa;CACjB,IAAI,YAAY;AAChB,mBAAkB;AACd,MAAI,CAAC,aAAa,MAAO;AACzB,eAAa,MAAM,aAAa;AAChC,eAAa,MAAM,YAAY;GACjC;AAEF,0BAAyB;AACrB,eAAa,aAAa,OAAO,cAAc;AAC/C,cAAY,aAAa,OAAO,aAAa;GAC/C"}
1
+ {"version":3,"file":"vue.js","names":[],"sources":["../src/vue.ts"],"sourcesContent":["import { onActivated } from 'vue';\nimport type { Ref } from 'vue';\nimport {\n onBeforeRouteLeave,\n useRoute,\n} from 'vue-router';\n\nimport type { Nullable } from './types';\nimport { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify\n *\n * @returns {string} A new URL with the current route fullPath as the `redirect` parameter\n */\nexport function appendRedirectParamFromCurrentRouteToUrl(url: string) {\n return appendRedirectParamToUrl(url, useRoute().fullPath);\n}\n\n/**\n * Clears an interval referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<Nullable<ReturnType<typeof setInterval>>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearIntervalRef(intervalRef: Ref<Nullable<ReturnType<typeof setInterval>>>) {\n if (intervalRef.value) clearInterval(intervalRef.value);\n intervalRef.value = null;\n}\n\n/**\n * Clears a timeout referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<Nullable<ReturnType<typeof setTimeout>>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearTimeoutRef(timeoutRef: Ref<Nullable<ReturnType<typeof setTimeout>>>) {\n if (timeoutRef.value) clearTimeout(timeoutRef.value);\n timeoutRef.value = null;\n}\n\n/**\n * A Vue composition function that remembers and restores scroll position\n * of a scrollable container across route changes and keep-alive activation.\n *\n * Designed for use with `<KeepAlive>` components. Scroll state is saved on\n * route leave and restored when the component is activated again.\n *\n * Note: Without `<KeepAlive>`, the component state is destroyed on unmount,\n * so scroll position will not be preserved.\n *\n * @template T - The type of the scrollable element (defaults to HTMLElement)\n *\n * @param {Ref<Nullable<T>>} containerRef - A ref to the scrollable HTML element\n */\nexport function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<Nullable<T>>) {\n let scrollLeft = 0;\n let scrollTop = 0;\n onActivated(() => {\n if (!containerRef.value) return;\n containerRef.value.scrollLeft = scrollLeft;\n containerRef.value.scrollTop = scrollTop;\n });\n\n onBeforeRouteLeave(() => {\n scrollLeft = containerRef.value?.scrollLeft || 0;\n scrollTop = containerRef.value?.scrollTop || 0;\n });\n}\n"],"mappings":";;;;;;;;;;;AAiBA,SAAgB,yCAAyC,KAAa;AAClE,QAAO,yBAAyB,KAAK,UAAU,CAAC,SAAS;;;;;;;AAQ7D,SAAgB,iBAAiB,aAA4D;AACzF,KAAI,YAAY,MAAO,eAAc,YAAY,MAAM;AACvD,aAAY,QAAQ;;;;;;;AAQxB,SAAgB,gBAAgB,YAA0D;AACtF,KAAI,WAAW,MAAO,cAAa,WAAW,MAAM;AACpD,YAAW,QAAQ;;;;;;;;;;;;;;;;AAiBvB,SAAgB,kBAAmD,cAAgC;CAC/F,IAAI,aAAa;CACjB,IAAI,YAAY;AAChB,mBAAkB;AACd,MAAI,CAAC,aAAa,MAAO;AACzB,eAAa,MAAM,aAAa;AAChC,eAAa,MAAM,YAAY;GACjC;AAEF,0BAAyB;AACrB,eAAa,aAAa,OAAO,cAAc;AAC/C,cAAY,aAAa,OAAO,aAAa;GAC/C"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kikiutils/shared",
3
3
  "type": "module",
4
- "version": "15.0.1",
4
+ "version": "15.0.2",
5
5
  "description": "A lightweight and modular utility library for modern JavaScript and TypeScript — includes secure hashing, flexible logging, datetime tools, Vue/web helpers, storage abstraction, and more.",
6
6
  "author": "kiki-kanri",
7
7
  "license": "MIT",
@@ -151,7 +151,7 @@
151
151
  "decimal.js": "^10.6.0",
152
152
  "element-plus": "^2.13.7",
153
153
  "jsdom": "^29.0.2",
154
- "knip": "^6.4.1",
154
+ "knip": "^6.5.0",
155
155
  "lru-cache": "^11.3.5",
156
156
  "millify": "^6.1.0",
157
157
  "msgpackr": "^1.11.10",
@@ -1,61 +1,190 @@
1
+ import { createHash } from 'node:crypto';
2
+ import type {
3
+ BinaryLike,
4
+ BinaryToTextEncoding,
5
+ } from 'node:crypto';
6
+
1
7
  /**
2
- * This file provides a set of functions for creating hash digests using different algorithms and bit lengths.
3
- * It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,
4
- * as well as a function for generating MD5 hash digests.
8
+ * Computes the MD5 hash of the given data.
9
+ *
10
+ * @param {BinaryLike} data - The input data to hash
11
+ * @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
5
12
  *
6
- * These functions use the Node.js crypto module to generate the hashes.
7
- * Can only be used in Node.js/Deno/Bun runtimes.
13
+ * @returns {string | Buffer} The hash digest in the specified encoding
8
14
  *
9
15
  * @example
10
16
  * ```typescript
11
- * import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';
17
+ * import { cryptoMd5 } from '@kikiutils/shared/crypto-hash';
12
18
  *
13
- * console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
19
+ * console.log(cryptoMd5('test')); // 33ed9a05a10b21f0...
14
20
  * ```
15
21
  */
16
-
17
- import { createHash } from 'node:crypto';
18
- import type {
19
- BinaryLike,
20
- BinaryToTextEncoding,
21
- } from 'node:crypto';
22
-
23
22
  export function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
24
23
  return createHash('md5').update(data).digest(outputEncoding);
25
24
  }
26
25
 
26
+ /**
27
+ * Computes the MD5 hash of the given data and returns the raw buffer.
28
+ *
29
+ * @param {BinaryLike} data - The input data to hash
30
+ *
31
+ * @returns {Buffer} The raw hash digest as a Buffer
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { cryptoMd5ToBuffer } from '@kikiutils/shared/crypto-hash';
36
+ *
37
+ * console.log(cryptoMd5ToBuffer('test')); // <Buffer 33 ed 9a ...>
38
+ * ```
39
+ */
27
40
  export function cryptoMd5ToBuffer(data: BinaryLike) {
28
41
  return createHash('md5').update(data).digest();
29
42
  }
30
43
 
44
+ /**
45
+ * Computes the SHA-3 hash of the given data using the 224-bit digest.
46
+ *
47
+ * @param {BinaryLike} data - The input data to hash
48
+ * @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
49
+ *
50
+ * @returns {string | Buffer} The hash digest in the specified encoding
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * import { cryptoSha3224 } from '@kikiutils/shared/crypto-hash';
55
+ *
56
+ * console.log(cryptoSha3224('test')); // 0qW8FoqDcFmkpuqR9J3uT8YX...
57
+ * ```
58
+ */
31
59
  export function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
32
60
  return createHash('sha3-224').update(data).digest(outputEncoding);
33
61
  }
34
62
 
63
+ /**
64
+ * Computes the SHA-3 hash of the given data using the 224-bit digest and returns the raw buffer.
65
+ *
66
+ * @param {BinaryLike} data - The input data to hash
67
+ *
68
+ * @returns {Buffer} The raw hash digest as a Buffer
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * import { cryptoSha3224ToBuffer } from '@kikiutils/shared/crypto-hash';
73
+ *
74
+ * console.log(cryptoSha3224ToBuffer('test')); // <Buffer 0q W8 Fo ...>
75
+ * ```
76
+ */
35
77
  export function cryptoSha3224ToBuffer(data: BinaryLike) {
36
78
  return createHash('sha3-224').update(data).digest();
37
79
  }
38
80
 
81
+ /**
82
+ * Computes the SHA-3 hash of the given data using the 256-bit digest.
83
+ *
84
+ * @param {BinaryLike} data - The input data to hash
85
+ * @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
86
+ *
87
+ * @returns {string | Buffer} The hash digest in the specified encoding
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';
92
+ *
93
+ * console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
94
+ * ```
95
+ */
39
96
  export function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
40
97
  return createHash('sha3-256').update(data).digest(outputEncoding);
41
98
  }
42
99
 
100
+ /**
101
+ * Computes the SHA-3 hash of the given data using the 256-bit digest and returns the raw buffer.
102
+ *
103
+ * @param {BinaryLike} data - The input data to hash
104
+ *
105
+ * @returns {Buffer} The raw hash digest as a Buffer
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * import { cryptoSha3256ToBuffer } from '@kikiutils/shared/crypto-hash';
110
+ *
111
+ * console.log(cryptoSha3256ToBuffer('test')); // <Buffer 36 f0 28 ...>
112
+ * ```
113
+ */
43
114
  export function cryptoSha3256ToBuffer(data: BinaryLike) {
44
115
  return createHash('sha3-256').update(data).digest();
45
116
  }
46
117
 
118
+ /**
119
+ * Computes the SHA-3 hash of the given data using the 384-bit digest.
120
+ *
121
+ * @param {BinaryLike} data - The input data to hash
122
+ * @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
123
+ *
124
+ * @returns {string | Buffer} The hash digest in the specified encoding
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { cryptoSha3384 } from '@kikiutils/shared/crypto-hash';
129
+ *
130
+ * console.log(cryptoSha3384('test')); // 1Q2wQAYaZ4o8vWX5bEB2n3Y...
131
+ * ```
132
+ */
47
133
  export function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
48
134
  return createHash('sha3-384').update(data).digest(outputEncoding);
49
135
  }
50
136
 
137
+ /**
138
+ * Computes the SHA-3 hash of the given data using the 384-bit digest and returns the raw buffer.
139
+ *
140
+ * @param {BinaryLike} data - The input data to hash
141
+ *
142
+ * @returns {Buffer} The raw hash digest as a Buffer
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * import { cryptoSha3384ToBuffer } from '@kikiutils/shared/crypto-hash';
147
+ *
148
+ * console.log(cryptoSha3384ToBuffer('test')); // <Buffer 1Q 2w QZ ...>
149
+ * ```
150
+ */
51
151
  export function cryptoSha3384ToBuffer(data: BinaryLike) {
52
152
  return createHash('sha3-384').update(data).digest();
53
153
  }
54
154
 
155
+ /**
156
+ * Computes the SHA-3 hash of the given data using the 512-bit digest.
157
+ *
158
+ * @param {BinaryLike} data - The input data to hash
159
+ * @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
160
+ *
161
+ * @returns {string | Buffer} The hash digest in the specified encoding
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * import { cryptoSha3512 } from '@kikiutils/shared/crypto-hash';
166
+ *
167
+ * console.log(cryptoSha3512('test')); // b_NQJ8FJBY9dIjm1q7...
168
+ * ```
169
+ */
55
170
  export function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
56
171
  return createHash('sha3-512').update(data).digest(outputEncoding);
57
172
  }
58
173
 
174
+ /**
175
+ * Computes the SHA-3 hash of the given data using the 512-bit digest and returns the raw buffer.
176
+ *
177
+ * @param {BinaryLike} data - The input data to hash
178
+ *
179
+ * @returns {Buffer} The raw hash digest as a Buffer
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * import { cryptoSha3512ToBuffer } from '@kikiutils/shared/crypto-hash';
184
+ *
185
+ * console.log(cryptoSha3512ToBuffer('test')); // <Buffer b_ NQ ...>
186
+ * ```
187
+ */
59
188
  export function cryptoSha3512ToBuffer(data: BinaryLike) {
60
189
  return createHash('sha3-512').update(data).digest();
61
190
  }
package/src/datetime.ts CHANGED
@@ -42,8 +42,6 @@ export type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek'
42
42
  * // Format a date string
43
43
  * console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
44
44
  * ```
45
- *
46
- * @see https://date-fns.org/docs/format
47
45
  */
48
46
  export function formatDate(date: DateArg<Date> & {}, format: string = 'yyyy-MM-dd HH:mm:ss', options?: FormatOptions) {
49
47
  return dateFnsFormat(date, format, options);
package/src/env.ts CHANGED
@@ -35,6 +35,8 @@ export class EnvironmentNotFoundError extends Error {
35
35
  *
36
36
  * @example
37
37
  * ```typescript
38
+ * import { checkAndGetEnvValue } from '@kikiutils/shared/env';
39
+ *
38
40
  * process.env.API_KEY = '';
39
41
  * checkAndGetEnvValue('API_KEY'); // ✅ Returns '' (still considered "defined")
40
42
  *
@@ -82,7 +82,7 @@ export class EventAwaiter<T> {
82
82
 
83
83
  resolvers.push(resolve);
84
84
  this.#promiseResolvers.set(key, resolvers);
85
- if (timeoutMs) {
85
+ if (timeoutMs != null) {
86
86
  setTimeout(
87
87
  () => {
88
88
  const resolvers = this.#promiseResolvers.get(key);
package/src/hash.ts CHANGED
@@ -1,17 +1,3 @@
1
- /**
2
- * This file provides a set of functions for creating SHA-3 hash digests
3
- * using different bit lengths (224, 256, 384, 512).
4
- * These functions use the [@noble/hashes](https://github.com/paulmillr/noble-hashes) library to generate the hashes.
5
- * Can be used in the browser, mainly for Nuxt/Vue and other frameworks compiled and executed in the browser.
6
- *
7
- * @example
8
- * ```typescript
9
- * import { sha3256 } from '@kikiutils/shared/hash';
10
- *
11
- * console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
12
- * ```
13
- */
14
-
15
1
  import {
16
2
  sha3_224,
17
3
  sha3_256,
@@ -23,18 +9,74 @@ import {
23
9
  utf8ToBytes,
24
10
  } from '@noble/hashes/utils.js';
25
11
 
12
+ /**
13
+ * Computes the SHA-3 hash of the given data using the 224-bit digest.
14
+ *
15
+ * @param {string | Uint8Array} data - The input data to hash
16
+ *
17
+ * @returns {string} The hexadecimal hash digest
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { sha3224 } from '@kikiutils/shared/hash';
22
+ *
23
+ * console.log(sha3224('test')); // 0qW8FoqDcFmkpuqR9J3uT8YXVb3pWnLYgA4JqyprhqZ5H...
24
+ * ```
25
+ */
26
26
  export function sha3224(data: string | Uint8Array) {
27
27
  return bytesToHex(sha3_224(typeof data === 'string' ? utf8ToBytes(data) : data));
28
28
  }
29
29
 
30
+ /**
31
+ * Computes the SHA-3 hash of the given data using the 256-bit digest.
32
+ *
33
+ * @param {string | Uint8Array} data - The input data to hash
34
+ *
35
+ * @returns {string} The hexadecimal hash digest
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * import { sha3256 } from '@kikiutils/shared/hash';
40
+ *
41
+ * console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
42
+ * ```
43
+ */
30
44
  export function sha3256(data: string | Uint8Array) {
31
45
  return bytesToHex(sha3_256(typeof data === 'string' ? utf8ToBytes(data) : data));
32
46
  }
33
47
 
48
+ /**
49
+ * Computes the SHA-3 hash of the given data using the 384-bit digest.
50
+ *
51
+ * @param {string | Uint8Array} data - The input data to hash
52
+ *
53
+ * @returns {string} The hexadecimal hash digest
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * import { sha3384 } from '@kikiutils/shared/hash';
58
+ *
59
+ * console.log(sha3384('test')); // 1Q2wQAYaZ4o8vWX5bEB2n3Y...
60
+ * ```
61
+ */
34
62
  export function sha3384(data: string | Uint8Array) {
35
63
  return bytesToHex(sha3_384(typeof data === 'string' ? utf8ToBytes(data) : data));
36
64
  }
37
65
 
66
+ /**
67
+ * Computes the SHA-3 hash of the given data using the 512-bit digest.
68
+ *
69
+ * @param {string | Uint8Array} data - The input data to hash
70
+ *
71
+ * @returns {string} The hexadecimal hash digest
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import { sha3512 } from '@kikiutils/shared/hash';
76
+ *
77
+ * console.log(sha3512('test')); // b_NQJ8FJBY9dIjm1q7...
78
+ * ```
79
+ */
38
80
  export function sha3512(data: string | Uint8Array) {
39
81
  return bytesToHex(sha3_512(typeof data === 'string' ? utf8ToBytes(data) : data));
40
82
  }
package/src/math.ts CHANGED
@@ -51,7 +51,8 @@ export function toPercentageString(
51
51
  const molecularDecimal = new Decimal(molecular.toString());
52
52
  const denominatorDecimal = new Decimal(denominator.toString());
53
53
  const calculationResult = molecularDecimal.div(denominatorDecimal);
54
- const result = calculationResult.isNaN()
54
+
55
+ const result = calculationResult.isNaN() || !calculationResult.isFinite()
55
56
  ? '0.00'
56
57
  : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);
57
58
 
package/src/object.ts CHANGED
@@ -8,6 +8,9 @@
8
8
  * It is designed for use cases such as signature generation, cache key construction,
9
9
  * or any context requiring consistent and predictable object serialization.
10
10
  *
11
+ * Note: Empty objects and arrays produce an empty string, which is useful for
12
+ * generating deterministic signature payloads.
13
+ *
11
14
  * @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
12
15
  * @param {string} kvSeparator - The string used to separate each key from its value (default: '=')
13
16
  * @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')
@@ -19,6 +22,7 @@
19
22
  *
20
23
  * console.log(stringifyObjectDeterministically({ b: 2, a: { x: 1, y: [3, 4] } })); // a.x=1&a.y.0=3&a.y.1=4&b=2
21
24
  * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // foo:bar
25
+ * console.log(stringifyObjectDeterministically({})); // ''
22
26
  * ```
23
27
  */
24
28
  export function stringifyObjectDeterministically(
package/src/random.ts CHANGED
@@ -25,6 +25,9 @@ export function generateWithNestedRandomLength<T = string>(
25
25
  maxMin: number,
26
26
  maxMax: number,
27
27
  ) {
28
+ if (minMin > minMax) throw new Error(`Invalid range: minMin (${minMin}) cannot be greater than minMax (${minMax})`);
29
+ if (maxMin > maxMax) throw new Error(`Invalid range: maxMin (${maxMin}) cannot be greater than maxMax (${maxMax})`);
30
+
28
31
  const random = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;
29
32
  const innerMin = random(minMin, minMax);
30
33
  const finalLength = random(Math.max(innerMin, maxMin), maxMax);
@@ -1,5 +1,27 @@
1
1
  import type { LRUCache } from 'lru-cache';
2
2
 
3
+ /**
4
+ * Creates a keyed store wrapper around an LRU cache instance.
5
+ *
6
+ * @template D - The data type stored in the keyed store
7
+ *
8
+ * @param {LRUCache<any, any, any>} lruInstance - The underlying lru-cache instance
9
+ *
10
+ * @returns {(keyFn: (...args: P) => string) => Readonly<{
11
+ * getItem, getItemTtl, hasItem, removeItem, resolveKey, setItem
12
+ * }>} A keyed store factory that takes a key resolution function
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { createLruKeyedStore } from '@kikiutils/shared/storages/lru/keyed-store';
17
+ * import { LRUCache } from 'lru-cache';
18
+ *
19
+ * const lru = new LRUCache({ max: 100 });
20
+ * const keyedStore = createLruKeyedStore(lru)((userId: string) => `user:${userId}`);
21
+ * await keyedStore.setItem({ name: 'Alice' }, 'user-123');
22
+ * const user = await keyedStore.getItem('user-123'); // { name: 'Alice' }
23
+ * ```
24
+ */
3
25
  export function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<any, any, any>) {
4
26
  return <P extends any[]>(keyFn: (...args: P) => string) => Object.freeze({
5
27
  /**
@@ -2,6 +2,31 @@ import type { MaybeReadonly } from '../../types';
2
2
 
3
3
  import type { RedisLikeStorage } from './types';
4
4
 
5
+ /**
6
+ * Creates a keyed store wrapper around a Redis-like storage.
7
+ *
8
+ * @template D - The data type stored in the keyed store
9
+ *
10
+ * @param {MaybeReadonly<RedisLikeStorage>} storage - The underlying Redis-like storage instance
11
+ *
12
+ * @returns {(keyFn: (...args: P) => string) => Readonly<{
13
+ * getItem, getItemTtl, hasItem, removeItem, resolveKey, setItem, setItemWithTtl
14
+ * }>} A keyed store factory that takes a key resolution function
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { createRedisKeyedStore } from '@kikiutils/shared/storages/redis/keyed-store';
19
+ * import { createRedisMsgpackStorage } from '@kikiutils/shared/storages/redis/msgpack';
20
+ * import { createClient } from 'redis';
21
+ *
22
+ * const client = createClient();
23
+ * await client.connect();
24
+ * const storage = createRedisMsgpackStorage(client as unknown as RedisLikeAdapter);
25
+ * const keyedStore = createRedisKeyedStore(storage)((userId: string) => `user:${userId}`);
26
+ * await keyedStore.setItem({ name: 'Alice' }, 'user-123');
27
+ * const user = await keyedStore.getItem('user-123'); // { name: 'Alice' }
28
+ * ```
29
+ */
5
30
  export function createRedisKeyedStore<D = unknown>(storage: MaybeReadonly<RedisLikeStorage>) {
6
31
  return <P extends any[]>(keyFn: (...args: P) => string) => Object.freeze({
7
32
  getItem: (...args: P) => storage.getItem<D>(keyFn(...args)),
@@ -13,6 +13,26 @@ if (!isNativeAccelerationEnabled) {
13
13
  console.warn('Native acceleration not enabled for msgpackr, verify that install finished properly');
14
14
  }
15
15
 
16
+ /**
17
+ * Creates a Redis-like storage using msgpack serialization.
18
+ *
19
+ * @param {RedisLikeAdapter} adapter - The Redis-like adapter to use for raw buffer operations
20
+ *
21
+ * @returns {Readonly<RedisLikeStorage>} A readonly storage instance
22
+ * with getItem, setItem, hasItem, removeItem, getItemTtl, setItemWithTtl
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * import { createRedisMsgpackStorage } from '@kikiutils/shared/storages/redis/msgpack';
27
+ * import { createClient } from 'redis';
28
+ *
29
+ * const client = createClient();
30
+ * await client.connect();
31
+ * const storage = createRedisMsgpackStorage(client as unknown as RedisLikeAdapter);
32
+ * await storage.setItem('key', { foo: 'bar' });
33
+ * const value = await storage.getItem('key'); // { foo: 'bar' }
34
+ * ```
35
+ */
16
36
  export function createRedisMsgpackStorage(adapter: RedisLikeAdapter): Readonly<RedisLikeStorage> {
17
37
  return Object.freeze({
18
38
  async getItem<T = unknown>(key: string) {