@kikiutils/shared 18.0.1 → 18.2.0

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 (156) hide show
  1. package/dist/buffer.d.ts +19 -21
  2. package/dist/buffer.d.ts.map +1 -1
  3. package/dist/buffer.js +18 -19
  4. package/dist/buffer.js.map +1 -1
  5. package/dist/classes/enhanced-date.d.ts +457 -0
  6. package/dist/classes/enhanced-date.d.ts.map +1 -0
  7. package/dist/classes/enhanced-date.js +635 -0
  8. package/dist/classes/enhanced-date.js.map +1 -0
  9. package/dist/classes/path.d.ts +211 -48
  10. package/dist/classes/path.d.ts.map +1 -1
  11. package/dist/classes/path.js +188 -54
  12. package/dist/classes/path.js.map +1 -1
  13. package/dist/classes/precision-number.d.ts +44 -39
  14. package/dist/classes/precision-number.d.ts.map +1 -1
  15. package/dist/classes/precision-number.js +51 -45
  16. package/dist/classes/precision-number.js.map +1 -1
  17. package/dist/classes/ssh-client.d.ts +3 -4
  18. package/dist/classes/ssh-client.d.ts.map +1 -1
  19. package/dist/classes/ssh-client.js +2 -2
  20. package/dist/classes/ssh-client.js.map +1 -1
  21. package/dist/clipboard.d.ts +25 -26
  22. package/dist/clipboard.d.ts.map +1 -1
  23. package/dist/clipboard.js +23 -23
  24. package/dist/clipboard.js.map +1 -1
  25. package/dist/consola.d.ts +12 -15
  26. package/dist/consola.d.ts.map +1 -1
  27. package/dist/consola.js +10 -12
  28. package/dist/consola.js.map +1 -1
  29. package/dist/crypto-hash.d.ts +65 -56
  30. package/dist/crypto-hash.d.ts.map +1 -1
  31. package/dist/crypto-hash.js +55 -45
  32. package/dist/crypto-hash.js.map +1 -1
  33. package/dist/datetime.d.ts +41 -53
  34. package/dist/datetime.d.ts.map +1 -1
  35. package/dist/datetime.js +53 -66
  36. package/dist/datetime.js.map +1 -1
  37. package/dist/element-plus.d.ts +13 -14
  38. package/dist/element-plus.d.ts.map +1 -1
  39. package/dist/element-plus.js +11 -11
  40. package/dist/element-plus.js.map +1 -1
  41. package/dist/enum.d.ts +39 -36
  42. package/dist/enum.d.ts.map +1 -1
  43. package/dist/enum.js +36 -32
  44. package/dist/enum.js.map +1 -1
  45. package/dist/env.d.ts +22 -15
  46. package/dist/env.d.ts.map +1 -1
  47. package/dist/env.js +20 -12
  48. package/dist/env.js.map +1 -1
  49. package/dist/event-awaiter.d.ts +47 -52
  50. package/dist/event-awaiter.d.ts.map +1 -1
  51. package/dist/event-awaiter.js +46 -50
  52. package/dist/event-awaiter.js.map +1 -1
  53. package/dist/general.d.ts +22 -17
  54. package/dist/general.d.ts.map +1 -1
  55. package/dist/general.js.map +1 -1
  56. package/dist/hash.d.ts +24 -21
  57. package/dist/hash.d.ts.map +1 -1
  58. package/dist/hash.js +20 -16
  59. package/dist/hash.js.map +1 -1
  60. package/dist/math.d.ts +20 -19
  61. package/dist/math.d.ts.map +1 -1
  62. package/dist/math.js +14 -12
  63. package/dist/math.js.map +1 -1
  64. package/dist/number.d.ts +10 -9
  65. package/dist/number.d.ts.map +1 -1
  66. package/dist/number.js +9 -7
  67. package/dist/number.js.map +1 -1
  68. package/dist/object.d.ts +22 -10
  69. package/dist/object.d.ts.map +1 -1
  70. package/dist/object.js +21 -8
  71. package/dist/object.js.map +1 -1
  72. package/dist/pino.d.ts +13 -15
  73. package/dist/pino.d.ts.map +1 -1
  74. package/dist/pino.js +10 -15
  75. package/dist/pino.js.map +1 -1
  76. package/dist/random.d.ts +17 -15
  77. package/dist/random.d.ts.map +1 -1
  78. package/dist/random.js +16 -13
  79. package/dist/random.js.map +1 -1
  80. package/dist/redis/script-runner.d.ts +57 -0
  81. package/dist/redis/script-runner.d.ts.map +1 -0
  82. package/dist/redis/script-runner.js +46 -0
  83. package/dist/redis/script-runner.js.map +1 -0
  84. package/dist/storages/lru/keyed-store.d.ts +18 -14
  85. package/dist/storages/lru/keyed-store.d.ts.map +1 -1
  86. package/dist/storages/lru/keyed-store.js +17 -12
  87. package/dist/storages/lru/keyed-store.js.map +1 -1
  88. package/dist/storages/redis/keyed-store.d.ts +11 -21
  89. package/dist/storages/redis/keyed-store.d.ts.map +1 -1
  90. package/dist/storages/redis/keyed-store.js +10 -19
  91. package/dist/storages/redis/keyed-store.js.map +1 -1
  92. package/dist/storages/redis/msgpack.d.ts +33 -13
  93. package/dist/storages/redis/msgpack.d.ts.map +1 -1
  94. package/dist/storages/redis/msgpack.js +32 -11
  95. package/dist/storages/redis/msgpack.js.map +1 -1
  96. package/dist/storages/redis/types.d.ts +34 -17
  97. package/dist/storages/redis/types.d.ts.map +1 -1
  98. package/dist/string.d.ts +12 -11
  99. package/dist/string.d.ts.map +1 -1
  100. package/dist/string.js +20 -15
  101. package/dist/string.js.map +1 -1
  102. package/dist/time.d.ts +26 -21
  103. package/dist/time.d.ts.map +1 -1
  104. package/dist/time.js +24 -18
  105. package/dist/time.js.map +1 -1
  106. package/dist/types/filtered-key-path.d.ts +4 -15
  107. package/dist/types/filtered-key-path.d.ts.map +1 -1
  108. package/dist/types/index.d.ts +10 -10
  109. package/dist/types/index.d.ts.map +1 -1
  110. package/dist/types/vue.d.ts +7 -7
  111. package/dist/types/vue.d.ts.map +1 -1
  112. package/dist/url.d.ts +15 -14
  113. package/dist/url.d.ts.map +1 -1
  114. package/dist/url.js +12 -10
  115. package/dist/url.js.map +1 -1
  116. package/dist/vue.d.ts +19 -21
  117. package/dist/vue.d.ts.map +1 -1
  118. package/dist/vue.js +15 -16
  119. package/dist/vue.js.map +1 -1
  120. package/dist/web.d.ts +14 -11
  121. package/dist/web.d.ts.map +1 -1
  122. package/dist/web.js +12 -8
  123. package/dist/web.js.map +1 -1
  124. package/package.json +21 -21
  125. package/src/buffer.ts +18 -19
  126. package/src/classes/enhanced-date.ts +715 -0
  127. package/src/classes/path.ts +248 -96
  128. package/src/classes/precision-number.ts +61 -53
  129. package/src/classes/ssh-client.ts +8 -5
  130. package/src/clipboard.ts +23 -23
  131. package/src/consola.ts +10 -12
  132. package/src/crypto-hash.ts +55 -45
  133. package/src/datetime.ts +65 -85
  134. package/src/element-plus.ts +11 -11
  135. package/src/enum.ts +36 -32
  136. package/src/env.ts +20 -12
  137. package/src/event-awaiter.ts +49 -50
  138. package/src/general.ts +20 -14
  139. package/src/hash.ts +20 -16
  140. package/src/math.ts +18 -16
  141. package/src/number.ts +9 -7
  142. package/src/object.ts +21 -8
  143. package/src/pino.ts +11 -15
  144. package/src/random.ts +16 -13
  145. package/src/redis/script-runner.ts +107 -0
  146. package/src/storages/lru/keyed-store.ts +17 -12
  147. package/src/storages/redis/keyed-store.ts +10 -19
  148. package/src/storages/redis/msgpack.ts +32 -11
  149. package/src/storages/redis/types.ts +32 -14
  150. package/src/string.ts +10 -8
  151. package/src/time.ts +24 -18
  152. package/src/types/filtered-key-path.ts +9 -14
  153. package/src/types/vue.ts +6 -5
  154. package/src/url.ts +12 -10
  155. package/src/vue.ts +15 -16
  156. package/src/web.ts +12 -8
@@ -1 +1 @@
1
- {"version":3,"file":"event-awaiter.js","names":["#promiseResolvers"],"sources":["../src/event-awaiter.ts"],"sourcesContent":["/**\n * EventAwaiter provides a mechanism to wait for events (by key) asynchronously.\n *\n * This class allows multiple consumers to `wait` for a specific key\n * and be resolved when `trigger` is called for that key, or automatically\n * resolved with `undefined` if a timeout occurs or an AbortSignal is triggered.\n *\n * Typical use cases include long-polling, request coordination,\n * or implementing event-driven primitives in applications or services.\n *\n * @template T - The type of value that will be resolved when the event is triggered\n */\nexport class EventAwaiter<T> {\n #promiseResolvers = new Map<string, ((value: PromiseLike<T | undefined> | T | undefined) => void)[]>();\n\n /**\n * Triggers all pending promises waiting for the given key.\n * Each promise will be resolved with the provided value.\n *\n * @param {string} key - Identifier for the awaited event\n * @param {T | undefined} value - The value to resolve the awaiting promises with.\n * May be `undefined` to indicate no result or a timeout-like behavior.\n */\n trigger(key: string, value: T | undefined) {\n const resolvers = this.#promiseResolvers.get(key);\n if (resolvers) {\n this.#promiseResolvers.delete(key);\n resolvers?.forEach((resolve) => resolve(value));\n }\n }\n\n /**\n * Triggers and resolves all pending promises across all keys.\n *\n * This is typically used during shutdown or cleanup to ensure that\n * no consumer is left waiting indefinitely.\n *\n * @param {T | undefined} [value] - Optional value to resolve all waiters with.\n * Defaults to `undefined`, which usually indicates cancellation or shutdown.\n */\n triggerAll(value: T | undefined = undefined) {\n for (const [_, resolvers] of this.#promiseResolvers.entries()) resolvers.forEach((resolve) => resolve(value));\n this.#promiseResolvers.clear();\n }\n\n /**\n * Waits for an event associated with the given key.\n *\n * The returned promise will resolve when:\n * - `trigger(key)` is called, in which case it resolves with the provided value.\n * - The optional timeout is reached, in which case it resolves with `undefined`.\n * - The optional `AbortSignal` is aborted, in which case it resolves with `undefined`.\n *\n * Behavior when multiple waiters exist for the same key:\n * - Default (no mode): multiple waiters are allowed, all will be resolved when triggered.\n * - `strict` mode: throws an error if a waiter already exists for the given key.\n * - `override` mode: cancels all existing waiters (resolving them with `undefined`)\n * and only keeps the latest one.\n *\n * @param {string} key - Identifier for the awaited event\n * @param {number} [timeoutMs] - Optional timeout (in milliseconds).\n * If reached, the promise resolves with `undefined`.\n * @param {'override' | 'strict'} [mode] - Optional behavior mode for handling multiple waiters\n * @param {AbortSignal} [signal] - Optional AbortSignal. If aborted, the promise resolves with `undefined`\n *\n * @returns {Promise<T | undefined>} A promise that resolves with the triggered value,\n * or `undefined` if timeout or abort occurs\n */\n wait(key: string, timeoutMs?: number, mode?: 'override' | 'strict', signal?: AbortSignal) {\n return new Promise<T | undefined>((resolve) => {\n const resolvers = this.#promiseResolvers.get(key) || [];\n if (resolvers.length) {\n switch (mode) {\n case 'override':\n resolvers.forEach((r) => r(undefined));\n resolvers.length = 0;\n break;\n case 'strict':\n throw new Error(`Duplicate wait detected for key: ${key}`);\n }\n }\n\n resolvers.push(resolve);\n this.#promiseResolvers.set(key, resolvers);\n if (timeoutMs != null) {\n setTimeout(\n () => {\n const resolvers = this.#promiseResolvers.get(key);\n if (resolvers?.includes(resolve)) {\n resolve(undefined);\n const newResolvers = resolvers.filter((r) => r !== resolve);\n if (newResolvers.length) this.#promiseResolvers.set(key, newResolvers);\n else this.#promiseResolvers.delete(key);\n }\n },\n timeoutMs,\n );\n }\n\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n const resolvers = this.#promiseResolvers.get(key);\n if (resolvers?.includes(resolve)) {\n resolve(undefined);\n const newResolvers = resolvers.filter((r) => r !== resolve);\n if (newResolvers.length) this.#promiseResolvers.set(key, newResolvers);\n else this.#promiseResolvers.delete(key);\n }\n },\n { once: true },\n );\n }\n });\n }\n\n /**\n * Waits for an event in strict mode.\n * Only one waiter is allowed per key. If another waiter already exists,\n * this method will throw an error.\n *\n * @param {string} key - Identifier for the awaited event\n * @param {number} [timeoutMs] - Optional timeout (in milliseconds).\n * If reached, the promise resolves with `undefined`.\n * @param {AbortSignal} [signal] - Optional AbortSignal. If aborted, the promise resolves with `undefined`\n */\n waitExclusive(key: string, timeoutMs?: number, signal?: AbortSignal) {\n return this.wait(key, timeoutMs, 'strict', signal);\n }\n\n /**\n * Waits for an event in override mode.\n * If another waiter already exists for the given key, it will be canceled\n * (resolved with `undefined`) and replaced by the new waiter.\n *\n * @param {string} key - Identifier for the awaited event\n * @param {number} [timeoutMs] - Optional timeout (in milliseconds).\n * If reached, the promise resolves with `undefined`.\n * @param {AbortSignal} [signal] - Optional AbortSignal. If aborted, the promise resolves with `undefined`\n */\n waitLatest(key: string, timeoutMs?: number, signal?: AbortSignal) {\n return this.wait(key, timeoutMs, 'override', signal);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,IAAa,eAAb,MAA6B;CACzB,oCAAoB,IAAI,IAA6E;;;;;;;;;CAUrG,QAAQ,KAAa,OAAsB;EACvC,MAAM,YAAY,KAAKA,kBAAkB,IAAI,GAAG;EAChD,IAAI,WAAW;GACX,KAAKA,kBAAkB,OAAO,GAAG;GACjC,WAAW,SAAS,YAAY,QAAQ,KAAK,CAAC;EAClD;CACJ;;;;;;;;;;CAWA,WAAW,QAAuB,KAAA,GAAW;EACzC,KAAK,MAAM,CAAC,GAAG,cAAc,KAAKA,kBAAkB,QAAQ,GAAG,UAAU,SAAS,YAAY,QAAQ,KAAK,CAAC;EAC5G,KAAKA,kBAAkB,MAAM;CACjC;;;;;;;;;;;;;;;;;;;;;;;;CAyBA,KAAK,KAAa,WAAoB,MAA8B,QAAsB;EACtF,OAAO,IAAI,SAAwB,YAAY;GAC3C,MAAM,YAAY,KAAKA,kBAAkB,IAAI,GAAG,KAAK,CAAC;GACtD,IAAI,UAAU,QACV,QAAQ,MAAR;IACI,KAAK;KACD,UAAU,SAAS,MAAM,EAAE,KAAA,CAAS,CAAC;KACrC,UAAU,SAAS;KACnB;IACJ,KAAK,UACD,MAAM,IAAI,MAAM,oCAAoC,KAAK;GACjE;GAGJ,UAAU,KAAK,OAAO;GACtB,KAAKA,kBAAkB,IAAI,KAAK,SAAS;GACzC,IAAI,aAAa,MACb,iBACU;IACF,MAAM,YAAY,KAAKA,kBAAkB,IAAI,GAAG;IAChD,IAAI,WAAW,SAAS,OAAO,GAAG;KAC9B,QAAQ,KAAA,CAAS;KACjB,MAAM,eAAe,UAAU,QAAQ,MAAM,MAAM,OAAO;KAC1D,IAAI,aAAa,QAAQ,KAAKA,kBAAkB,IAAI,KAAK,YAAY;UAChE,KAAKA,kBAAkB,OAAO,GAAG;IAC1C;GACJ,GACA,SACJ;GAGJ,IAAI,QACA,OAAO,iBACH,eACM;IACF,MAAM,YAAY,KAAKA,kBAAkB,IAAI,GAAG;IAChD,IAAI,WAAW,SAAS,OAAO,GAAG;KAC9B,QAAQ,KAAA,CAAS;KACjB,MAAM,eAAe,UAAU,QAAQ,MAAM,MAAM,OAAO;KAC1D,IAAI,aAAa,QAAQ,KAAKA,kBAAkB,IAAI,KAAK,YAAY;UAChE,KAAKA,kBAAkB,OAAO,GAAG;IAC1C;GACJ,GACA,EAAE,MAAM,KAAK,CACjB;EAER,CAAC;CACL;;;;;;;;;;;CAYA,cAAc,KAAa,WAAoB,QAAsB;EACjE,OAAO,KAAK,KAAK,KAAK,WAAW,UAAU,MAAM;CACrD;;;;;;;;;;;CAYA,WAAW,KAAa,WAAoB,QAAsB;EAC9D,OAAO,KAAK,KAAK,KAAK,WAAW,YAAY,MAAM;CACvD;AACJ"}
1
+ {"version":3,"file":"event-awaiter.js","names":[],"sources":["../src/event-awaiter.ts"],"sourcesContent":["/**\n * An asynchronous keyed event rendezvous for one or more waiting consumers.\n *\n * @remarks\n * Triggers resolve the currently registered waiters; values are not retained for future waits.\n * Timeouts and subsequent abort events resolve affected waiters with `undefined`.\n * Use `triggerAll` to resolve pending waits during cleanup. Timers and abort listeners are not proactively\n * removed by triggers, so they may remain until their timeout or abort event occurs.\n *\n * @typeParam T - The value delivered to waiting consumers.\n */\nexport class EventAwaiter<T> {\n // Private instance properties\n #promiseResolvers = new Map<string, ((value: PromiseLike<T | undefined> | T | undefined) => void)[]>();\n\n // Public instance methods\n\n /**\n * Resolves all currently pending waits for a key with the supplied value.\n *\n * @param key - The event identifier; a key without pending waits has no effect.\n * @param value - The delivered value; `undefined` indicates no result.\n */\n trigger(key: string, value: T | undefined) {\n const resolvers = this.#promiseResolvers.get(key);\n if (resolvers) {\n this.#promiseResolvers.delete(key);\n resolvers?.forEach((resolve) => resolve(value));\n }\n }\n\n /**\n * Resolves all currently pending waits and clears their registrations.\n *\n * @param value - The delivered value; omission resolves all pending waits with `undefined`.\n */\n triggerAll(value: T | undefined = undefined) {\n for (const [_, resolvers] of this.#promiseResolvers.entries()) resolvers.forEach((resolve) => resolve(value));\n this.#promiseResolvers.clear();\n }\n\n /**\n * Waits for a trigger associated with a key.\n *\n * @remarks\n * By default, multiple waiters share a key and all receive the next trigger value.\n * `strict` mode rejects duplicate waits; `override` mode resolves existing waits with `undefined` before\n * registering the new wait. Timeout and abort remove only the affected waiter's registration.\n * An already aborted signal is not checked; only an abort event emitted after registration ends the wait.\n * Without a timeout or subsequent abort, the wait remains pending until a trigger arrives.\n *\n * @param key - The event identifier to wait for.\n * @param timeoutMs - The optional timeout in milliseconds, using native `setTimeout` timing rules.\n * @param mode - The policy for existing waiters; omission allows multiple waiters.\n * @param signal - A signal whose subsequent abort event ends this wait.\n *\n * @returns A promise resolving to the triggered value, or `undefined` after timeout, abort, or replacement.\n *\n * @throws Error through promise rejection if `strict` mode encounters an existing waiter.\n */\n wait(key: string, timeoutMs?: number, mode?: 'override' | 'strict', signal?: AbortSignal) {\n return new Promise<T | undefined>((resolve) => {\n const resolvers = this.#promiseResolvers.get(key) || [];\n if (resolvers.length) {\n switch (mode) {\n case 'override':\n resolvers.forEach((r) => r(undefined));\n resolvers.length = 0;\n break;\n case 'strict':\n throw new Error(`Duplicate wait detected for key: ${key}`);\n }\n }\n\n resolvers.push(resolve);\n this.#promiseResolvers.set(key, resolvers);\n if (timeoutMs != null) {\n setTimeout(\n () => {\n const resolvers = this.#promiseResolvers.get(key);\n if (resolvers?.includes(resolve)) {\n resolve(undefined);\n const newResolvers = resolvers.filter((r) => r !== resolve);\n if (newResolvers.length) this.#promiseResolvers.set(key, newResolvers);\n else this.#promiseResolvers.delete(key);\n }\n },\n timeoutMs,\n );\n }\n\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n const resolvers = this.#promiseResolvers.get(key);\n if (resolvers?.includes(resolve)) {\n resolve(undefined);\n const newResolvers = resolvers.filter((r) => r !== resolve);\n if (newResolvers.length) this.#promiseResolvers.set(key, newResolvers);\n else this.#promiseResolvers.delete(key);\n }\n },\n { once: true },\n );\n }\n });\n }\n\n /**\n * Waits for a key while rejecting duplicate registrations.\n *\n * @param key - The event identifier to wait for.\n * @param timeoutMs - The optional timeout in milliseconds.\n * @param signal - A signal whose subsequent abort event ends this wait; an already aborted signal is not checked.\n *\n * @returns A promise resolving to the triggered value, or `undefined` on timeout or subsequent abort.\n *\n * @throws Error through promise rejection if the key already has a pending waiter.\n *\n * @see {@link EventAwaiter.wait}\n */\n waitExclusive(key: string, timeoutMs?: number, signal?: AbortSignal) {\n return this.wait(key, timeoutMs, 'strict', signal);\n }\n\n /**\n * Replaces existing waiters for a key and waits for its next trigger.\n *\n * @remarks\n * Existing waiters resolve with `undefined` before the new waiter is registered.\n *\n * @param key - The event identifier to wait for.\n * @param timeoutMs - The optional timeout in milliseconds.\n * @param signal - A signal whose subsequent abort event ends this wait; an already aborted signal is not checked.\n *\n * @returns A promise resolving to the triggered value, or `undefined` on timeout, subsequent abort, or replacement.\n *\n * @see {@link EventAwaiter.wait}\n */\n waitLatest(key: string, timeoutMs?: number, signal?: AbortSignal) {\n return this.wait(key, timeoutMs, 'override', signal);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAWA,IAAa,eAAb,MAA6B;CAEzB,oCAAoB,IAAI,IAA6E;;;;;;;CAUrG,QAAQ,KAAa,OAAsB;EACvC,MAAM,YAAY,KAAK,kBAAkB,IAAI,GAAG;EAChD,IAAI,WAAW;GACX,KAAK,kBAAkB,OAAO,GAAG;GACjC,WAAW,SAAS,YAAY,QAAQ,KAAK,CAAC;EAClD;CACJ;;;;;;CAOA,WAAW,QAAuB,KAAA,GAAW;EACzC,KAAK,MAAM,CAAC,GAAG,cAAc,KAAK,kBAAkB,QAAQ,GAAG,UAAU,SAAS,YAAY,QAAQ,KAAK,CAAC;EAC5G,KAAK,kBAAkB,MAAM;CACjC;;;;;;;;;;;;;;;;;;;;CAqBA,KAAK,KAAa,WAAoB,MAA8B,QAAsB;EACtF,OAAO,IAAI,SAAwB,YAAY;GAC3C,MAAM,YAAY,KAAK,kBAAkB,IAAI,GAAG,KAAK,CAAC;GACtD,IAAI,UAAU,QACV,QAAQ,MAAR;IACI,KAAK;KACD,UAAU,SAAS,MAAM,EAAE,KAAA,CAAS,CAAC;KACrC,UAAU,SAAS;KACnB;IACJ,KAAK,UACD,MAAM,IAAI,MAAM,oCAAoC,KAAK;GACjE;GAGJ,UAAU,KAAK,OAAO;GACtB,KAAK,kBAAkB,IAAI,KAAK,SAAS;GACzC,IAAI,aAAa,MACb,iBACU;IACF,MAAM,YAAY,KAAK,kBAAkB,IAAI,GAAG;IAChD,IAAI,WAAW,SAAS,OAAO,GAAG;KAC9B,QAAQ,KAAA,CAAS;KACjB,MAAM,eAAe,UAAU,QAAQ,MAAM,MAAM,OAAO;KAC1D,IAAI,aAAa,QAAQ,KAAK,kBAAkB,IAAI,KAAK,YAAY;UAChE,KAAK,kBAAkB,OAAO,GAAG;IAC1C;GACJ,GACA,SACJ;GAGJ,IAAI,QACA,OAAO,iBACH,eACM;IACF,MAAM,YAAY,KAAK,kBAAkB,IAAI,GAAG;IAChD,IAAI,WAAW,SAAS,OAAO,GAAG;KAC9B,QAAQ,KAAA,CAAS;KACjB,MAAM,eAAe,UAAU,QAAQ,MAAM,MAAM,OAAO;KAC1D,IAAI,aAAa,QAAQ,KAAK,kBAAkB,IAAI,KAAK,YAAY;UAChE,KAAK,kBAAkB,OAAO,GAAG;IAC1C;GACJ,GACA,EAAE,MAAM,KAAK,CACjB;EAER,CAAC;CACL;;;;;;;;;;;;;;CAeA,cAAc,KAAa,WAAoB,QAAsB;EACjE,OAAO,KAAK,KAAK,KAAK,WAAW,UAAU,MAAM;CACrD;;;;;;;;;;;;;;;CAgBA,WAAW,KAAa,WAAoB,QAAsB;EAC9D,OAAO,KAAK,KAAK,KAAK,WAAW,YAAY,MAAM;CACvD;AACJ"}
package/dist/general.d.ts CHANGED
@@ -1,31 +1,36 @@
1
1
  //#region src/general.d.ts
2
2
  /**
3
- * Extracts the first value from an array or returns the value itself if it's not an array.
3
+ * Returns the first array element or the input value, with a nullish fallback.
4
4
  *
5
- * - If `value` is an array, returns the first element.
6
- * - If `value` is not an array, returns `value` directly.
7
- * - If the result is `null` or `undefined`, and `defaultValue` is provided, returns `defaultValue` instead.
5
+ * @remarks
6
+ * An empty array, `null`, or `undefined` selects the fallback; omission of a fallback yields `undefined`.
7
+ * The input and selected values are not copied or changed.
8
8
  *
9
- * @template T - The type of the input value(s)
10
- * @template D - The type of the default value (if provided)
9
+ * @typeParam T - The input value or array element type.
10
+ * @typeParam D - The fallback type when the fallback overload is used.
11
11
  *
12
- * @param {T | T[]} value - A single value or an array of values
13
- * @param {D} [defaultValue] - A fallback value if the result is `null` or `undefined`
12
+ * @param value - A single value or an array of values.
13
+ * @param defaultValue - The fallback returned when the selected value is nullish.
14
14
  *
15
- * @returns {T | D | undefined} The first value or the fallback
15
+ * @returns The selected non-nullish value, or the fallback without copying either value.
16
16
  *
17
17
  * @example
18
- * ```typescript
18
+ *
19
+ * ```ts
19
20
  * import { extractFirstValue } from '@kikiutils/shared/general';
20
21
  *
21
- * console.log(extractFirstValue([1, 2, 3])); // 1
22
- * console.log(extractFirstValue('hello')); // hello
23
- * console.log(extractFirstValue([], 'default')); // default
24
- * console.log(extractFirstValue(undefined, 'fallback')); // fallback
22
+ * console.log(extractFirstValue([
23
+ * 1,
24
+ * 2,
25
+ * 3,
26
+ * ])); // => 1
27
+ *
28
+ * console.log(extractFirstValue('hello')); // => 'hello'
29
+ * console.log(extractFirstValue([], 'default')); // => 'default'
30
+ * console.log(extractFirstValue(undefined, 'fallback')); // => 'fallback'
25
31
  * ```
26
32
  */
27
- declare function extractFirstValue<T>(value: T | T[]): T | undefined;
28
- declare function extractFirstValue<T, D>(value: T | T[], defaultValue: D): D | NonNullable<T>;
33
+ export declare function extractFirstValue<T>(value: T | T[]): T | undefined;
34
+ export declare function extractFirstValue<T, D>(value: T | T[], defaultValue: D): D | NonNullable<T>;
29
35
  //#endregion
30
- export { extractFirstValue };
31
36
  //# sourceMappingURL=general.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"general.d.ts","names":[],"sources":["../src/general.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;iBA2BgB,kBAAkB,GAAG,OAAO,IAAI,MAAM;iBACtC,kBAAkB,GAAG,GAAG,OAAO,IAAI,KAAK,cAAc,IAAI,IAAI,YAAY"}
1
+ {"version":3,"file":"general.d.ts","names":[],"sources":["../src/general.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiCgB,kBAAkB,GAAG,OAAO,IAAI,MAAM;wBACtC,kBAAkB,GAAG,GAAG,OAAO,IAAI,KAAK,cAAc,IAAI,IAAI,YAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"general.js","names":[],"sources":["../src/general.ts"],"sourcesContent":["/* eslint-disable jsdoc/check-param-names */\n\n/**\n * Extracts the first value from an array or returns the value itself if it's not an array.\n *\n * - If `value` is an array, returns the first element.\n * - If `value` is not an array, returns `value` directly.\n * - If the result is `null` or `undefined`, and `defaultValue` is provided, returns `defaultValue` instead.\n *\n * @template T - The type of the input value(s)\n * @template D - The type of the default value (if provided)\n *\n * @param {T | T[]} value - A single value or an array of values\n * @param {D} [defaultValue] - A fallback value if the result is `null` or `undefined`\n *\n * @returns {T | D | undefined} The first value or the fallback\n *\n * @example\n * ```typescript\n * import { extractFirstValue } from '@kikiutils/shared/general';\n *\n * console.log(extractFirstValue([1, 2, 3])); // 1\n * console.log(extractFirstValue('hello')); // hello\n * console.log(extractFirstValue([], 'default')); // default\n * console.log(extractFirstValue(undefined, 'fallback')); // fallback\n * ```\n */\nexport function extractFirstValue<T>(value: T | T[]): T | undefined;\nexport function extractFirstValue<T, D>(value: T | T[], defaultValue: D): D | NonNullable<T>;\nexport function extractFirstValue<T, D>(value: T | T[], defaultValue?: D) {\n return (Array.isArray(value) ? value[0] : value) ?? defaultValue;\n}\n\n/* eslint-enable jsdoc/check-param-names */\n"],"mappings":";AA6BA,SAAgB,kBAAwB,OAAgB,cAAkB;CACtE,QAAQ,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,UAAU;AACxD"}
1
+ {"version":3,"file":"general.js","names":[],"sources":["../src/general.ts"],"sourcesContent":["/* eslint-disable jsdoc/check-param-names */\n\n/**\n * Returns the first array element or the input value, with a nullish fallback.\n *\n * @remarks\n * An empty array, `null`, or `undefined` selects the fallback; omission of a fallback yields `undefined`.\n * The input and selected values are not copied or changed.\n *\n * @typeParam T - The input value or array element type.\n * @typeParam D - The fallback type when the fallback overload is used.\n *\n * @param value - A single value or an array of values.\n * @param defaultValue - The fallback returned when the selected value is nullish.\n *\n * @returns The selected non-nullish value, or the fallback without copying either value.\n *\n * @example\n *\n * ```ts\n * import { extractFirstValue } from '@kikiutils/shared/general';\n *\n * console.log(extractFirstValue([\n * 1,\n * 2,\n * 3,\n * ])); // => 1\n *\n * console.log(extractFirstValue('hello')); // => 'hello'\n * console.log(extractFirstValue([], 'default')); // => 'default'\n * console.log(extractFirstValue(undefined, 'fallback')); // => 'fallback'\n * ```\n */\nexport function extractFirstValue<T>(value: T | T[]): T | undefined;\nexport function extractFirstValue<T, D>(value: T | T[], defaultValue: D): D | NonNullable<T>;\nexport function extractFirstValue<T, D>(value: T | T[], defaultValue?: D) {\n return (Array.isArray(value) ? value[0] : value) ?? defaultValue;\n}\n\n/* eslint-enable jsdoc/check-param-names */\n"],"mappings":";AAmCA,SAAgB,kBAAwB,OAAgB,cAAkB;CACtE,QAAQ,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,UAAU;AACxD"}
package/dist/hash.d.ts CHANGED
@@ -2,63 +2,66 @@
2
2
  /**
3
3
  * Computes the SHA-3 hash of the given data using the 224-bit digest.
4
4
  *
5
- * @param {string | Uint8Array} data - The input data to hash
5
+ * @param data - The UTF-8 string or raw bytes to hash.
6
6
  *
7
- * @returns {string} The hexadecimal hash digest
7
+ * @returns The hexadecimal hash digest.
8
8
  *
9
9
  * @example
10
- * ```typescript
10
+ *
11
+ * ```ts
11
12
  * import { sha3224 } from '@kikiutils/shared/hash';
12
13
  *
13
- * console.log(sha3224('test')); // 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
14
+ * console.log(sha3224('test')); // => 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
14
15
  * ```
15
16
  */
16
- declare function sha3224(data: string | Uint8Array): string;
17
+ export declare function sha3224(data: string | Uint8Array): string;
17
18
  /**
18
19
  * Computes the SHA-3 hash of the given data using the 256-bit digest.
19
20
  *
20
- * @param {string | Uint8Array} data - The input data to hash
21
+ * @param data - The UTF-8 string or raw bytes to hash.
21
22
  *
22
- * @returns {string} The hexadecimal hash digest
23
+ * @returns The hexadecimal hash digest.
23
24
  *
24
25
  * @example
25
- * ```typescript
26
+ *
27
+ * ```ts
26
28
  * import { sha3256 } from '@kikiutils/shared/hash';
27
29
  *
28
- * console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
30
+ * console.log(sha3256('test')); // => 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
29
31
  * ```
30
32
  */
31
- declare function sha3256(data: string | Uint8Array): string;
33
+ export declare function sha3256(data: string | Uint8Array): string;
32
34
  /**
33
35
  * Computes the SHA-3 hash of the given data using the 384-bit digest.
34
36
  *
35
- * @param {string | Uint8Array} data - The input data to hash
37
+ * @param data - The UTF-8 string or raw bytes to hash.
36
38
  *
37
- * @returns {string} The hexadecimal hash digest
39
+ * @returns The hexadecimal hash digest.
38
40
  *
39
41
  * @example
40
- * ```typescript
42
+ *
43
+ * ```ts
41
44
  * import { sha3384 } from '@kikiutils/shared/hash';
42
45
  *
43
- * console.log(sha3384('test')); // e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
46
+ * console.log(sha3384('test')); // => e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
44
47
  * ```
45
48
  */
46
- declare function sha3384(data: string | Uint8Array): string;
49
+ export declare function sha3384(data: string | Uint8Array): string;
47
50
  /**
48
51
  * Computes the SHA-3 hash of the given data using the 512-bit digest.
49
52
  *
50
- * @param {string | Uint8Array} data - The input data to hash
53
+ * @param data - The UTF-8 string or raw bytes to hash.
51
54
  *
52
- * @returns {string} The hexadecimal hash digest
55
+ * @returns The hexadecimal hash digest.
53
56
  *
54
57
  * @example
55
- * ```typescript
58
+ *
59
+ * ```ts
56
60
  * import { sha3512 } from '@kikiutils/shared/hash';
57
61
  *
58
- * console.log(sha3512('test')); // 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
62
+ * console.log(sha3512('test')); // => 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
59
63
  * ```
60
64
  */
61
- declare function sha3512(data: string | Uint8Array): string;
65
+ export declare function sha3512(data: string | Uint8Array): string;
62
66
  //#endregion
63
- export { sha3224, sha3256, sha3384, sha3512 };
64
67
  //# sourceMappingURL=hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","names":[],"sources":["../src/hash.ts"],"mappings":";;;;;;;;;;;;;;;iBAyBgB,QAAQ,eAAe;;;;;;;;;;;;;;;iBAkBvB,QAAQ,eAAe;;;;;;;;;;;;;;;iBAkBvB,QAAQ,eAAe;;;;;;;;;;;;;;;iBAkBvB,QAAQ,eAAe"}
1
+ {"version":3,"file":"hash.d.ts","names":[],"sources":["../src/hash.ts"],"mappings":";;;;;;;;;;;;;;;;wBA0BgB,QAAQ,eAAe;;;;;;;;;;;;;;;;wBAmBvB,QAAQ,eAAe;;;;;;;;;;;;;;;;wBAmBvB,QAAQ,eAAe;;;;;;;;;;;;;;;;wBAmBvB,QAAQ,eAAe"}
package/dist/hash.js CHANGED
@@ -4,15 +4,16 @@ import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
4
4
  /**
5
5
  * Computes the SHA-3 hash of the given data using the 224-bit digest.
6
6
  *
7
- * @param {string | Uint8Array} data - The input data to hash
7
+ * @param data - The UTF-8 string or raw bytes to hash.
8
8
  *
9
- * @returns {string} The hexadecimal hash digest
9
+ * @returns The hexadecimal hash digest.
10
10
  *
11
11
  * @example
12
- * ```typescript
12
+ *
13
+ * ```ts
13
14
  * import { sha3224 } from '@kikiutils/shared/hash';
14
15
  *
15
- * console.log(sha3224('test')); // 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
16
+ * console.log(sha3224('test')); // => 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
16
17
  * ```
17
18
  */
18
19
  function sha3224(data) {
@@ -21,15 +22,16 @@ function sha3224(data) {
21
22
  /**
22
23
  * Computes the SHA-3 hash of the given data using the 256-bit digest.
23
24
  *
24
- * @param {string | Uint8Array} data - The input data to hash
25
+ * @param data - The UTF-8 string or raw bytes to hash.
25
26
  *
26
- * @returns {string} The hexadecimal hash digest
27
+ * @returns The hexadecimal hash digest.
27
28
  *
28
29
  * @example
29
- * ```typescript
30
+ *
31
+ * ```ts
30
32
  * import { sha3256 } from '@kikiutils/shared/hash';
31
33
  *
32
- * console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
34
+ * console.log(sha3256('test')); // => 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
33
35
  * ```
34
36
  */
35
37
  function sha3256(data) {
@@ -38,15 +40,16 @@ function sha3256(data) {
38
40
  /**
39
41
  * Computes the SHA-3 hash of the given data using the 384-bit digest.
40
42
  *
41
- * @param {string | Uint8Array} data - The input data to hash
43
+ * @param data - The UTF-8 string or raw bytes to hash.
42
44
  *
43
- * @returns {string} The hexadecimal hash digest
45
+ * @returns The hexadecimal hash digest.
44
46
  *
45
47
  * @example
46
- * ```typescript
48
+ *
49
+ * ```ts
47
50
  * import { sha3384 } from '@kikiutils/shared/hash';
48
51
  *
49
- * console.log(sha3384('test')); // e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
52
+ * console.log(sha3384('test')); // => e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
50
53
  * ```
51
54
  */
52
55
  function sha3384(data) {
@@ -55,15 +58,16 @@ function sha3384(data) {
55
58
  /**
56
59
  * Computes the SHA-3 hash of the given data using the 512-bit digest.
57
60
  *
58
- * @param {string | Uint8Array} data - The input data to hash
61
+ * @param data - The UTF-8 string or raw bytes to hash.
59
62
  *
60
- * @returns {string} The hexadecimal hash digest
63
+ * @returns The hexadecimal hash digest.
61
64
  *
62
65
  * @example
63
- * ```typescript
66
+ *
67
+ * ```ts
64
68
  * import { sha3512 } from '@kikiutils/shared/hash';
65
69
  *
66
- * console.log(sha3512('test')); // 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
70
+ * console.log(sha3512('test')); // => 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
67
71
  * ```
68
72
  */
69
73
  function sha3512(data) {
package/dist/hash.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hash.js","names":[],"sources":["../src/hash.ts"],"sourcesContent":["import {\n sha3_224,\n sha3_256,\n sha3_384,\n sha3_512,\n} from '@noble/hashes/sha3.js';\nimport {\n bytesToHex,\n utf8ToBytes,\n} from '@noble/hashes/utils.js';\n\n/**\n * Computes the SHA-3 hash of the given data using the 224-bit digest.\n *\n * @param {string | Uint8Array} data - The input data to hash\n *\n * @returns {string} The hexadecimal hash digest\n *\n * @example\n * ```typescript\n * import { sha3224 } from '@kikiutils/shared/hash';\n *\n * console.log(sha3224('test')); // 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b\n * ```\n */\nexport function sha3224(data: string | Uint8Array) {\n return bytesToHex(sha3_224(typeof data === 'string' ? utf8ToBytes(data) : data));\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 256-bit digest.\n *\n * @param {string | Uint8Array} data - The input data to hash\n *\n * @returns {string} The hexadecimal hash digest\n *\n * @example\n * ```typescript\n * import { sha3256 } from '@kikiutils/shared/hash';\n *\n * console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80\n * ```\n */\nexport function sha3256(data: string | Uint8Array) {\n return bytesToHex(sha3_256(typeof data === 'string' ? utf8ToBytes(data) : data));\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 384-bit digest.\n *\n * @param {string | Uint8Array} data - The input data to hash\n *\n * @returns {string} The hexadecimal hash digest\n *\n * @example\n * ```typescript\n * import { sha3384 } from '@kikiutils/shared/hash';\n *\n * console.log(sha3384('test')); // e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...\n * ```\n */\nexport function sha3384(data: string | Uint8Array) {\n return bytesToHex(sha3_384(typeof data === 'string' ? utf8ToBytes(data) : data));\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 512-bit digest.\n *\n * @param {string | Uint8Array} data - The input data to hash\n *\n * @returns {string} The hexadecimal hash digest\n *\n * @example\n * ```typescript\n * import { sha3512 } from '@kikiutils/shared/hash';\n *\n * console.log(sha3512('test')); // 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...\n * ```\n */\nexport function sha3512(data: string | Uint8Array) {\n return bytesToHex(sha3_512(typeof data === 'string' ? utf8ToBytes(data) : data));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,SAAgB,QAAQ,MAA2B;CAC/C,OAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,IAAI,IAAI,IAAI,CAAC;AACnF;;;;;;;;;;;;;;;AAgBA,SAAgB,QAAQ,MAA2B;CAC/C,OAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,IAAI,IAAI,IAAI,CAAC;AACnF;;;;;;;;;;;;;;;AAgBA,SAAgB,QAAQ,MAA2B;CAC/C,OAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,IAAI,IAAI,IAAI,CAAC;AACnF;;;;;;;;;;;;;;;AAgBA,SAAgB,QAAQ,MAA2B;CAC/C,OAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,IAAI,IAAI,IAAI,CAAC;AACnF"}
1
+ {"version":3,"file":"hash.js","names":[],"sources":["../src/hash.ts"],"sourcesContent":["import {\n sha3_224,\n sha3_256,\n sha3_384,\n sha3_512,\n} from '@noble/hashes/sha3.js';\nimport {\n bytesToHex,\n utf8ToBytes,\n} from '@noble/hashes/utils.js';\n\n/**\n * Computes the SHA-3 hash of the given data using the 224-bit digest.\n *\n * @param data - The UTF-8 string or raw bytes to hash.\n *\n * @returns The hexadecimal hash digest.\n *\n * @example\n *\n * ```ts\n * import { sha3224 } from '@kikiutils/shared/hash';\n *\n * console.log(sha3224('test')); // => 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b\n * ```\n */\nexport function sha3224(data: string | Uint8Array) {\n return bytesToHex(sha3_224(typeof data === 'string' ? utf8ToBytes(data) : data));\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 256-bit digest.\n *\n * @param data - The UTF-8 string or raw bytes to hash.\n *\n * @returns The hexadecimal hash digest.\n *\n * @example\n *\n * ```ts\n * import { sha3256 } from '@kikiutils/shared/hash';\n *\n * console.log(sha3256('test')); // => 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80\n * ```\n */\nexport function sha3256(data: string | Uint8Array) {\n return bytesToHex(sha3_256(typeof data === 'string' ? utf8ToBytes(data) : data));\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 384-bit digest.\n *\n * @param data - The UTF-8 string or raw bytes to hash.\n *\n * @returns The hexadecimal hash digest.\n *\n * @example\n *\n * ```ts\n * import { sha3384 } from '@kikiutils/shared/hash';\n *\n * console.log(sha3384('test')); // => e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...\n * ```\n */\nexport function sha3384(data: string | Uint8Array) {\n return bytesToHex(sha3_384(typeof data === 'string' ? utf8ToBytes(data) : data));\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 512-bit digest.\n *\n * @param data - The UTF-8 string or raw bytes to hash.\n *\n * @returns The hexadecimal hash digest.\n *\n * @example\n *\n * ```ts\n * import { sha3512 } from '@kikiutils/shared/hash';\n *\n * console.log(sha3512('test')); // => 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...\n * ```\n */\nexport function sha3512(data: string | Uint8Array) {\n return bytesToHex(sha3_512(typeof data === 'string' ? utf8ToBytes(data) : data));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0BA,SAAgB,QAAQ,MAA2B;CAC/C,OAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,IAAI,IAAI,IAAI,CAAC;AACnF;;;;;;;;;;;;;;;;AAiBA,SAAgB,QAAQ,MAA2B;CAC/C,OAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,IAAI,IAAI,IAAI,CAAC;AACnF;;;;;;;;;;;;;;;;AAiBA,SAAgB,QAAQ,MAA2B;CAC/C,OAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,IAAI,IAAI,IAAI,CAAC;AACnF;;;;;;;;;;;;;;;;AAiBA,SAAgB,QAAQ,MAA2B;CAC/C,OAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,IAAI,IAAI,IAAI,CAAC;AACnF"}
package/dist/math.d.ts CHANGED
@@ -6,43 +6,44 @@ type CalculableValue = Decimal.Value | {
6
6
  /**
7
7
  * Options for configuring the output of `toPercentageString`.
8
8
  */
9
- interface ToPercentageStringOptions {
9
+ export interface ToPercentageStringOptions {
10
10
  /**
11
- * Number of decimal places to include in the result.
11
+ * The number of decimal places to include in the result.
12
12
  *
13
- * @default 2
13
+ * @defaultValue 2
14
14
  */
15
15
  decimalPlaces?: number;
16
16
  /**
17
- * Whether to include the '%' symbol in the result.
17
+ * Whether to include the `%` symbol in the result.
18
18
  *
19
- * @default true
19
+ * @defaultValue true
20
20
  */
21
21
  withSymbol?: boolean;
22
22
  }
23
23
  /**
24
- * Converts a fraction (numerator / denominator) into a percentage string.
24
+ * Converts a numerator and denominator into a formatted percentage.
25
25
  *
26
- * - Uses `decimal.js` for precise decimal calculations.
27
- * - Supports custom decimal places and optional percentage symbol.
28
- * - Returns `'0.00%'` if result is `NaN` or division is invalid.
26
+ * @remarks
27
+ * A `NaN` or infinite quotient produces `0.00`, regardless of the configured decimal places;
28
+ * the percent symbol is appended according to `options.withSymbol`.
29
+ * Invalid decimal input and formatting options propagate decimal.js exceptions.
29
30
  *
30
- * @param {CalculableValue} molecular - The numerator of the fraction
31
- * @param {CalculableValue} denominator - The denominator of the fraction
32
- * @param {ToPercentageStringOptions} [options] - Optional output settings
31
+ * @param molecular - The numerator of the fraction.
32
+ * @param denominator - The denominator of the fraction.
33
+ * @param options - Output precision and percent-symbol settings.
33
34
  *
34
- * @returns {string} Formatted percentage string
35
+ * @returns The formatted percentage string.
35
36
  *
36
37
  * @example
37
- * ```typescript
38
+ *
39
+ * ```ts
38
40
  * import { toPercentageString } from '@kikiutils/shared/math';
39
41
  *
40
- * console.log(toPercentageString(50, 200)); // 25.00%
41
- * console.log(toPercentageString(50, 200, { withSymbol: false })); // 25.00
42
- * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // 25.0%
42
+ * console.log(toPercentageString(50, 200)); // => '25.00%'
43
+ * console.log(toPercentageString(50, 200, { withSymbol: false })); // => '25.00'
44
+ * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // => '25.0%'
43
45
  * ```
44
46
  */
45
- declare function toPercentageString(molecular: CalculableValue, denominator: CalculableValue, options?: ToPercentageStringOptions): string;
47
+ export declare function toPercentageString(molecular: CalculableValue, denominator: CalculableValue, options?: ToPercentageStringOptions): string;
46
48
  //#endregion
47
- export { ToPercentageStringOptions, toPercentageString };
48
49
  //# sourceMappingURL=math.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"math.d.ts","names":[],"sources":["../src/math.ts"],"mappings":";;KAEK,kBAAkB,QAAQ;EAAU;;;;;UAKxB;;;;;;EAMb;;;;;;EAOA;;;;;;;;;;;;;;;;;;;;;;;;iBAyBY,mBACZ,WAAW,iBACX,aAAa,iBACb,UAAU"}
1
+ {"version":3,"file":"math.d.ts","names":[],"sources":["../src/math.ts"],"mappings":";;KAEK,kBAAkB,QAAQ;EAAU;;;;;iBAKxB;;;;;;EAMb;;;;;;EAOA;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2BY,mBACZ,WAAW,iBACX,aAAa,iBACb,UAAU"}
package/dist/math.js CHANGED
@@ -1,25 +1,27 @@
1
1
  import { Decimal } from "decimal.js";
2
2
  //#region src/math.ts
3
3
  /**
4
- * Converts a fraction (numerator / denominator) into a percentage string.
4
+ * Converts a numerator and denominator into a formatted percentage.
5
5
  *
6
- * - Uses `decimal.js` for precise decimal calculations.
7
- * - Supports custom decimal places and optional percentage symbol.
8
- * - Returns `'0.00%'` if result is `NaN` or division is invalid.
6
+ * @remarks
7
+ * A `NaN` or infinite quotient produces `0.00`, regardless of the configured decimal places;
8
+ * the percent symbol is appended according to `options.withSymbol`.
9
+ * Invalid decimal input and formatting options propagate decimal.js exceptions.
9
10
  *
10
- * @param {CalculableValue} molecular - The numerator of the fraction
11
- * @param {CalculableValue} denominator - The denominator of the fraction
12
- * @param {ToPercentageStringOptions} [options] - Optional output settings
11
+ * @param molecular - The numerator of the fraction.
12
+ * @param denominator - The denominator of the fraction.
13
+ * @param options - Output precision and percent-symbol settings.
13
14
  *
14
- * @returns {string} Formatted percentage string
15
+ * @returns The formatted percentage string.
15
16
  *
16
17
  * @example
17
- * ```typescript
18
+ *
19
+ * ```ts
18
20
  * import { toPercentageString } from '@kikiutils/shared/math';
19
21
  *
20
- * console.log(toPercentageString(50, 200)); // 25.00%
21
- * console.log(toPercentageString(50, 200, { withSymbol: false })); // 25.00
22
- * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // 25.0%
22
+ * console.log(toPercentageString(50, 200)); // => '25.00%'
23
+ * console.log(toPercentageString(50, 200, { withSymbol: false })); // => '25.00'
24
+ * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // => '25.0%'
23
25
  * ```
24
26
  */
25
27
  function toPercentageString(molecular, denominator, options) {
package/dist/math.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"math.js","names":[],"sources":["../src/math.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\n\ntype CalculableValue = Decimal.Value | { toString: () => string };\n\n/**\n * Options for configuring the output of `toPercentageString`.\n */\nexport interface ToPercentageStringOptions {\n /**\n * Number of decimal places to include in the result.\n *\n * @default 2\n */\n decimalPlaces?: number;\n\n /**\n * Whether to include the '%' symbol in the result.\n *\n * @default true\n */\n withSymbol?: boolean;\n}\n\n/**\n * Converts a fraction (numerator / denominator) into a percentage string.\n *\n * - Uses `decimal.js` for precise decimal calculations.\n * - Supports custom decimal places and optional percentage symbol.\n * - Returns `'0.00%'` if result is `NaN` or division is invalid.\n *\n * @param {CalculableValue} molecular - The numerator of the fraction\n * @param {CalculableValue} denominator - The denominator of the fraction\n * @param {ToPercentageStringOptions} [options] - Optional output settings\n *\n * @returns {string} Formatted percentage string\n *\n * @example\n * ```typescript\n * import { toPercentageString } from '@kikiutils/shared/math';\n *\n * console.log(toPercentageString(50, 200)); // 25.00%\n * console.log(toPercentageString(50, 200, { withSymbol: false })); // 25.00\n * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // 25.0%\n * ```\n */\nexport function toPercentageString(\n molecular: CalculableValue,\n denominator: CalculableValue,\n options?: ToPercentageStringOptions,\n) {\n const molecularDecimal = new Decimal(molecular.toString());\n const denominatorDecimal = new Decimal(denominator.toString());\n const calculationResult = molecularDecimal.div(denominatorDecimal);\n\n const result = calculationResult.isNaN() || !calculationResult.isFinite()\n ? '0.00'\n : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);\n\n return options?.withSymbol ?? true ? `${result}%` : result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,mBACZ,WACA,aACA,SACF;CACE,MAAM,mBAAmB,IAAI,QAAQ,UAAU,SAAS,CAAC;CACzD,MAAM,qBAAqB,IAAI,QAAQ,YAAY,SAAS,CAAC;CAC7D,MAAM,oBAAoB,iBAAiB,IAAI,kBAAkB;CAEjE,MAAM,SAAS,kBAAkB,MAAM,KAAK,CAAC,kBAAkB,SAAS,IAClE,SACA,kBAAkB,MAAM,GAAG,CAAC,CAAC,QAAQ,SAAS,iBAAiB,CAAC;CAEtE,OAAO,SAAS,cAAc,OAAO,GAAG,OAAO,KAAK;AACxD"}
1
+ {"version":3,"file":"math.js","names":[],"sources":["../src/math.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\n\ntype CalculableValue = Decimal.Value | { toString: () => string };\n\n/**\n * Options for configuring the output of `toPercentageString`.\n */\nexport interface ToPercentageStringOptions {\n /**\n * The number of decimal places to include in the result.\n *\n * @defaultValue 2\n */\n decimalPlaces?: number;\n\n /**\n * Whether to include the `%` symbol in the result.\n *\n * @defaultValue true\n */\n withSymbol?: boolean;\n}\n\n/**\n * Converts a numerator and denominator into a formatted percentage.\n *\n * @remarks\n * A `NaN` or infinite quotient produces `0.00`, regardless of the configured decimal places;\n * the percent symbol is appended according to `options.withSymbol`.\n * Invalid decimal input and formatting options propagate decimal.js exceptions.\n *\n * @param molecular - The numerator of the fraction.\n * @param denominator - The denominator of the fraction.\n * @param options - Output precision and percent-symbol settings.\n *\n * @returns The formatted percentage string.\n *\n * @example\n *\n * ```ts\n * import { toPercentageString } from '@kikiutils/shared/math';\n *\n * console.log(toPercentageString(50, 200)); // => '25.00%'\n * console.log(toPercentageString(50, 200, { withSymbol: false })); // => '25.00'\n * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // => '25.0%'\n * ```\n */\nexport function toPercentageString(\n molecular: CalculableValue,\n denominator: CalculableValue,\n options?: ToPercentageStringOptions,\n) {\n const molecularDecimal = new Decimal(molecular.toString());\n const denominatorDecimal = new Decimal(denominator.toString());\n const calculationResult = molecularDecimal.div(denominatorDecimal);\n\n const result = calculationResult.isNaN() || !calculationResult.isFinite()\n ? '0.00'\n : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);\n\n return options?.withSymbol ?? true ? `${result}%` : result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,mBACZ,WACA,aACA,SACF;CACE,MAAM,mBAAmB,IAAI,QAAQ,UAAU,SAAS,CAAC;CACzD,MAAM,qBAAqB,IAAI,QAAQ,YAAY,SAAS,CAAC;CAC7D,MAAM,oBAAoB,iBAAiB,IAAI,kBAAkB;CAEjE,MAAM,SAAS,kBAAkB,MAAM,KAAK,CAAC,kBAAkB,SAAS,IAClE,SACA,kBAAkB,MAAM,GAAG,CAAC,CAAC,QAAQ,SAAS,iBAAiB,CAAC;CAEtE,OAAO,SAAS,cAAc,OAAO,GAAG,OAAO,KAAK;AACxD"}
package/dist/number.d.ts CHANGED
@@ -3,22 +3,23 @@ import { millify } from "millify";
3
3
  /**
4
4
  * Converts a large number into a compact, human-readable string using `millify`.
5
5
  *
6
- * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.
6
+ * @remarks
7
+ * Uses lowercase units, for example `k` and `m`, and a precision of `2` unless overridden.
7
8
  *
8
- * @param {number} value - The number to format
9
- * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`
9
+ * @param value - The number to format.
10
+ * @param options - Optional configuration passed to `millify`.
10
11
  *
11
- * @returns {string} The compact number string
12
+ * @returns The compact number string.
12
13
  *
13
14
  * @example
14
- * ```typescript
15
+ *
16
+ * ```ts
15
17
  * import { toCompactNumberString } from '@kikiutils/shared/number';
16
18
  *
17
- * console.log(toCompactNumberString(1234567)); // 1.23m
18
- * console.log(toCompactNumberString(1234567, { precision: 3 })); // 1.235m
19
+ * console.log(toCompactNumberString(1234567)); // => 1.23m
20
+ * console.log(toCompactNumberString(1234567, { precision: 3 })); // => 1.235m
19
21
  * ```
20
22
  */
21
- declare function toCompactNumberString(value: number, options?: Parameters<typeof millify>[1]): string;
23
+ export declare function toCompactNumberString(value: number, options?: Parameters<typeof millify>[1]): string;
22
24
  //#endregion
23
- export { toCompactNumberString };
24
25
  //# sourceMappingURL=number.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"number.d.ts","names":[],"sources":["../src/number.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAoBgB,sBAAsB,eAAe,UAAU,kBAAkB"}
1
+ {"version":3,"file":"number.d.ts","names":[],"sources":["../src/number.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;wBAsBgB,sBAAsB,eAAe,UAAU,kBAAkB"}
package/dist/number.js CHANGED
@@ -3,19 +3,21 @@ import { millify } from "millify";
3
3
  /**
4
4
  * Converts a large number into a compact, human-readable string using `millify`.
5
5
  *
6
- * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.
6
+ * @remarks
7
+ * Uses lowercase units, for example `k` and `m`, and a precision of `2` unless overridden.
7
8
  *
8
- * @param {number} value - The number to format
9
- * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`
9
+ * @param value - The number to format.
10
+ * @param options - Optional configuration passed to `millify`.
10
11
  *
11
- * @returns {string} The compact number string
12
+ * @returns The compact number string.
12
13
  *
13
14
  * @example
14
- * ```typescript
15
+ *
16
+ * ```ts
15
17
  * import { toCompactNumberString } from '@kikiutils/shared/number';
16
18
  *
17
- * console.log(toCompactNumberString(1234567)); // 1.23m
18
- * console.log(toCompactNumberString(1234567, { precision: 3 })); // 1.235m
19
+ * console.log(toCompactNumberString(1234567)); // => 1.23m
20
+ * console.log(toCompactNumberString(1234567, { precision: 3 })); // => 1.235m
19
21
  * ```
20
22
  */
21
23
  function toCompactNumberString(value, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"number.js","names":[],"sources":["../src/number.ts"],"sourcesContent":["import { millify } from 'millify';\n\n/**\n * Converts a large number into a compact, human-readable string using `millify`.\n *\n * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.\n *\n * @param {number} value - The number to format\n * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`\n *\n * @returns {string} The compact number string\n *\n * @example\n * ```typescript\n * import { toCompactNumberString } from '@kikiutils/shared/number';\n *\n * console.log(toCompactNumberString(1234567)); // 1.23m\n * console.log(toCompactNumberString(1234567, { precision: 3 })); // 1.235m\n * ```\n */\nexport function toCompactNumberString(value: number, options?: Parameters<typeof millify>[1]) {\n return millify(\n value,\n {\n lowercase: true,\n precision: 2,\n ...options,\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,sBAAsB,OAAe,SAAyC;CAC1F,OAAO,QACH,OACA;EACI,WAAW;EACX,WAAW;EACX,GAAG;CACP,CACJ;AACJ"}
1
+ {"version":3,"file":"number.js","names":[],"sources":["../src/number.ts"],"sourcesContent":["import { millify } from 'millify';\n\n/**\n * Converts a large number into a compact, human-readable string using `millify`.\n *\n * @remarks\n * Uses lowercase units, for example `k` and `m`, and a precision of `2` unless overridden.\n *\n * @param value - The number to format.\n * @param options - Optional configuration passed to `millify`.\n *\n * @returns The compact number string.\n *\n * @example\n *\n * ```ts\n * import { toCompactNumberString } from '@kikiutils/shared/number';\n *\n * console.log(toCompactNumberString(1234567)); // => 1.23m\n * console.log(toCompactNumberString(1234567, { precision: 3 })); // => 1.235m\n * ```\n */\nexport function toCompactNumberString(value: number, options?: Parameters<typeof millify>[1]) {\n return millify(\n value,\n {\n lowercase: true,\n precision: 2,\n ...options,\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,sBAAsB,OAAe,SAAyC;CAC1F,OAAO,QACH,OACA;EACI,WAAW;EACX,WAAW;EACX,GAAG;CACP,CACJ;AACJ"}
package/dist/object.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  /**
3
3
  * Serializes a nested object into a deterministic, flat string format.
4
4
  *
5
+ * @remarks
5
6
  * This function recursively traverses the input object (including nested objects and arrays),
6
7
  * flattens it into key paths using dot notation (e.g. "a.b.0.c"), sorts all keys,
7
8
  * and joins each key-value pair into a string with customizable separators.
@@ -12,21 +13,32 @@
12
13
  * Note: Empty objects and arrays produce an empty string, which is useful for
13
14
  * generating deterministic signature payloads.
14
15
  *
15
- * @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
16
- * @param {string} kvSeparator - The string used to separate each key from its value (default: '=')
17
- * @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')
18
- * @returns {string} A deterministic string representation of the input object
16
+ * @param input - The object to serialize. Can contain nested objects and arrays.
17
+ * @param kvSeparator - The string used to separate each key from its value (default: '=').
18
+ * @param pairSeparator - The string used to separate each key-value pair (default: '&').
19
+ *
20
+ * @returns A deterministic string representation of the input object.
19
21
  *
20
22
  * @example
21
- * ```typescript
23
+ *
24
+ * ```ts
22
25
  * import { stringifyObjectDeterministically } from '@kikiutils/shared/object';
23
26
  *
24
- * console.log(stringifyObjectDeterministically({ b: 2, a: { x: 1, y: [3, 4] } })); // a.x=1&a.y.0=3&a.y.1=4&b=2
25
- * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // foo:bar
26
- * console.log(stringifyObjectDeterministically({})); // ''
27
+ * console.log(stringifyObjectDeterministically({
28
+ * b: 2,
29
+ * a: {
30
+ * x: 1,
31
+ * y: [
32
+ * 3,
33
+ * 4,
34
+ * ],
35
+ * },
36
+ * })); // => a.x=1&a.y.0=3&a.y.1=4&b=2
37
+ *
38
+ * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // => foo:bar
39
+ * console.log(stringifyObjectDeterministically({})); // => ''
27
40
  * ```
28
41
  */
29
- declare function stringifyObjectDeterministically(input: Record<string, any>, kvSeparator?: string, pairSeparator?: string): string;
42
+ export declare function stringifyObjectDeterministically(input: Record<string, any>, kvSeparator?: string, pairSeparator?: string): string;
30
43
  //#endregion
31
- export { stringifyObjectDeterministically };
32
44
  //# sourceMappingURL=object.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","names":[],"sources":["../src/object.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2BgB,iCACZ,OAAO,qBACP,sBACA"}
1
+ {"version":3,"file":"object.d.ts","names":[],"sources":["../src/object.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCgB,iCACZ,OAAO,qBACP,sBACA"}