@kikiutils/shared 9.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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +142 -0
  3. package/dist/consola.cjs +35 -0
  4. package/dist/consola.cjs.map +1 -0
  5. package/dist/consola.d.ts +24 -0
  6. package/dist/consola.d.ts.map +1 -0
  7. package/dist/consola.mjs +32 -0
  8. package/dist/consola.mjs.map +1 -0
  9. package/dist/crypto-hash.cjs +60 -0
  10. package/dist/crypto-hash.cjs.map +1 -0
  11. package/dist/crypto-hash.d.ts +26 -0
  12. package/dist/crypto-hash.d.ts.map +1 -0
  13. package/dist/crypto-hash.mjs +49 -0
  14. package/dist/crypto-hash.mjs.map +1 -0
  15. package/dist/datetime.cjs +131 -0
  16. package/dist/datetime.cjs.map +1 -0
  17. package/dist/datetime.d.ts +79 -0
  18. package/dist/datetime.d.ts.map +1 -0
  19. package/dist/datetime.mjs +127 -0
  20. package/dist/datetime.mjs.map +1 -0
  21. package/dist/enum.cjs +65 -0
  22. package/dist/enum.cjs.map +1 -0
  23. package/dist/enum.d.ts +43 -0
  24. package/dist/enum.d.ts.map +1 -0
  25. package/dist/enum.mjs +62 -0
  26. package/dist/enum.mjs.map +1 -0
  27. package/dist/env.cjs +54 -0
  28. package/dist/env.cjs.map +1 -0
  29. package/dist/env.d.ts +40 -0
  30. package/dist/env.d.ts.map +1 -0
  31. package/dist/env.mjs +51 -0
  32. package/dist/env.mjs.map +1 -0
  33. package/dist/general.cjs +8 -0
  34. package/dist/general.cjs.map +1 -0
  35. package/dist/general.d.ts +27 -0
  36. package/dist/general.d.ts.map +1 -0
  37. package/dist/general.mjs +6 -0
  38. package/dist/general.mjs.map +1 -0
  39. package/dist/hash.cjs +27 -0
  40. package/dist/hash.cjs.map +1 -0
  41. package/dist/hash.d.ts +17 -0
  42. package/dist/hash.d.ts.map +1 -0
  43. package/dist/hash.mjs +22 -0
  44. package/dist/hash.mjs.map +1 -0
  45. package/dist/math.cjs +37 -0
  46. package/dist/math.cjs.map +1 -0
  47. package/dist/math.d.ts +43 -0
  48. package/dist/math.d.ts.map +1 -0
  49. package/dist/math.mjs +35 -0
  50. package/dist/math.mjs.map +1 -0
  51. package/dist/number.cjs +31 -0
  52. package/dist/number.cjs.map +1 -0
  53. package/dist/number.d.ts +20 -0
  54. package/dist/number.d.ts.map +1 -0
  55. package/dist/number.mjs +29 -0
  56. package/dist/number.mjs.map +1 -0
  57. package/dist/pino.cjs +42 -0
  58. package/dist/pino.cjs.map +1 -0
  59. package/dist/pino.d.ts +24 -0
  60. package/dist/pino.d.ts.map +1 -0
  61. package/dist/pino.mjs +39 -0
  62. package/dist/pino.mjs.map +1 -0
  63. package/dist/random.cjs +30 -0
  64. package/dist/random.cjs.map +1 -0
  65. package/dist/random.d.ts +21 -0
  66. package/dist/random.d.ts.map +1 -0
  67. package/dist/random.mjs +28 -0
  68. package/dist/random.mjs.map +1 -0
  69. package/dist/string.cjs +44 -0
  70. package/dist/string.cjs.map +1 -0
  71. package/dist/string.d.ts +21 -0
  72. package/dist/string.d.ts.map +1 -0
  73. package/dist/string.mjs +42 -0
  74. package/dist/string.mjs.map +1 -0
  75. package/package.json +82 -0
  76. package/src/consola.ts +27 -0
  77. package/src/crypto-hash.ts +60 -0
  78. package/src/datetime.ts +154 -0
  79. package/src/enum.ts +60 -0
  80. package/src/env.ts +49 -0
  81. package/src/general.ts +29 -0
  82. package/src/hash.ts +25 -0
  83. package/src/math.ts +56 -0
  84. package/src/number.ts +29 -0
  85. package/src/pino.ts +37 -0
  86. package/src/random.ts +31 -0
  87. package/src/string.ts +49 -0
package/dist/hash.cjs ADDED
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const sha3 = require('@noble/hashes/sha3');
4
+ const utils = require('@noble/hashes/utils');
5
+
6
+ /**
7
+ * This file provides a set of functions for creating SHA-3 hash digests using different bit lengths (224, 256, 384, 512).
8
+ * These functions use the [@noble/hashes](https://github.com/paulmillr/noble-hashes) library to generate the hashes.
9
+ * Can be used in the browser, mainly for Nuxt/Vue and other frameworks compiled and executed in the browser.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { sha3256 } from '@kikiutils/shared/hash';
14
+ *
15
+ * console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
16
+ * ```
17
+ */
18
+ const sha3224 = (data) => utils.bytesToHex(sha3.sha3_224(data));
19
+ const sha3256 = (data) => utils.bytesToHex(sha3.sha3_256(data));
20
+ const sha3384 = (data) => utils.bytesToHex(sha3.sha3_384(data));
21
+ const sha3512 = (data) => utils.bytesToHex(sha3.sha3_512(data));
22
+
23
+ exports.sha3224 = sha3224;
24
+ exports.sha3256 = sha3256;
25
+ exports.sha3384 = sha3384;
26
+ exports.sha3512 = sha3512;
27
+ //# sourceMappingURL=hash.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.cjs","sources":["../src/hash.ts"],"sourcesContent":["/**\n * This file provides a set of functions for creating SHA-3 hash digests 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 { bytesToHex } from '@noble/hashes/utils';\n\nexport const sha3224 = (data: string | Uint8Array) => bytesToHex(sha3_224(data));\nexport const sha3256 = (data: string | Uint8Array) => bytesToHex(sha3_256(data));\nexport const sha3384 = (data: string | Uint8Array) => bytesToHex(sha3_384(data));\nexport const sha3512 = (data: string | Uint8Array) => bytesToHex(sha3_512(data));\n"],"names":["bytesToHex","sha3_224","sha3_256","sha3_384","sha3_512"],"mappings":";;;;;AAAA;;;;;;;;;;;AAWG;AAUU,MAAA,OAAO,GAAG,CAAC,IAAyB,KAAKA,gBAAU,CAACC,aAAQ,CAAC,IAAI,CAAC;AAClE,MAAA,OAAO,GAAG,CAAC,IAAyB,KAAKD,gBAAU,CAACE,aAAQ,CAAC,IAAI,CAAC;AAClE,MAAA,OAAO,GAAG,CAAC,IAAyB,KAAKF,gBAAU,CAACG,aAAQ,CAAC,IAAI,CAAC;AAClE,MAAA,OAAO,GAAG,CAAC,IAAyB,KAAKH,gBAAU,CAACI,aAAQ,CAAC,IAAI,CAAC;;;;;;;"}
package/dist/hash.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * This file provides a set of functions for creating SHA-3 hash digests using different bit lengths (224, 256, 384, 512).
3
+ * These functions use the [@noble/hashes](https://github.com/paulmillr/noble-hashes) library to generate the hashes.
4
+ * Can be used in the browser, mainly for Nuxt/Vue and other frameworks compiled and executed in the browser.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { sha3256 } from '@kikiutils/shared/hash';
9
+ *
10
+ * console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
11
+ * ```
12
+ */
13
+ export declare const sha3224: (data: string | Uint8Array) => string;
14
+ export declare const sha3256: (data: string | Uint8Array) => string;
15
+ export declare const sha3384: (data: string | Uint8Array) => string;
16
+ export declare const sha3512: (data: string | Uint8Array) => string;
17
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;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"}
package/dist/hash.mjs ADDED
@@ -0,0 +1,22 @@
1
+ import { sha3_224, sha3_256, sha3_384, sha3_512 } from '@noble/hashes/sha3';
2
+ import { bytesToHex } from '@noble/hashes/utils';
3
+
4
+ /**
5
+ * This file provides a set of functions for creating SHA-3 hash digests using different bit lengths (224, 256, 384, 512).
6
+ * These functions use the [@noble/hashes](https://github.com/paulmillr/noble-hashes) library to generate the hashes.
7
+ * Can be used in the browser, mainly for Nuxt/Vue and other frameworks compiled and executed in the browser.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { sha3256 } from '@kikiutils/shared/hash';
12
+ *
13
+ * console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
14
+ * ```
15
+ */
16
+ const sha3224 = (data) => bytesToHex(sha3_224(data));
17
+ const sha3256 = (data) => bytesToHex(sha3_256(data));
18
+ const sha3384 = (data) => bytesToHex(sha3_384(data));
19
+ const sha3512 = (data) => bytesToHex(sha3_512(data));
20
+
21
+ export { sha3224, sha3256, sha3384, sha3512 };
22
+ //# sourceMappingURL=hash.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.mjs","sources":["../src/hash.ts"],"sourcesContent":["/**\n * This file provides a set of functions for creating SHA-3 hash digests 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 { bytesToHex } from '@noble/hashes/utils';\n\nexport const sha3224 = (data: string | Uint8Array) => bytesToHex(sha3_224(data));\nexport const sha3256 = (data: string | Uint8Array) => bytesToHex(sha3_256(data));\nexport const sha3384 = (data: string | Uint8Array) => bytesToHex(sha3_384(data));\nexport const sha3512 = (data: string | Uint8Array) => bytesToHex(sha3_512(data));\n"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;AAWG;AAUU,MAAA,OAAO,GAAG,CAAC,IAAyB,KAAK,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;AAClE,MAAA,OAAO,GAAG,CAAC,IAAyB,KAAK,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;AAClE,MAAA,OAAO,GAAG,CAAC,IAAyB,KAAK,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;AAClE,MAAA,OAAO,GAAG,CAAC,IAAyB,KAAK,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;;;;"}
package/dist/math.cjs ADDED
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ const decimal_js = require('decimal.js');
4
+
5
+ /**
6
+ * Converts a fraction (numerator / denominator) into a percentage string.
7
+ *
8
+ * - Uses `decimal.js` for precise decimal calculations.
9
+ * - Supports custom decimal places and optional percentage symbol.
10
+ * - Returns `'0.00%'` if result is `NaN` or division is invalid.
11
+ *
12
+ * @param {CalculableValue} molecular - The numerator of the fraction.
13
+ * @param {CalculableValue} denominator - The denominator of the fraction.
14
+ * @param {ToPercentageStringOptions} [options] - Optional output settings.
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_js.Decimal(molecular.toString());
28
+ const denominatorDecimal = new decimal_js.Decimal(denominator.toString());
29
+ const calculationResult = molecularDecimal.div(denominatorDecimal);
30
+ const result = calculationResult.isNaN()
31
+ ? '0.00'
32
+ : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);
33
+ return options?.withSymbol ?? true ? `${result}%` : result;
34
+ }
35
+
36
+ exports.toPercentageString = toPercentageString;
37
+ //# sourceMappingURL=math.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.cjs","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 * @default 2\n */\n decimalPlaces?: number;\n\n /**\n * Whether to include the '%' symbol in the result.\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 * @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"],"names":["Decimal"],"mappings":";;;;AAqBA;;;;;;;;;;;;;;;;;;;;AAoBG;SACa,kBAAkB,CAC9B,SAA0B,EAC1B,WAA4B,EAC5B,OAAmC,EAAA;IAEnC,MAAM,gBAAgB,GAAG,IAAIA,kBAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC1D,MAAM,kBAAkB,GAAG,IAAIA,kBAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC9D,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,GAAG,CAAC,kBAAkB,CAAC;AAClE,IAAA,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK;AAClC,UAAE;AACF,UAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,IAAI,CAAC,CAAC;AAEvE,IAAA,OAAO,OAAO,EAAE,UAAU,IAAI,IAAI,GAAG,CAAA,EAAG,MAAM,CAAG,CAAA,CAAA,GAAG,MAAM;AAC9D;;;;"}
package/dist/math.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { Decimal } from 'decimal.js';
2
+ type CalculableValue = Decimal.Value | {
3
+ toString: () => string;
4
+ };
5
+ /**
6
+ * Options for configuring the output of `toPercentageString`.
7
+ */
8
+ export interface ToPercentageStringOptions {
9
+ /**
10
+ * Number of decimal places to include in the result.
11
+ * @default 2
12
+ */
13
+ decimalPlaces?: number;
14
+ /**
15
+ * Whether to include the '%' symbol in the result.
16
+ * @default true
17
+ */
18
+ withSymbol?: boolean;
19
+ }
20
+ /**
21
+ * Converts a fraction (numerator / denominator) into a percentage string.
22
+ *
23
+ * - Uses `decimal.js` for precise decimal calculations.
24
+ * - Supports custom decimal places and optional percentage symbol.
25
+ * - Returns `'0.00%'` if result is `NaN` or division is invalid.
26
+ *
27
+ * @param {CalculableValue} molecular - The numerator of the fraction.
28
+ * @param {CalculableValue} denominator - The denominator of the fraction.
29
+ * @param {ToPercentageStringOptions} [options] - Optional output settings.
30
+ * @returns {string} Formatted percentage string.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * import { toPercentageString } from '@kikiutils/shared/math';
35
+ *
36
+ * console.log(toPercentageString(50, 200)); // 25.00%
37
+ * console.log(toPercentageString(50, 200, { withSymbol: false })); // 25.00
38
+ * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // 25.0%
39
+ * ```
40
+ */
41
+ export declare function toPercentageString(molecular: CalculableValue, denominator: CalculableValue, options?: ToPercentageStringOptions): string;
42
+ export {};
43
+ //# sourceMappingURL=math.d.ts.map
@@ -0,0 +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;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAC9B,SAAS,EAAE,eAAe,EAC1B,WAAW,EAAE,eAAe,EAC5B,OAAO,CAAC,EAAE,yBAAyB,UAUtC"}
package/dist/math.mjs ADDED
@@ -0,0 +1,35 @@
1
+ import { Decimal } from 'decimal.js';
2
+
3
+ /**
4
+ * Converts a fraction (numerator / denominator) into a percentage string.
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.
9
+ *
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.
13
+ * @returns {string} Formatted percentage string.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { toPercentageString } from '@kikiutils/shared/math';
18
+ *
19
+ * console.log(toPercentageString(50, 200)); // 25.00%
20
+ * console.log(toPercentageString(50, 200, { withSymbol: false })); // 25.00
21
+ * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // 25.0%
22
+ * ```
23
+ */
24
+ function toPercentageString(molecular, denominator, options) {
25
+ const molecularDecimal = new Decimal(molecular.toString());
26
+ const denominatorDecimal = new Decimal(denominator.toString());
27
+ const calculationResult = molecularDecimal.div(denominatorDecimal);
28
+ const result = calculationResult.isNaN()
29
+ ? '0.00'
30
+ : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);
31
+ return options?.withSymbol ?? true ? `${result}%` : result;
32
+ }
33
+
34
+ export { toPercentageString };
35
+ //# sourceMappingURL=math.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.mjs","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 * @default 2\n */\n decimalPlaces?: number;\n\n /**\n * Whether to include the '%' symbol in the result.\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 * @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"],"names":[],"mappings":";;AAqBA;;;;;;;;;;;;;;;;;;;;AAoBG;SACa,kBAAkB,CAC9B,SAA0B,EAC1B,WAA4B,EAC5B,OAAmC,EAAA;IAEnC,MAAM,gBAAgB,GAAG,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC1D,MAAM,kBAAkB,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC9D,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,GAAG,CAAC,kBAAkB,CAAC;AAClE,IAAA,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK;AAClC,UAAE;AACF,UAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,IAAI,CAAC,CAAC;AAEvE,IAAA,OAAO,OAAO,EAAE,UAAU,IAAI,IAAI,GAAG,CAAA,EAAG,MAAM,CAAG,CAAA,CAAA,GAAG,MAAM;AAC9D;;;;"}
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ const millify = require('millify');
4
+
5
+ /**
6
+ * Converts a large number into a compact, human-readable string using `millify`.
7
+ *
8
+ * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.
9
+ *
10
+ * @param {number} value - The number to format.
11
+ * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`.
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.millify(value, {
24
+ lowercase: true,
25
+ precision: 2,
26
+ ...options,
27
+ });
28
+ }
29
+
30
+ exports.toCompactNumberString = toCompactNumberString;
31
+ //# sourceMappingURL=number.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.cjs","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 * @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"],"names":["millify"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;AAgBG;AACa,SAAA,qBAAqB,CAAC,KAAa,EAAE,OAAuC,EAAA;IACxF,OAAOA,eAAO,CACV,KAAK,EACL;AACI,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,SAAS,EAAE,CAAC;AACZ,QAAA,GAAG,OAAO;AACb,KAAA,CACJ;AACL;;;;"}
@@ -0,0 +1,20 @@
1
+ import { millify } from 'millify';
2
+ /**
3
+ * Converts a large number into a compact, human-readable string using `millify`.
4
+ *
5
+ * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.
6
+ *
7
+ * @param {number} value - The number to format.
8
+ * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`.
9
+ * @returns {string} The compact number string.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { toCompactNumberString } from '@kikiutils/shared/number';
14
+ *
15
+ * console.log(toCompactNumberString(1234567)); // 1.23m
16
+ * console.log(toCompactNumberString(1234567, { precision: 3 })); // 1.235m
17
+ * ```
18
+ */
19
+ export declare function toCompactNumberString(value: number, options?: Parameters<typeof millify>[1]): string;
20
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,UAS3F"}
@@ -0,0 +1,29 @@
1
+ import { millify } from 'millify';
2
+
3
+ /**
4
+ * Converts a large number into a compact, human-readable string using `millify`.
5
+ *
6
+ * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.
7
+ *
8
+ * @param {number} value - The number to format.
9
+ * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`.
10
+ * @returns {string} The compact number string.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { toCompactNumberString } from '@kikiutils/shared/number';
15
+ *
16
+ * console.log(toCompactNumberString(1234567)); // 1.23m
17
+ * console.log(toCompactNumberString(1234567, { precision: 3 })); // 1.235m
18
+ * ```
19
+ */
20
+ function toCompactNumberString(value, options) {
21
+ return millify(value, {
22
+ lowercase: true,
23
+ precision: 2,
24
+ ...options,
25
+ });
26
+ }
27
+
28
+ export { toCompactNumberString };
29
+ //# sourceMappingURL=number.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.mjs","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 * @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"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;AAgBG;AACa,SAAA,qBAAqB,CAAC,KAAa,EAAE,OAAuC,EAAA;IACxF,OAAO,OAAO,CACV,KAAK,EACL;AACI,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,SAAS,EAAE,CAAC;AACZ,QAAA,GAAG,OAAO;AACb,KAAA,CACJ;AACL;;;;"}
package/dist/pino.cjs ADDED
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ const pino = require('pino');
4
+ const pinoPretty = require('pino-pretty');
5
+
6
+ /**
7
+ * Configure pinoPretty to enhance the log output.
8
+ */
9
+ const stream = pinoPretty.PinoPretty({
10
+ colorize: true, // Enable colored output for better readability
11
+ ignore: 'hostname,pid', // Exclude 'hostname' and 'pid' fields from the logs
12
+ translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', // Format the timestamp in 'yyyy-mm-dd HH:MM:ss.l' format
13
+ });
14
+ /**
15
+ * A pino logger instance with the configured stream.
16
+ *
17
+ * The logger's level is determined based on the `PINO_LOGGER_LEVEL` and `NODE_ENV` environment variables.
18
+ * If `PINO_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,
19
+ * the level will be set to `error`.
20
+ *
21
+ * To manually change the level, assign the desired level to `logger.level`.
22
+ *
23
+ * See available levels [here](https://getpino.io/#/docs/api?id=level-string).
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import logger from '@kikiutils/shared/pino';
28
+ *
29
+ * logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test
30
+ *
31
+ * // Manually change the level
32
+ * logger.level = 'info';
33
+ * ```
34
+ */
35
+ const pinoLogger = pino.pino({}, stream);
36
+ const logger = pinoLogger;
37
+ // eslint-disable-next-line style/max-len
38
+ pinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === 'production' ? 'error' : pinoLogger.level);
39
+
40
+ exports.logger = logger;
41
+ exports.pinoLogger = pinoLogger;
42
+ //# sourceMappingURL=pino.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pino.cjs","sources":["../src/pino.ts"],"sourcesContent":["import { pino } from 'pino';\nimport { PinoPretty } from 'pino-pretty';\n\n/**\n * Configure pinoPretty to enhance the log output.\n */\nconst stream = PinoPretty({\n colorize: true, // Enable colored output for better readability\n ignore: 'hostname,pid', // Exclude 'hostname' and 'pid' fields from the logs\n translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', // Format the timestamp in 'yyyy-mm-dd HH:MM:ss.l' format\n});\n\n/**\n * A pino logger instance with the configured stream.\n *\n * The logger's level is determined based on the `PINO_LOGGER_LEVEL` and `NODE_ENV` environment variables.\n * If `PINO_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,\n * the level will be set to `error`.\n *\n * To manually change the level, assign the desired level to `logger.level`.\n *\n * See available levels [here](https://getpino.io/#/docs/api?id=level-string).\n *\n * @example\n * ```typescript\n * import logger from '@kikiutils/shared/pino';\n *\n * logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test\n *\n * // Manually change the level\n * logger.level = 'info';\n * ```\n */\nexport const pinoLogger = pino({}, stream);\nexport const logger = pinoLogger;\n// eslint-disable-next-line style/max-len\npinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === 'production' ? 'error' : pinoLogger.level);\n"],"names":["PinoPretty","pino"],"mappings":";;;;;AAGA;;AAEG;AACH,MAAM,MAAM,GAAGA,qBAAU,CAAC;IACtB,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,cAAc;IACtB,aAAa,EAAE,2BAA2B;AAC7C,CAAA,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;AAoBG;AACU,MAAA,UAAU,GAAGC,SAAI,CAAC,EAAE,EAAE,MAAM;AAClC,MAAM,MAAM,GAAG;AACtB;AACA,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC;;;;;"}
package/dist/pino.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A pino logger instance with the configured stream.
3
+ *
4
+ * The logger's level is determined based on the `PINO_LOGGER_LEVEL` and `NODE_ENV` environment variables.
5
+ * If `PINO_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,
6
+ * the level will be set to `error`.
7
+ *
8
+ * To manually change the level, assign the desired level to `logger.level`.
9
+ *
10
+ * See available levels [here](https://getpino.io/#/docs/api?id=level-string).
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import logger from '@kikiutils/shared/pino';
15
+ *
16
+ * logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test
17
+ *
18
+ * // Manually change the level
19
+ * logger.level = 'info';
20
+ * ```
21
+ */
22
+ export declare const pinoLogger: import("pino").Logger<never, boolean>;
23
+ export declare const logger: import("pino").Logger<never, boolean>;
24
+ //# sourceMappingURL=pino.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pino.d.ts","sourceRoot":"","sources":["../src/pino.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,UAAU,uCAAmB,CAAC;AAC3C,eAAO,MAAM,MAAM,uCAAa,CAAC"}
package/dist/pino.mjs ADDED
@@ -0,0 +1,39 @@
1
+ import { pino } from 'pino';
2
+ import { PinoPretty } from 'pino-pretty';
3
+
4
+ /**
5
+ * Configure pinoPretty to enhance the log output.
6
+ */
7
+ const stream = PinoPretty({
8
+ colorize: true, // Enable colored output for better readability
9
+ ignore: 'hostname,pid', // Exclude 'hostname' and 'pid' fields from the logs
10
+ translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', // Format the timestamp in 'yyyy-mm-dd HH:MM:ss.l' format
11
+ });
12
+ /**
13
+ * A pino logger instance with the configured stream.
14
+ *
15
+ * The logger's level is determined based on the `PINO_LOGGER_LEVEL` and `NODE_ENV` environment variables.
16
+ * If `PINO_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,
17
+ * the level will be set to `error`.
18
+ *
19
+ * To manually change the level, assign the desired level to `logger.level`.
20
+ *
21
+ * See available levels [here](https://getpino.io/#/docs/api?id=level-string).
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * import logger from '@kikiutils/shared/pino';
26
+ *
27
+ * logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test
28
+ *
29
+ * // Manually change the level
30
+ * logger.level = 'info';
31
+ * ```
32
+ */
33
+ const pinoLogger = pino({}, stream);
34
+ const logger = pinoLogger;
35
+ // eslint-disable-next-line style/max-len
36
+ pinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === 'production' ? 'error' : pinoLogger.level);
37
+
38
+ export { logger, pinoLogger };
39
+ //# sourceMappingURL=pino.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pino.mjs","sources":["../src/pino.ts"],"sourcesContent":["import { pino } from 'pino';\nimport { PinoPretty } from 'pino-pretty';\n\n/**\n * Configure pinoPretty to enhance the log output.\n */\nconst stream = PinoPretty({\n colorize: true, // Enable colored output for better readability\n ignore: 'hostname,pid', // Exclude 'hostname' and 'pid' fields from the logs\n translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', // Format the timestamp in 'yyyy-mm-dd HH:MM:ss.l' format\n});\n\n/**\n * A pino logger instance with the configured stream.\n *\n * The logger's level is determined based on the `PINO_LOGGER_LEVEL` and `NODE_ENV` environment variables.\n * If `PINO_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,\n * the level will be set to `error`.\n *\n * To manually change the level, assign the desired level to `logger.level`.\n *\n * See available levels [here](https://getpino.io/#/docs/api?id=level-string).\n *\n * @example\n * ```typescript\n * import logger from '@kikiutils/shared/pino';\n *\n * logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test\n *\n * // Manually change the level\n * logger.level = 'info';\n * ```\n */\nexport const pinoLogger = pino({}, stream);\nexport const logger = pinoLogger;\n// eslint-disable-next-line style/max-len\npinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === 'production' ? 'error' : pinoLogger.level);\n"],"names":[],"mappings":";;;AAGA;;AAEG;AACH,MAAM,MAAM,GAAG,UAAU,CAAC;IACtB,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,cAAc;IACtB,aAAa,EAAE,2BAA2B;AAC7C,CAAA,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;AAoBG;AACU,MAAA,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,MAAM;AAClC,MAAM,MAAM,GAAG;AACtB;AACA,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC;;;;"}
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Generates a value using a provided generator function, where the input length
5
+ * is determined by two levels of nested random ranges:
6
+ *
7
+ * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.
8
+ * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.
9
+ * 3. The generator is called with the final length and its result is returned.
10
+ *
11
+ * This function supports any return type by using a generic type parameter.
12
+ *
13
+ * @typeParam T - The return type of the generator function.
14
+ *
15
+ * @param generator - A function that accepts a length and returns a value of type T.
16
+ * @param minMin - Lower bound of the first random range.
17
+ * @param minMax - Upper bound of the first random range.
18
+ * @param maxMin - Lower bound of the second random range.
19
+ * @param maxMax - Upper bound of the second random range.
20
+ * @returns The result of the generator function using the computed final length.
21
+ */
22
+ function generateWithNestedRandomLength(generator, minMin, minMax, maxMin, maxMax) {
23
+ const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
24
+ const innerMin = random(minMin, minMax);
25
+ const finalLength = random(Math.max(innerMin, maxMin), maxMax);
26
+ return generator(finalLength);
27
+ }
28
+
29
+ exports.generateWithNestedRandomLength = generateWithNestedRandomLength;
30
+ //# sourceMappingURL=random.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.cjs","sources":["../src/random.ts"],"sourcesContent":["/**\n * Generates a value using a provided generator function, where the input length\n * is determined by two levels of nested random ranges:\n *\n * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.\n * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.\n * 3. The generator is called with the final length and its result is returned.\n *\n * This function supports any return type by using a generic type parameter.\n *\n * @typeParam T - The return type of the generator function.\n *\n * @param generator - A function that accepts a length and returns a value of type T.\n * @param minMin - Lower bound of the first random range.\n * @param minMax - Upper bound of the first random range.\n * @param maxMin - Lower bound of the second random range.\n * @param maxMax - Upper bound of the second random range.\n * @returns The result of the generator function using the computed final length.\n */\nexport function generateWithNestedRandomLength<T = string>(\n generator: (length: number) => T,\n minMin: number,\n minMax: number,\n maxMin: number,\n maxMax: number,\n) {\n const random = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;\n const innerMin = random(minMin, minMax);\n const finalLength = random(Math.max(innerMin, maxMin), maxMax);\n return generator(finalLength);\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,8BAA8B,CAC1C,SAAgC,EAChC,MAAc,EACd,MAAc,EACd,MAAc,EACd,MAAc,EAAA;AAEd,IAAA,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,GAAW,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG;IAC9F,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;AACvC,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC;AAC9D,IAAA,OAAO,SAAS,CAAC,WAAW,CAAC;AACjC;;;;"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Generates a value using a provided generator function, where the input length
3
+ * is determined by two levels of nested random ranges:
4
+ *
5
+ * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.
6
+ * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.
7
+ * 3. The generator is called with the final length and its result is returned.
8
+ *
9
+ * This function supports any return type by using a generic type parameter.
10
+ *
11
+ * @typeParam T - The return type of the generator function.
12
+ *
13
+ * @param generator - A function that accepts a length and returns a value of type T.
14
+ * @param minMin - Lower bound of the first random range.
15
+ * @param minMax - Upper bound of the first random range.
16
+ * @param maxMin - Lower bound of the second random range.
17
+ * @param maxMax - Upper bound of the second random range.
18
+ * @returns The result of the generator function using the computed final length.
19
+ */
20
+ export declare function generateWithNestedRandomLength<T = string>(generator: (length: number) => T, minMin: number, minMax: number, maxMin: number, maxMax: number): T;
21
+ //# sourceMappingURL=random.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,GAAG,MAAM,EACrD,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,EAChC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,KAMjB"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Generates a value using a provided generator function, where the input length
3
+ * is determined by two levels of nested random ranges:
4
+ *
5
+ * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.
6
+ * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.
7
+ * 3. The generator is called with the final length and its result is returned.
8
+ *
9
+ * This function supports any return type by using a generic type parameter.
10
+ *
11
+ * @typeParam T - The return type of the generator function.
12
+ *
13
+ * @param generator - A function that accepts a length and returns a value of type T.
14
+ * @param minMin - Lower bound of the first random range.
15
+ * @param minMax - Upper bound of the first random range.
16
+ * @param maxMin - Lower bound of the second random range.
17
+ * @param maxMax - Upper bound of the second random range.
18
+ * @returns The result of the generator function using the computed final length.
19
+ */
20
+ function generateWithNestedRandomLength(generator, minMin, minMax, maxMin, maxMax) {
21
+ const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
22
+ const innerMin = random(minMin, minMax);
23
+ const finalLength = random(Math.max(innerMin, maxMin), maxMax);
24
+ return generator(finalLength);
25
+ }
26
+
27
+ export { generateWithNestedRandomLength };
28
+ //# sourceMappingURL=random.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.mjs","sources":["../src/random.ts"],"sourcesContent":["/**\n * Generates a value using a provided generator function, where the input length\n * is determined by two levels of nested random ranges:\n *\n * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.\n * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.\n * 3. The generator is called with the final length and its result is returned.\n *\n * This function supports any return type by using a generic type parameter.\n *\n * @typeParam T - The return type of the generator function.\n *\n * @param generator - A function that accepts a length and returns a value of type T.\n * @param minMin - Lower bound of the first random range.\n * @param minMax - Upper bound of the first random range.\n * @param maxMin - Lower bound of the second random range.\n * @param maxMax - Upper bound of the second random range.\n * @returns The result of the generator function using the computed final length.\n */\nexport function generateWithNestedRandomLength<T = string>(\n generator: (length: number) => T,\n minMin: number,\n minMax: number,\n maxMin: number,\n maxMax: number,\n) {\n const random = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;\n const innerMin = random(minMin, minMax);\n const finalLength = random(Math.max(innerMin, maxMin), maxMax);\n return generator(finalLength);\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,8BAA8B,CAC1C,SAAgC,EAChC,MAAc,EACd,MAAc,EACd,MAAc,EACd,MAAc,EAAA;AAEd,IAAA,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,GAAW,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG;IAC9F,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;AACvC,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC;AAC9D,IAAA,OAAO,SAAS,CAAC,WAAW,CAAC;AACjC;;;;"}
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const DIGITS = '0123456789';
4
+ const LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
5
+ const UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
6
+ const CHARSETS = {
7
+ 'alphabetic': LOWERCASE + UPPERCASE,
8
+ 'alphanumeric': DIGITS + LOWERCASE + UPPERCASE,
9
+ 'lowercase': LOWERCASE,
10
+ 'lowercase-numeric': DIGITS + LOWERCASE,
11
+ 'numeric': DIGITS,
12
+ 'uppercase': UPPERCASE,
13
+ 'uppercase-numeric': DIGITS + UPPERCASE,
14
+ };
15
+ /**
16
+ * Generates a random string of a given length using a specified character set.
17
+ *
18
+ * @param {number} length - The length of the string to generate. Must be a positive integer.
19
+ * @param {RandomStringMode} [mode] - The character set to use.
20
+ * @returns {string} The generated random string.
21
+ *
22
+ * @throws {Error} If the length is not a positive integer or the mode is unsupported.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * import { randomString } from '@kikiutils/shared/string';
27
+ *
28
+ * console.log(randomString(8)); // e.g. 'aZbXwTyQ' (alphabetic)
29
+ * console.log(randomString(6, 'numeric')); // e.g. '402398'
30
+ * console.log(randomString(10, 'alphanumeric')); // e.g. 'a9Z4pQ8xY2'
31
+ * ```
32
+ */
33
+ function randomString(length, mode = 'alphabetic') {
34
+ if (!Number.isInteger(length) || length <= 0) {
35
+ throw new Error(`Invalid length: ${length}. Must be a positive integer.`);
36
+ }
37
+ const charset = CHARSETS[mode];
38
+ if (!charset)
39
+ throw new Error(`Unsupported mode: ${mode}`);
40
+ return Array.from({ length }, () => charset[Math.floor(Math.random() * charset.length)]).join('');
41
+ }
42
+
43
+ exports.randomString = randomString;
44
+ //# sourceMappingURL=string.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.cjs","sources":["../src/string.ts"],"sourcesContent":["export type RandomStringMode =\n | 'alphabetic'\n | 'alphanumeric'\n | 'lowercase'\n | 'lowercase-numeric'\n | 'numeric'\n | 'uppercase'\n | 'uppercase-numeric';\n\nconst DIGITS = '0123456789';\nconst LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';\nconst UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\nconst CHARSETS: Record<RandomStringMode, string> = {\n 'alphabetic': LOWERCASE + UPPERCASE,\n 'alphanumeric': DIGITS + LOWERCASE + UPPERCASE,\n 'lowercase': LOWERCASE,\n 'lowercase-numeric': DIGITS + LOWERCASE,\n 'numeric': DIGITS,\n 'uppercase': UPPERCASE,\n 'uppercase-numeric': DIGITS + UPPERCASE,\n};\n\n/**\n * Generates a random string of a given length using a specified character set.\n *\n * @param {number} length - The length of the string to generate. Must be a positive integer.\n * @param {RandomStringMode} [mode] - The character set to use.\n * @returns {string} The generated random string.\n *\n * @throws {Error} If the length is not a positive integer or the mode is unsupported.\n *\n * @example\n * ```typescript\n * import { randomString } from '@kikiutils/shared/string';\n *\n * console.log(randomString(8)); // e.g. 'aZbXwTyQ' (alphabetic)\n * console.log(randomString(6, 'numeric')); // e.g. '402398'\n * console.log(randomString(10, 'alphanumeric')); // e.g. 'a9Z4pQ8xY2'\n * ```\n */\nexport function randomString(length: number, mode: RandomStringMode = 'alphabetic') {\n if (!Number.isInteger(length) || length <= 0) {\n throw new Error(`Invalid length: ${length}. Must be a positive integer.`);\n }\n\n const charset = CHARSETS[mode];\n if (!charset) throw new Error(`Unsupported mode: ${mode}`);\n return Array.from({ length }, () => charset[Math.floor(Math.random() * charset.length)]).join('');\n}\n"],"names":[],"mappings":";;AASA,MAAM,MAAM,GAAG,YAAY;AAC3B,MAAM,SAAS,GAAG,4BAA4B;AAC9C,MAAM,SAAS,GAAG,4BAA4B;AAC9C,MAAM,QAAQ,GAAqC;IAC/C,YAAY,EAAE,SAAS,GAAG,SAAS;AACnC,IAAA,cAAc,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;AAC9C,IAAA,WAAW,EAAE,SAAS;IACtB,mBAAmB,EAAE,MAAM,GAAG,SAAS;AACvC,IAAA,SAAS,EAAE,MAAM;AACjB,IAAA,WAAW,EAAE,SAAS;IACtB,mBAAmB,EAAE,MAAM,GAAG,SAAS;CAC1C;AAED;;;;;;;;;;;;;;;;;AAiBG;SACa,YAAY,CAAC,MAAc,EAAE,OAAyB,YAAY,EAAA;AAC9E,IAAA,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE;AAC1C,QAAA,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,CAAA,6BAAA,CAA+B,CAAC;;AAG7E,IAAA,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC;AAC9B,IAAA,IAAI,CAAC,OAAO;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAA,CAAE,CAAC;AAC1D,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AACrG;;;;"}
@@ -0,0 +1,21 @@
1
+ export type RandomStringMode = 'alphabetic' | 'alphanumeric' | 'lowercase' | 'lowercase-numeric' | 'numeric' | 'uppercase' | 'uppercase-numeric';
2
+ /**
3
+ * Generates a random string of a given length using a specified character set.
4
+ *
5
+ * @param {number} length - The length of the string to generate. Must be a positive integer.
6
+ * @param {RandomStringMode} [mode] - The character set to use.
7
+ * @returns {string} The generated random string.
8
+ *
9
+ * @throws {Error} If the length is not a positive integer or the mode is unsupported.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { randomString } from '@kikiutils/shared/string';
14
+ *
15
+ * console.log(randomString(8)); // e.g. 'aZbXwTyQ' (alphabetic)
16
+ * console.log(randomString(6, 'numeric')); // e.g. '402398'
17
+ * console.log(randomString(10, 'alphanumeric')); // e.g. 'a9Z4pQ8xY2'
18
+ * ```
19
+ */
20
+ export declare function randomString(length: number, mode?: RandomStringMode): string;
21
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,YAAY,GACZ,cAAc,GACd,WAAW,GACX,mBAAmB,GACnB,SAAS,GACT,WAAW,GACX,mBAAmB,CAAC;AAexB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,gBAA+B,UAQjF"}