@kikiutils/shared 11.0.0 → 13.0.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 (211) hide show
  1. package/README.md +10 -1
  2. package/dist/buffer.d.ts +7 -3
  3. package/dist/buffer.d.ts.map +1 -1
  4. package/dist/buffer.js +42 -0
  5. package/dist/buffer.js.map +1 -0
  6. package/dist/clipboard.d.ts +8 -6
  7. package/dist/clipboard.d.ts.map +1 -1
  8. package/dist/clipboard.js +86 -0
  9. package/dist/clipboard.js.map +1 -0
  10. package/dist/consola.d.ts +8 -2
  11. package/dist/consola.d.ts.map +1 -1
  12. package/dist/consola.js +32 -0
  13. package/dist/consola.js.map +1 -0
  14. package/dist/crypto-hash.d.ts +16 -26
  15. package/dist/crypto-hash.d.ts.map +1 -1
  16. package/dist/crypto-hash.js +37 -0
  17. package/dist/crypto-hash.js.map +1 -0
  18. package/dist/datetime.d.ts +13 -9
  19. package/dist/datetime.d.ts.map +1 -1
  20. package/dist/datetime.js +131 -0
  21. package/dist/datetime.js.map +1 -0
  22. package/dist/element-plus.d.ts +8 -4
  23. package/dist/element-plus.d.ts.map +1 -1
  24. package/dist/element-plus.js +37 -0
  25. package/dist/element-plus.js.map +1 -0
  26. package/dist/enum.d.ts +6 -3
  27. package/dist/enum.d.ts.map +1 -1
  28. package/dist/enum.js +108 -0
  29. package/dist/enum.js.map +1 -0
  30. package/dist/env.d.ts +12 -9
  31. package/dist/env.d.ts.map +1 -1
  32. package/dist/env.js +51 -0
  33. package/dist/env.js.map +1 -0
  34. package/dist/general.d.ts +5 -2
  35. package/dist/general.d.ts.map +1 -1
  36. package/dist/general.js +8 -0
  37. package/dist/general.js.map +1 -0
  38. package/dist/hash.d.ts +7 -4
  39. package/dist/hash.d.ts.map +1 -1
  40. package/dist/hash.js +20 -0
  41. package/dist/hash.js.map +1 -0
  42. package/dist/math.d.ts +20 -17
  43. package/dist/math.d.ts.map +1 -1
  44. package/dist/math.js +36 -0
  45. package/dist/math.js.map +1 -0
  46. package/dist/number.d.ts +7 -2
  47. package/dist/number.d.ts.map +1 -1
  48. package/dist/number.js +32 -0
  49. package/dist/number.js.map +1 -0
  50. package/dist/object.d.ts +4 -1
  51. package/dist/object.d.ts.map +1 -1
  52. package/dist/object.js +42 -0
  53. package/dist/object.js.map +1 -0
  54. package/dist/pino.d.ts +8 -2
  55. package/dist/pino.d.ts.map +1 -1
  56. package/dist/pino.js +40 -0
  57. package/dist/pino.js.map +1 -0
  58. package/dist/random.d.ts +4 -1
  59. package/dist/random.d.ts.map +1 -1
  60. package/dist/random.js +31 -0
  61. package/dist/random.js.map +1 -0
  62. package/dist/storage/enhanced/local/core.d.ts +45 -42
  63. package/dist/storage/enhanced/local/core.d.ts.map +1 -1
  64. package/dist/storage/enhanced/local/core.js +63 -0
  65. package/dist/storage/enhanced/local/core.js.map +1 -0
  66. package/dist/storage/enhanced/local/index.d.ts +3 -3
  67. package/dist/storage/enhanced/local/index.js +4 -0
  68. package/dist/storage/enhanced/local/keyed-store.d.ts +14 -11
  69. package/dist/storage/enhanced/local/keyed-store.d.ts.map +1 -1
  70. package/dist/storage/enhanced/local/keyed-store.js +36 -0
  71. package/dist/storage/enhanced/local/keyed-store.js.map +1 -0
  72. package/dist/storage/enhanced/redis/core.d.ts +64 -59
  73. package/dist/storage/enhanced/redis/core.d.ts.map +1 -1
  74. package/dist/storage/enhanced/redis/core.js +85 -0
  75. package/dist/storage/enhanced/redis/core.js.map +1 -0
  76. package/dist/storage/enhanced/redis/index.d.ts +3 -3
  77. package/dist/storage/enhanced/redis/index.js +4 -0
  78. package/dist/storage/enhanced/redis/keyed-store.d.ts +19 -14
  79. package/dist/storage/enhanced/redis/keyed-store.d.ts.map +1 -1
  80. package/dist/storage/enhanced/redis/keyed-store.js +41 -0
  81. package/dist/storage/enhanced/redis/keyed-store.js.map +1 -0
  82. package/dist/storage/lru/keyed-store.d.ts +21 -16
  83. package/dist/storage/lru/keyed-store.d.ts.map +1 -1
  84. package/dist/storage/lru/keyed-store.js +40 -0
  85. package/dist/storage/lru/keyed-store.js.map +1 -0
  86. package/dist/string.d.ts +5 -2
  87. package/dist/string.d.ts.map +1 -1
  88. package/dist/string.js +42 -0
  89. package/dist/string.js.map +1 -0
  90. package/dist/url.d.ts +4 -1
  91. package/dist/url.d.ts.map +1 -1
  92. package/dist/url.js +21 -0
  93. package/dist/url.js.map +1 -0
  94. package/dist/vue.d.ts +10 -5
  95. package/dist/vue.d.ts.map +1 -1
  96. package/dist/vue.js +58 -0
  97. package/dist/vue.js.map +1 -0
  98. package/dist/web.d.ts +5 -2
  99. package/dist/web.d.ts.map +1 -1
  100. package/dist/web.js +32 -0
  101. package/dist/web.js.map +1 -0
  102. package/package.json +108 -32
  103. package/src/hash.ts +19 -5
  104. package/src/vue.ts +1 -1
  105. package/src/web.ts +1 -1
  106. package/dist/buffer.cjs +0 -43
  107. package/dist/buffer.cjs.map +0 -1
  108. package/dist/buffer.mjs +0 -41
  109. package/dist/buffer.mjs.map +0 -1
  110. package/dist/clipboard.cjs +0 -91
  111. package/dist/clipboard.cjs.map +0 -1
  112. package/dist/clipboard.mjs +0 -88
  113. package/dist/clipboard.mjs.map +0 -1
  114. package/dist/consola.cjs +0 -35
  115. package/dist/consola.cjs.map +0 -1
  116. package/dist/consola.mjs +0 -32
  117. package/dist/consola.mjs.map +0 -1
  118. package/dist/crypto-hash.cjs +0 -61
  119. package/dist/crypto-hash.cjs.map +0 -1
  120. package/dist/crypto-hash.mjs +0 -50
  121. package/dist/crypto-hash.mjs.map +0 -1
  122. package/dist/datetime.cjs +0 -134
  123. package/dist/datetime.cjs.map +0 -1
  124. package/dist/datetime.mjs +0 -130
  125. package/dist/datetime.mjs.map +0 -1
  126. package/dist/element-plus.cjs +0 -37
  127. package/dist/element-plus.cjs.map +0 -1
  128. package/dist/element-plus.mjs +0 -35
  129. package/dist/element-plus.mjs.map +0 -1
  130. package/dist/enum.cjs +0 -112
  131. package/dist/enum.cjs.map +0 -1
  132. package/dist/enum.mjs +0 -108
  133. package/dist/enum.mjs.map +0 -1
  134. package/dist/env.cjs +0 -53
  135. package/dist/env.cjs.map +0 -1
  136. package/dist/env.mjs +0 -50
  137. package/dist/env.mjs.map +0 -1
  138. package/dist/general.cjs +0 -10
  139. package/dist/general.cjs.map +0 -1
  140. package/dist/general.mjs +0 -8
  141. package/dist/general.mjs.map +0 -1
  142. package/dist/hash.cjs +0 -28
  143. package/dist/hash.cjs.map +0 -1
  144. package/dist/hash.mjs +0 -23
  145. package/dist/hash.mjs.map +0 -1
  146. package/dist/math.cjs +0 -38
  147. package/dist/math.cjs.map +0 -1
  148. package/dist/math.mjs +0 -36
  149. package/dist/math.mjs.map +0 -1
  150. package/dist/number.cjs +0 -32
  151. package/dist/number.cjs.map +0 -1
  152. package/dist/number.mjs +0 -30
  153. package/dist/number.mjs.map +0 -1
  154. package/dist/object.cjs +0 -55
  155. package/dist/object.cjs.map +0 -1
  156. package/dist/object.mjs +0 -53
  157. package/dist/object.mjs.map +0 -1
  158. package/dist/pino.cjs +0 -42
  159. package/dist/pino.cjs.map +0 -1
  160. package/dist/pino.mjs +0 -39
  161. package/dist/pino.mjs.map +0 -1
  162. package/dist/random.cjs +0 -31
  163. package/dist/random.cjs.map +0 -1
  164. package/dist/random.mjs +0 -29
  165. package/dist/random.mjs.map +0 -1
  166. package/dist/storage/enhanced/local/core.cjs +0 -105
  167. package/dist/storage/enhanced/local/core.cjs.map +0 -1
  168. package/dist/storage/enhanced/local/core.mjs +0 -103
  169. package/dist/storage/enhanced/local/core.mjs.map +0 -1
  170. package/dist/storage/enhanced/local/index.cjs +0 -10
  171. package/dist/storage/enhanced/local/index.cjs.map +0 -1
  172. package/dist/storage/enhanced/local/index.d.ts.map +0 -1
  173. package/dist/storage/enhanced/local/index.mjs +0 -3
  174. package/dist/storage/enhanced/local/index.mjs.map +0 -1
  175. package/dist/storage/enhanced/local/keyed-store.cjs +0 -41
  176. package/dist/storage/enhanced/local/keyed-store.cjs.map +0 -1
  177. package/dist/storage/enhanced/local/keyed-store.mjs +0 -39
  178. package/dist/storage/enhanced/local/keyed-store.mjs.map +0 -1
  179. package/dist/storage/enhanced/redis/core.cjs +0 -144
  180. package/dist/storage/enhanced/redis/core.cjs.map +0 -1
  181. package/dist/storage/enhanced/redis/core.mjs +0 -142
  182. package/dist/storage/enhanced/redis/core.mjs.map +0 -1
  183. package/dist/storage/enhanced/redis/index.cjs +0 -10
  184. package/dist/storage/enhanced/redis/index.cjs.map +0 -1
  185. package/dist/storage/enhanced/redis/index.d.ts.map +0 -1
  186. package/dist/storage/enhanced/redis/index.mjs +0 -3
  187. package/dist/storage/enhanced/redis/index.mjs.map +0 -1
  188. package/dist/storage/enhanced/redis/keyed-store.cjs +0 -46
  189. package/dist/storage/enhanced/redis/keyed-store.cjs.map +0 -1
  190. package/dist/storage/enhanced/redis/keyed-store.mjs +0 -44
  191. package/dist/storage/enhanced/redis/keyed-store.mjs.map +0 -1
  192. package/dist/storage/lru/keyed-store.cjs +0 -49
  193. package/dist/storage/lru/keyed-store.cjs.map +0 -1
  194. package/dist/storage/lru/keyed-store.mjs +0 -47
  195. package/dist/storage/lru/keyed-store.mjs.map +0 -1
  196. package/dist/string.cjs +0 -45
  197. package/dist/string.cjs.map +0 -1
  198. package/dist/string.mjs +0 -43
  199. package/dist/string.mjs.map +0 -1
  200. package/dist/url.cjs +0 -21
  201. package/dist/url.cjs.map +0 -1
  202. package/dist/url.mjs +0 -19
  203. package/dist/url.mjs.map +0 -1
  204. package/dist/vue.cjs +0 -64
  205. package/dist/vue.cjs.map +0 -1
  206. package/dist/vue.mjs +0 -59
  207. package/dist/vue.mjs.map +0 -1
  208. package/dist/web.cjs +0 -35
  209. package/dist/web.cjs.map +0 -1
  210. package/dist/web.mjs +0 -32
  211. package/dist/web.mjs.map +0 -1
@@ -0,0 +1,37 @@
1
+ //#region src/element-plus.ts
2
+ /**
3
+ * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.
4
+ *
5
+ * This utility provides default values for `required`, `trigger`, and `type`,
6
+ * while allowing overrides via the `options` parameter. It simplifies common
7
+ * form validation rule creation and ensures consistency across forms.
8
+ *
9
+ * @param {string} message - The validation message to display when the rule fails
10
+ * @param {FormItemRule} [options] - Optional overrides for the rule fields
11
+ * @param {boolean} [options.required] - Whether the field is required (default: `true`)
12
+ * @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
13
+ * @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
14
+ *
15
+ * @returns A `FormItemRule` object that can be used in Element Plus form validation
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';
20
+ *
21
+ * const rule = createElFormItemRuleWithDefaults('This field is required');
22
+ * const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });
23
+ * ```
24
+ */
25
+ function createElFormItemRuleWithDefaults(message, options = {}) {
26
+ return {
27
+ ...options,
28
+ message,
29
+ required: options.required ?? true,
30
+ trigger: options.trigger ?? "blur",
31
+ type: options.type ?? "string"
32
+ };
33
+ }
34
+
35
+ //#endregion
36
+ export { createElFormItemRuleWithDefaults };
37
+ //# sourceMappingURL=element-plus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-plus.js","names":[],"sources":["../src/element-plus.ts"],"sourcesContent":["import type { RuleType } from 'async-validator';\nimport type { FormItemRule } from 'element-plus';\n\nexport type DoNotRemoveOrUseThisType = RuleType;\n\n/**\n * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.\n *\n * This utility provides default values for `required`, `trigger`, and `type`,\n * while allowing overrides via the `options` parameter. It simplifies common\n * form validation rule creation and ensures consistency across forms.\n *\n * @param {string} message - The validation message to display when the rule fails\n * @param {FormItemRule} [options] - Optional overrides for the rule fields\n * @param {boolean} [options.required] - Whether the field is required (default: `true`)\n * @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)\n * @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)\n *\n * @returns A `FormItemRule` object that can be used in Element Plus form validation\n *\n * @example\n * ```typescript\n * import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';\n *\n * const rule = createElFormItemRuleWithDefaults('This field is required');\n * const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });\n * ```\n */\nexport function createElFormItemRuleWithDefaults(message: string, options: FormItemRule = {}): FormItemRule {\n return {\n ...options,\n message,\n required: options.required ?? true,\n trigger: options.trigger ?? 'blur',\n type: options.type ?? 'string',\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,iCAAiC,SAAiB,UAAwB,EAAE,EAAgB;AACxG,QAAO;EACH,GAAG;EACH;EACA,UAAU,QAAQ,YAAY;EAC9B,SAAS,QAAQ,WAAW;EAC5B,MAAM,QAAQ,QAAQ;EACzB"}
package/dist/enum.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/enum.d.ts
1
2
  /**
2
3
  * Extracts only the numeric values from an enumeration-like object.
3
4
  *
@@ -21,7 +22,7 @@
21
22
  * console.log(getEnumNumberValues(RecordType)); // [0, 1]
22
23
  * ```
23
24
  */
24
- export declare function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], number>[];
25
+ declare function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], number>[];
25
26
  /**
26
27
  * Extracts only the string values from an enumeration-like object.
27
28
  *
@@ -45,7 +46,7 @@ export declare function getEnumNumberValues<T extends Record<string, any>>(enumO
45
46
  * console.log(getEnumStringValues(RecordType)); // ['unknown']
46
47
  * ```
47
48
  */
48
- export declare function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], string>[];
49
+ declare function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], string>[];
49
50
  /**
50
51
  * Extracts all values from an enumeration-like object.
51
52
  *
@@ -92,5 +93,7 @@ export declare function getEnumStringValues<T extends Record<string, any>>(enumO
92
93
  * console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']
93
94
  * ```
94
95
  */
95
- export declare function getEnumValues<T extends Record<string, any>>(enumObject: T): (T[keyof T])[];
96
+ declare function getEnumValues<T extends Record<string, any>>(enumObject: T): (T[keyof T])[];
97
+ //#endregion
98
+ export { getEnumNumberValues, getEnumStringValues, getEnumValues };
96
99
  //# sourceMappingURL=enum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../src/enum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAE/G;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAE/G;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAK1F"}
1
+ {"version":3,"file":"enum.d.ts","names":[],"sources":["../src/enum.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;AA2BA;;;;;;;;AAkDA;;;;;;AAAuF,iBA7EvE,mBA6EuE,CAAA,UA7EzC,MA6EyC,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,UAAA,EA7ER,CA6EQ,CAAA,EA7EJ,OA6EI,CA7EI,CA6EJ,CAAA,MA7EY,CA6EZ,CAAA,EAAA,MAAA,CAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;iBAlDvE,8BAA8B,iCAAiC,IAAI,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkDnF,wBAAwB,iCAAiC,KAAK,QAAQ"}
package/dist/enum.js ADDED
@@ -0,0 +1,108 @@
1
+ //#region src/enum.ts
2
+ /**
3
+ * Extracts only the numeric values from an enumeration-like object.
4
+ *
5
+ * @template T - The type of the enum object
6
+ *
7
+ * @param {T} enumObject - The enumeration-like object to extract numeric values from,
8
+ * the object can contain numeric values, string values, or both.
9
+ *
10
+ * @returns {Extract<T[keyof T], number>[]} An array of numeric values extracted from the enum object
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { getEnumNumberValues } from '@kikiutils/shared/enum';
15
+ *
16
+ * enum RecordType {
17
+ * Receive = 0,
18
+ * Send = 1,
19
+ * Unknown = 'unknown'
20
+ * }
21
+ *
22
+ * console.log(getEnumNumberValues(RecordType)); // [0, 1]
23
+ * ```
24
+ */
25
+ function getEnumNumberValues(enumObject) {
26
+ return getEnumValues(enumObject).filter((value) => typeof value === "number");
27
+ }
28
+ /**
29
+ * Extracts only the string values from an enumeration-like object.
30
+ *
31
+ * @template T - The type of the enum object
32
+ *
33
+ * @param {T} enumObject - The enumeration-like object to extract string values from,
34
+ * the object can contain numeric values, string values, or both.
35
+ *
36
+ * @returns {Extract<T[keyof T], string>[]} An array of string values extracted from the enum object
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { getEnumStringValues } from '@kikiutils/shared/enum';
41
+ *
42
+ * enum RecordType {
43
+ * Receive = 0,
44
+ * Send = 1,
45
+ * Unknown = 'unknown'
46
+ * }
47
+ *
48
+ * console.log(getEnumStringValues(RecordType)); // ['unknown']
49
+ * ```
50
+ */
51
+ function getEnumStringValues(enumObject) {
52
+ return getEnumValues(enumObject).filter((value) => typeof value === "string");
53
+ }
54
+ /**
55
+ * Extracts all values from an enumeration-like object.
56
+ *
57
+ * This function handles TypeScript enums correctly by accounting for the reverse mapping
58
+ * that occurs with numeric enums. It works with pure numeric enums, pure string enums,
59
+ * and mixed enums.
60
+ *
61
+ * @template T - The type of the enum object
62
+ *
63
+ * @param {T} enumObject - The enumeration-like object to extract values from,
64
+ * the object can contain numeric values, string values, or both.
65
+ *
66
+ * @returns {(T[keyof T])[]} An array containing all the values from the enum object
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { getEnumValues } from '@kikiutils/shared/enum';
71
+ *
72
+ * // Numeric enum
73
+ * enum Status {
74
+ * Active = 0,
75
+ * Inactive = 1,
76
+ * Pending = 2
77
+ * }
78
+ *
79
+ * console.log(getEnumValues(Status)); // [0, 1, 2]
80
+ *
81
+ * // String enum
82
+ * enum Color {
83
+ * Red = 'RED',
84
+ * Green = 'GREEN',
85
+ * Blue = 'BLUE'
86
+ * }
87
+ *
88
+ * console.log(getEnumValues(Color)); // ['RED', 'GREEN', 'BLUE']
89
+ *
90
+ * // Mixed enum
91
+ * enum RecordType {
92
+ * Receive = 0,
93
+ * Send = 1,
94
+ * Unknown = 'unknown'
95
+ * }
96
+ *
97
+ * console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']
98
+ * ```
99
+ */
100
+ function getEnumValues(enumObject) {
101
+ const values = Object.values(enumObject);
102
+ if (!values.some((value) => typeof value === "number")) return values;
103
+ return Object.keys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);
104
+ }
105
+
106
+ //#endregion
107
+ export { getEnumNumberValues, getEnumStringValues, getEnumValues };
108
+ //# sourceMappingURL=enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.js","names":[],"sources":["../src/enum.ts"],"sourcesContent":["/**\n * Extracts only the numeric values from an enumeration-like object.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract numeric values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {Extract<T[keyof T], number>[]} An array of numeric values extracted from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumNumberValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumNumberValues(RecordType)); // [0, 1]\n * ```\n */\nexport function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], number>[] {\n return getEnumValues(enumObject).filter((value) => typeof value === 'number');\n}\n\n/**\n * Extracts only the string values from an enumeration-like object.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract string values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {Extract<T[keyof T], string>[]} An array of string values extracted from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumStringValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumStringValues(RecordType)); // ['unknown']\n * ```\n */\nexport function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], string>[] {\n return getEnumValues(enumObject).filter((value) => typeof value === 'string');\n}\n\n/**\n * Extracts all values from an enumeration-like object.\n *\n * This function handles TypeScript enums correctly by accounting for the reverse mapping\n * that occurs with numeric enums. It works with pure numeric enums, pure string enums,\n * and mixed enums.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {(T[keyof T])[]} An array containing all the values from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumValues } from '@kikiutils/shared/enum';\n *\n * // Numeric enum\n * enum Status {\n * Active = 0,\n * Inactive = 1,\n * Pending = 2\n * }\n *\n * console.log(getEnumValues(Status)); // [0, 1, 2]\n *\n * // String enum\n * enum Color {\n * Red = 'RED',\n * Green = 'GREEN',\n * Blue = 'BLUE'\n * }\n *\n * console.log(getEnumValues(Color)); // ['RED', 'GREEN', 'BLUE']\n *\n * // Mixed enum\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']\n * ```\n */\nexport function getEnumValues<T extends Record<string, any>>(enumObject: T): (T[keyof T])[] {\n const values = Object.values(enumObject);\n const hasNumberValues = values.some((value) => typeof value === 'number');\n if (!hasNumberValues) return values;\n return Object.keys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBAAmD,YAA8C;AAC7G,QAAO,cAAc,WAAW,CAAC,QAAQ,UAAU,OAAO,UAAU,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;AA0BjF,SAAgB,oBAAmD,YAA8C;AAC7G,QAAO,cAAc,WAAW,CAAC,QAAQ,UAAU,OAAO,UAAU,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDjF,SAAgB,cAA6C,YAA+B;CACxF,MAAM,SAAS,OAAO,OAAO,WAAW;AAExC,KAAI,CADoB,OAAO,MAAM,UAAU,OAAO,UAAU,SAAS,CACnD,QAAO;AAC7B,QAAO,OAAO,KAAK,WAAW,CAAC,QAAQ,QAAQ,OAAO,MAAM,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,WAAW,KAAK"}
package/dist/env.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/env.d.ts
1
2
  /**
2
3
  * Custom error class for handling missing environment variables.
3
4
  *
@@ -5,14 +6,14 @@
5
6
  *
6
7
  * @extends {Error}
7
8
  */
8
- export declare class EnvironmentNotFoundError extends Error {
9
- readonly key: string;
10
- /**
11
- * Creates a new EnvironmentNotFoundError.
12
- *
13
- * @param {string} key - The missing environment variable key
14
- */
15
- constructor(key: string);
9
+ declare class EnvironmentNotFoundError extends Error {
10
+ readonly key: string;
11
+ /**
12
+ * Creates a new EnvironmentNotFoundError.
13
+ *
14
+ * @param {string} key - The missing environment variable key
15
+ */
16
+ constructor(key: string);
16
17
  }
17
18
  /**
18
19
  * Retrieves the value of an environment variable, or throws an error if it is not defined.
@@ -35,5 +36,7 @@ export declare class EnvironmentNotFoundError extends Error {
35
36
  * checkAndGetEnvValue('API_KEY'); // ❌ Throws EnvironmentNotFoundError
36
37
  * ```
37
38
  */
38
- export declare function checkAndGetEnvValue(key: string): string;
39
+ declare function checkAndGetEnvValue(key: string): string;
40
+ //#endregion
41
+ export { EnvironmentNotFoundError, checkAndGetEnvValue };
39
42
  //# sourceMappingURL=env.d.ts.map
package/dist/env.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB;;;;OAIG;gBACS,GAAG,EAAE,MAAM;CAM1B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGvD"}
1
+ {"version":3,"file":"env.d.ts","names":[],"sources":["../src/env.ts"],"sourcesContent":[],"mappings":";;AAOA;AAqCA;;;;;cArCa,wBAAA,SAAiC,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqC9B,mBAAA"}
package/dist/env.js ADDED
@@ -0,0 +1,51 @@
1
+ //#region src/env.ts
2
+ /**
3
+ * Custom error class for handling missing environment variables.
4
+ *
5
+ * Extends the built-in `Error` class and includes the missing key.
6
+ *
7
+ * @extends {Error}
8
+ */
9
+ var EnvironmentNotFoundError = class extends Error {
10
+ key;
11
+ /**
12
+ * Creates a new EnvironmentNotFoundError.
13
+ *
14
+ * @param {string} key - The missing environment variable key
15
+ */
16
+ constructor(key) {
17
+ super(`Missing environment variable: ${key}`);
18
+ this.key = key;
19
+ this.name = this.constructor.name;
20
+ Error.captureStackTrace?.(this, this.constructor);
21
+ }
22
+ };
23
+ /**
24
+ * Retrieves the value of an environment variable, or throws an error if it is not defined.
25
+ *
26
+ * Only checks for `process.env[key] === undefined`. An empty string (e.g. '') or any falsy string
27
+ * value like `'0'` or `'false'` is considered a valid (defined) value.
28
+ *
29
+ * @param {string} key - The environment variable key to retrieve
30
+ *
31
+ * @returns {string} The value of the environment variable
32
+ *
33
+ * @throws {EnvironmentNotFoundError} If the environment variable is not defined
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * process.env.API_KEY = '';
38
+ * checkAndGetEnvValue('API_KEY'); // ✅ Returns '' (still considered "defined")
39
+ *
40
+ * delete process.env.API_KEY;
41
+ * checkAndGetEnvValue('API_KEY'); // ❌ Throws EnvironmentNotFoundError
42
+ * ```
43
+ */
44
+ function checkAndGetEnvValue(key) {
45
+ if (process.env[key] === void 0) throw new EnvironmentNotFoundError(key);
46
+ return process.env[key];
47
+ }
48
+
49
+ //#endregion
50
+ export { EnvironmentNotFoundError, checkAndGetEnvValue };
51
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","names":[],"sources":["../src/env.ts"],"sourcesContent":["/**\n * Custom error class for handling missing environment variables.\n *\n * Extends the built-in `Error` class and includes the missing key.\n *\n * @extends {Error}\n */\nexport class EnvironmentNotFoundError extends Error {\n readonly key: string;\n\n /**\n * Creates a new EnvironmentNotFoundError.\n *\n * @param {string} key - The missing environment variable key\n */\n constructor(key: string) {\n super(`Missing environment variable: ${key}`);\n this.key = key;\n this.name = this.constructor.name;\n Error.captureStackTrace?.(this, this.constructor);\n }\n}\n\n/**\n * Retrieves the value of an environment variable, or throws an error if it is not defined.\n *\n * Only checks for `process.env[key] === undefined`. An empty string (e.g. '') or any falsy string\n * value like `'0'` or `'false'` is considered a valid (defined) value.\n *\n * @param {string} key - The environment variable key to retrieve\n *\n * @returns {string} The value of the environment variable\n *\n * @throws {EnvironmentNotFoundError} If the environment variable is not defined\n *\n * @example\n * ```typescript\n * process.env.API_KEY = '';\n * checkAndGetEnvValue('API_KEY'); // ✅ Returns '' (still considered \"defined\")\n *\n * delete process.env.API_KEY;\n * checkAndGetEnvValue('API_KEY'); // ❌ Throws EnvironmentNotFoundError\n * ```\n */\nexport function checkAndGetEnvValue(key: string): string {\n if (process.env[key] === undefined) throw new EnvironmentNotFoundError(key);\n return process.env[key];\n}\n"],"mappings":";;;;;;;;AAOA,IAAa,2BAAb,cAA8C,MAAM;CAChD,AAAS;;;;;;CAOT,YAAY,KAAa;AACrB,QAAM,iCAAiC,MAAM;AAC7C,OAAK,MAAM;AACX,OAAK,OAAO,KAAK,YAAY;AAC7B,QAAM,oBAAoB,MAAM,KAAK,YAAY;;;;;;;;;;;;;;;;;;;;;;;;AAyBzD,SAAgB,oBAAoB,KAAqB;AACrD,KAAI,QAAQ,IAAI,SAAS,OAAW,OAAM,IAAI,yBAAyB,IAAI;AAC3E,QAAO,QAAQ,IAAI"}
package/dist/general.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/general.d.ts
1
2
  /**
2
3
  * Extracts the first value from an array or returns the value itself if it's not an array.
3
4
  *
@@ -23,6 +24,8 @@
23
24
  * console.log(extractFirstValue(undefined, 'fallback')); // fallback
24
25
  * ```
25
26
  */
26
- export declare function extractFirstValue<T>(value: T | T[]): T | undefined;
27
- export declare function extractFirstValue<T, D>(value: T | T[], defaultValue: D): D | NonNullable<T>;
27
+ declare function extractFirstValue<T>(value: T | T[]): T | undefined;
28
+ declare function extractFirstValue<T, D>(value: T | T[], defaultValue: D): D | NonNullable<T>;
29
+ //#endregion
30
+ export { extractFirstValue };
28
31
  //# sourceMappingURL=general.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../src/general.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AACpE,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"general.d.ts","names":[],"sources":["../src/general.ts"],"sourcesContent":[],"mappings":";;AA2BA;;;;;;AACA;;;;;;;;;;;;;;;;;;iBADgB,4BAA4B,IAAI,MAAM;iBACtC,+BAA+B,IAAI,mBAAmB,IAAI,IAAI,YAAY"}
@@ -0,0 +1,8 @@
1
+ //#region src/general.ts
2
+ function extractFirstValue(value, defaultValue) {
3
+ return (Array.isArray(value) ? value[0] : value) ?? defaultValue;
4
+ }
5
+
6
+ //#endregion
7
+ export { extractFirstValue };
8
+ //# sourceMappingURL=general.js.map
@@ -0,0 +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;AACtE,SAAQ,MAAM,QAAQ,MAAM,GAAG,MAAM,KAAK,UAAU"}
package/dist/hash.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/hash.d.ts
1
2
  /**
2
3
  * This file provides a set of functions for creating SHA-3 hash digests
3
4
  * using different bit lengths (224, 256, 384, 512).
@@ -11,8 +12,10 @@
11
12
  * console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
12
13
  * ```
13
14
  */
14
- export declare const sha3224: (data: string | Uint8Array) => string;
15
- export declare const sha3256: (data: string | Uint8Array) => string;
16
- export declare const sha3384: (data: string | Uint8Array) => string;
17
- export declare const sha3512: (data: string | Uint8Array) => string;
15
+ declare function sha3224(data: string | Uint8Array): string;
16
+ declare function sha3256(data: string | Uint8Array): string;
17
+ declare function sha3384(data: string | Uint8Array): string;
18
+ declare function sha3512(data: string | Uint8Array): string;
19
+ //#endregion
20
+ export { sha3224, sha3256, sha3384, sha3512 };
18
21
  //# sourceMappingURL=hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAUH,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,GAAG,UAAU,WAA+B,CAAC;AACjF,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,GAAG,UAAU,WAA+B,CAAC;AACjF,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,GAAG,UAAU,WAA+B,CAAC;AACjF,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,GAAG,UAAU,WAA+B,CAAC"}
1
+ {"version":3,"file":"hash.d.ts","names":[],"sources":["../src/hash.ts"],"sourcesContent":[],"mappings":";;AAyBA;AAIA;AAIA;AAIA;;;;;;;;;iBAZgB,OAAA,gBAAuB;iBAIvB,OAAA,gBAAuB;iBAIvB,OAAA,gBAAuB;iBAIvB,OAAA,gBAAuB"}
package/dist/hash.js ADDED
@@ -0,0 +1,20 @@
1
+ import { sha3_224, sha3_256, sha3_384, sha3_512 } from "@noble/hashes/sha3";
2
+ import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils";
3
+
4
+ //#region src/hash.ts
5
+ function sha3224(data) {
6
+ return bytesToHex(sha3_224(typeof data === "string" ? utf8ToBytes(data) : data));
7
+ }
8
+ function sha3256(data) {
9
+ return bytesToHex(sha3_256(typeof data === "string" ? utf8ToBytes(data) : data));
10
+ }
11
+ function sha3384(data) {
12
+ return bytesToHex(sha3_384(typeof data === "string" ? utf8ToBytes(data) : data));
13
+ }
14
+ function sha3512(data) {
15
+ return bytesToHex(sha3_512(typeof data === "string" ? utf8ToBytes(data) : data));
16
+ }
17
+
18
+ //#endregion
19
+ export { sha3224, sha3256, sha3384, sha3512 };
20
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","names":[],"sources":["../src/hash.ts"],"sourcesContent":["/**\n * This file provides a set of functions for creating SHA-3 hash digests\n * using different bit lengths (224, 256, 384, 512).\n * These functions use the [@noble/hashes](https://github.com/paulmillr/noble-hashes) library to generate the hashes.\n * Can be used in the browser, mainly for Nuxt/Vue and other frameworks compiled and executed in the browser.\n *\n * @example\n * ```typescript\n * import { sha3256 } from '@kikiutils/shared/hash';\n *\n * console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80\n * ```\n */\n\nimport {\n sha3_224,\n sha3_256,\n sha3_384,\n sha3_512,\n} from '@noble/hashes/sha3';\nimport {\n bytesToHex,\n utf8ToBytes,\n} from '@noble/hashes/utils';\n\nexport function sha3224(data: string | Uint8Array) {\n return bytesToHex(sha3_224(typeof data === 'string' ? utf8ToBytes(data) : data));\n}\n\nexport function sha3256(data: string | Uint8Array) {\n return bytesToHex(sha3_256(typeof data === 'string' ? utf8ToBytes(data) : data));\n}\n\nexport function sha3384(data: string | Uint8Array) {\n return bytesToHex(sha3_384(typeof data === 'string' ? utf8ToBytes(data) : data));\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;AAC/C,QAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,KAAK,GAAG,KAAK,CAAC;;AAGpF,SAAgB,QAAQ,MAA2B;AAC/C,QAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,KAAK,GAAG,KAAK,CAAC;;AAGpF,SAAgB,QAAQ,MAA2B;AAC/C,QAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,KAAK,GAAG,KAAK,CAAC;;AAGpF,SAAgB,QAAQ,MAA2B;AAC/C,QAAO,WAAW,SAAS,OAAO,SAAS,WAAW,YAAY,KAAK,GAAG,KAAK,CAAC"}
package/dist/math.d.ts CHANGED
@@ -1,23 +1,25 @@
1
- import { Decimal } from 'decimal.js';
1
+ import { Decimal } from "decimal.js";
2
+
3
+ //#region src/math.d.ts
2
4
  type CalculableValue = Decimal.Value | {
3
- toString: () => string;
5
+ toString: () => string;
4
6
  };
5
7
  /**
6
8
  * Options for configuring the output of `toPercentageString`.
7
9
  */
8
- export interface ToPercentageStringOptions {
9
- /**
10
- * Number of decimal places to include in the result.
11
- *
12
- * @default 2
13
- */
14
- decimalPlaces?: number;
15
- /**
16
- * Whether to include the '%' symbol in the result.
17
- *
18
- * @default true
19
- */
20
- withSymbol?: boolean;
10
+ interface ToPercentageStringOptions {
11
+ /**
12
+ * Number of decimal places to include in the result.
13
+ *
14
+ * @default 2
15
+ */
16
+ decimalPlaces?: number;
17
+ /**
18
+ * Whether to include the '%' symbol in the result.
19
+ *
20
+ * @default true
21
+ */
22
+ withSymbol?: boolean;
21
23
  }
22
24
  /**
23
25
  * Converts a fraction (numerator / denominator) into a percentage string.
@@ -41,6 +43,7 @@ export interface ToPercentageStringOptions {
41
43
  * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // 25.0%
42
44
  * ```
43
45
  */
44
- export declare function toPercentageString(molecular: CalculableValue, denominator: CalculableValue, options?: ToPercentageStringOptions): string;
45
- export {};
46
+ declare function toPercentageString(molecular: CalculableValue, denominator: CalculableValue, options?: ToPercentageStringOptions): string;
47
+ //#endregion
48
+ export { ToPercentageStringOptions, toPercentageString };
46
49
  //# sourceMappingURL=math.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,KAAK,eAAe,GAAG,OAAO,CAAC,KAAK,GAAG;IAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;CAAE,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAC9B,SAAS,EAAE,eAAe,EAC1B,WAAW,EAAE,eAAe,EAC5B,OAAO,CAAC,EAAE,yBAAyB,UAUtC"}
1
+ {"version":3,"file":"math.d.ts","names":[],"sources":["../src/math.ts"],"sourcesContent":[],"mappings":";;;KAEK,eAAA,GAAkB,OAAA,CAAQ;;AAFM,CAAA;AAOrC;AAsCA;;AACe,UAvCE,yBAAA,CAuCF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBADC,kBAAA,YACD,8BACE,2BACH"}
package/dist/math.js ADDED
@@ -0,0 +1,36 @@
1
+ import { Decimal } from "decimal.js";
2
+
3
+ //#region src/math.ts
4
+ /**
5
+ * Converts a fraction (numerator / denominator) into a percentage string.
6
+ *
7
+ * - Uses `decimal.js` for precise decimal calculations.
8
+ * - Supports custom decimal places and optional percentage symbol.
9
+ * - Returns `'0.00%'` if result is `NaN` or division is invalid.
10
+ *
11
+ * @param {CalculableValue} molecular - The numerator of the fraction
12
+ * @param {CalculableValue} denominator - The denominator of the fraction
13
+ * @param {ToPercentageStringOptions} [options] - Optional output settings
14
+ *
15
+ * @returns {string} Formatted percentage string
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { toPercentageString } from '@kikiutils/shared/math';
20
+ *
21
+ * console.log(toPercentageString(50, 200)); // 25.00%
22
+ * console.log(toPercentageString(50, 200, { withSymbol: false })); // 25.00
23
+ * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // 25.0%
24
+ * ```
25
+ */
26
+ function toPercentageString(molecular, denominator, options) {
27
+ const molecularDecimal = new Decimal(molecular.toString());
28
+ const denominatorDecimal = new Decimal(denominator.toString());
29
+ const calculationResult = molecularDecimal.div(denominatorDecimal);
30
+ const result = calculationResult.isNaN() ? "0.00" : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);
31
+ return options?.withSymbol ?? true ? `${result}%` : result;
32
+ }
33
+
34
+ //#endregion
35
+ export { toPercentageString };
36
+ //# sourceMappingURL=math.js.map
@@ -0,0 +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 const result = calculationResult.isNaN()\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,UAAU,CAAC;CAC1D,MAAM,qBAAqB,IAAI,QAAQ,YAAY,UAAU,CAAC;CAC9D,MAAM,oBAAoB,iBAAiB,IAAI,mBAAmB;CAClE,MAAM,SAAS,kBAAkB,OAAO,GAClC,SACA,kBAAkB,MAAM,IAAI,CAAC,QAAQ,SAAS,iBAAiB,EAAE;AAEvE,QAAO,SAAS,cAAc,OAAO,GAAG,OAAO,KAAK"}
package/dist/number.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- import { millify } from 'millify';
1
+ import { millify } from "millify";
2
+
3
+ //#region src/number.d.ts
4
+
2
5
  /**
3
6
  * Converts a large number into a compact, human-readable string using `millify`.
4
7
  *
@@ -17,5 +20,7 @@ import { millify } from 'millify';
17
20
  * console.log(toCompactNumberString(1234567, { precision: 3 })); // 1.235m
18
21
  * ```
19
22
  */
20
- export declare function toCompactNumberString(value: number, options?: Parameters<typeof millify>[1]): string;
23
+ declare function toCompactNumberString(value: number, options?: Parameters<typeof millify>[1]): string;
24
+ //#endregion
25
+ export { toCompactNumberString };
21
26
  //# sourceMappingURL=number.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,UAS3F"}
1
+ {"version":3,"file":"number.d.ts","names":[],"sources":["../src/number.ts"],"sourcesContent":[],"mappings":";;;;;;AAoBA;;;;;;;;;;;;;;;;iBAAgB,qBAAA,0BAA+C,kBAAkB"}
package/dist/number.js ADDED
@@ -0,0 +1,32 @@
1
+ import { millify } from "millify";
2
+
3
+ //#region src/number.ts
4
+ /**
5
+ * Converts a large number into a compact, human-readable string using `millify`.
6
+ *
7
+ * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.
8
+ *
9
+ * @param {number} value - The number to format
10
+ * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`
11
+ *
12
+ * @returns {string} The compact number string
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { toCompactNumberString } from '@kikiutils/shared/number';
17
+ *
18
+ * console.log(toCompactNumberString(1234567)); // 1.23m
19
+ * console.log(toCompactNumberString(1234567, { precision: 3 })); // 1.235m
20
+ * ```
21
+ */
22
+ function toCompactNumberString(value, options) {
23
+ return millify(value, {
24
+ lowercase: true,
25
+ precision: 2,
26
+ ...options
27
+ });
28
+ }
29
+
30
+ //#endregion
31
+ export { toCompactNumberString };
32
+ //# sourceMappingURL=number.js.map
@@ -0,0 +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;AAC1F,QAAO,QACH,OACA;EACI,WAAW;EACX,WAAW;EACX,GAAG;EACN,CACJ"}
package/dist/object.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/object.d.ts
1
2
  /**
2
3
  * Serializes a nested object into a deterministic, flat string format.
3
4
  *
@@ -21,5 +22,7 @@
21
22
  * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // foo:bar
22
23
  * ```
23
24
  */
24
- export declare function stringifyObjectDeterministically(input: Record<string, any>, kvSeparator?: string, pairSeparator?: string): string;
25
+ declare function stringifyObjectDeterministically(input: Record<string, any>, kvSeparator?: string, pairSeparator?: string): string;
26
+ //#endregion
27
+ export { stringifyObjectDeterministically };
25
28
  //# sourceMappingURL=object.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gCAAgC,CAC5C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,WAAW,GAAE,MAAY,EACzB,aAAa,GAAE,MAAY,UAkC9B"}
1
+ {"version":3,"file":"object.d.ts","names":[],"sources":["../src/object.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;;;iBAAgB,gCAAA,QACL"}
package/dist/object.js ADDED
@@ -0,0 +1,42 @@
1
+ //#region src/object.ts
2
+ /**
3
+ * Serializes a nested object into a deterministic, flat string format.
4
+ *
5
+ * This function recursively traverses the input object (including nested objects and arrays),
6
+ * flattens it into key paths using dot notation (e.g. "a.b.0.c"), sorts all keys,
7
+ * and joins each key-value pair into a string with customizable separators.
8
+ *
9
+ * It is designed for use cases such as signature generation, cache key construction,
10
+ * or any context requiring consistent and predictable object serialization.
11
+ *
12
+ * @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
13
+ * @param {string} kvSeparator - The string used to separate each key from its value (default: '=')
14
+ * @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')
15
+ * @returns {string} A deterministic string representation of the input object
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { stringifyObjectDeterministically } from '@kikiutils/shared/object';
20
+ *
21
+ * console.log(stringifyObjectDeterministically({ b: 2, a: { x: 1, y: [3, 4] } })); // a.x=1&a.y.0=3&a.y.1=4&b=2
22
+ * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // foo:bar
23
+ * ```
24
+ */
25
+ function stringifyObjectDeterministically(input, kvSeparator = "=", pairSeparator = "&") {
26
+ const entries = [];
27
+ function walk(object, path = []) {
28
+ if (Array.isArray(object)) object.forEach((value, index) => {
29
+ walk(value, [...path, index.toString()]);
30
+ });
31
+ else if (object !== null && typeof object === "object" && Object.prototype.toString.call(object) === "[object Object]") Object.keys(object).sort().forEach((key) => {
32
+ walk(object[key], [...path, key]);
33
+ });
34
+ else entries.push(`${path.join(".")}${kvSeparator}${String(object)}`);
35
+ }
36
+ walk(input);
37
+ return entries.sort().join(pairSeparator);
38
+ }
39
+
40
+ //#endregion
41
+ export { stringifyObjectDeterministically };
42
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","names":["entries: string[]"],"sources":["../src/object.ts"],"sourcesContent":["/**\n * Serializes a nested object into a deterministic, flat string format.\n *\n * This function recursively traverses the input object (including nested objects and arrays),\n * flattens it into key paths using dot notation (e.g. \"a.b.0.c\"), sorts all keys,\n * and joins each key-value pair into a string with customizable separators.\n *\n * It is designed for use cases such as signature generation, cache key construction,\n * or any context requiring consistent and predictable object serialization.\n *\n * @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays\n * @param {string} kvSeparator - The string used to separate each key from its value (default: '=')\n * @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')\n * @returns {string} A deterministic string representation of the input object\n *\n * @example\n * ```typescript\n * import { stringifyObjectDeterministically } from '@kikiutils/shared/object';\n *\n * console.log(stringifyObjectDeterministically({ b: 2, a: { x: 1, y: [3, 4] } })); // a.x=1&a.y.0=3&a.y.1=4&b=2\n * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // foo:bar\n * ```\n */\nexport function stringifyObjectDeterministically(\n input: Record<string, any>,\n kvSeparator: string = '=',\n pairSeparator: string = '&',\n) {\n const entries: string[] = [];\n\n function walk(object: any, path: string[] = []) {\n if (Array.isArray(object)) {\n object.forEach((value, index) => {\n walk(\n value,\n [\n ...path,\n index.toString(),\n ],\n );\n });\n } else if (\n object !== null\n && typeof object === 'object'\n && Object.prototype.toString.call(object) === '[object Object]'\n ) {\n Object.keys(object).sort().forEach((key) => {\n walk(\n object[key],\n [\n ...path,\n key,\n ],\n );\n });\n } else entries.push(`${path.join('.')}${kvSeparator}${String(object)}`);\n }\n\n walk(input);\n return entries.sort().join(pairSeparator);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,iCACZ,OACA,cAAsB,KACtB,gBAAwB,KAC1B;CACE,MAAMA,UAAoB,EAAE;CAE5B,SAAS,KAAK,QAAa,OAAiB,EAAE,EAAE;AAC5C,MAAI,MAAM,QAAQ,OAAO,CACrB,QAAO,SAAS,OAAO,UAAU;AAC7B,QACI,OACA,CACI,GAAG,MACH,MAAM,UAAU,CACnB,CACJ;IACH;WAEF,WAAW,QACR,OAAO,WAAW,YAClB,OAAO,UAAU,SAAS,KAAK,OAAO,KAAK,kBAE9C,QAAO,KAAK,OAAO,CAAC,MAAM,CAAC,SAAS,QAAQ;AACxC,QACI,OAAO,MACP,CACI,GAAG,MACH,IACH,CACJ;IACH;MACC,SAAQ,KAAK,GAAG,KAAK,KAAK,IAAI,GAAG,cAAc,OAAO,OAAO,GAAG;;AAG3E,MAAK,MAAM;AACX,QAAO,QAAQ,MAAM,CAAC,KAAK,cAAc"}