@kikiutils/shared 9.0.0 → 9.1.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 (96) hide show
  1. package/README.md +15 -0
  2. package/dist/consola.cjs +1 -1
  3. package/dist/consola.cjs.map +1 -1
  4. package/dist/consola.d.ts +1 -1
  5. package/dist/consola.mjs +1 -1
  6. package/dist/consola.mjs.map +1 -1
  7. package/dist/crypto-hash.cjs +1 -0
  8. package/dist/crypto-hash.cjs.map +1 -1
  9. package/dist/crypto-hash.d.ts +1 -0
  10. package/dist/crypto-hash.d.ts.map +1 -1
  11. package/dist/crypto-hash.mjs +1 -0
  12. package/dist/crypto-hash.mjs.map +1 -1
  13. package/dist/datetime.cjs +3 -0
  14. package/dist/datetime.cjs.map +1 -1
  15. package/dist/datetime.d.ts +3 -0
  16. package/dist/datetime.d.ts.map +1 -1
  17. package/dist/datetime.mjs +3 -0
  18. package/dist/datetime.mjs.map +1 -1
  19. package/dist/enum.cjs +2 -0
  20. package/dist/enum.cjs.map +1 -1
  21. package/dist/enum.d.ts +2 -0
  22. package/dist/enum.d.ts.map +1 -1
  23. package/dist/enum.mjs +2 -0
  24. package/dist/enum.mjs.map +1 -1
  25. package/dist/env.cjs +2 -0
  26. package/dist/env.cjs.map +1 -1
  27. package/dist/env.d.ts +2 -0
  28. package/dist/env.d.ts.map +1 -1
  29. package/dist/env.mjs +2 -0
  30. package/dist/env.mjs.map +1 -1
  31. package/dist/general.cjs.map +1 -1
  32. package/dist/general.d.ts +1 -0
  33. package/dist/general.d.ts.map +1 -1
  34. package/dist/general.mjs.map +1 -1
  35. package/dist/math.cjs +1 -0
  36. package/dist/math.cjs.map +1 -1
  37. package/dist/math.d.ts +3 -0
  38. package/dist/math.d.ts.map +1 -1
  39. package/dist/math.mjs +1 -0
  40. package/dist/math.mjs.map +1 -1
  41. package/dist/number.cjs +1 -0
  42. package/dist/number.cjs.map +1 -1
  43. package/dist/number.d.ts +1 -0
  44. package/dist/number.d.ts.map +1 -1
  45. package/dist/number.mjs +1 -0
  46. package/dist/number.mjs.map +1 -1
  47. package/dist/pino.cjs +1 -1
  48. package/dist/pino.cjs.map +1 -1
  49. package/dist/pino.d.ts +1 -1
  50. package/dist/pino.mjs +1 -1
  51. package/dist/pino.mjs.map +1 -1
  52. package/dist/random.cjs +8 -7
  53. package/dist/random.cjs.map +1 -1
  54. package/dist/random.d.ts +8 -7
  55. package/dist/random.d.ts.map +1 -1
  56. package/dist/random.mjs +8 -7
  57. package/dist/random.mjs.map +1 -1
  58. package/dist/string.cjs +1 -0
  59. package/dist/string.cjs.map +1 -1
  60. package/dist/string.d.ts +1 -0
  61. package/dist/string.d.ts.map +1 -1
  62. package/dist/string.mjs +1 -0
  63. package/dist/string.mjs.map +1 -1
  64. package/dist/url.cjs +21 -0
  65. package/dist/url.cjs.map +1 -0
  66. package/dist/url.d.ts +12 -0
  67. package/dist/url.d.ts.map +1 -0
  68. package/dist/url.mjs +19 -0
  69. package/dist/url.mjs.map +1 -0
  70. package/dist/vue.cjs +64 -0
  71. package/dist/vue.cjs.map +1 -0
  72. package/dist/vue.d.ts +31 -0
  73. package/dist/vue.d.ts.map +1 -0
  74. package/dist/vue.mjs +59 -0
  75. package/dist/vue.mjs.map +1 -0
  76. package/dist/web.cjs +18 -0
  77. package/dist/web.cjs.map +1 -0
  78. package/dist/web.d.ts +9 -0
  79. package/dist/web.d.ts.map +1 -0
  80. package/dist/web.mjs +16 -0
  81. package/dist/web.mjs.map +1 -0
  82. package/package.json +5 -2
  83. package/src/consola.ts +1 -1
  84. package/src/crypto-hash.ts +1 -0
  85. package/src/datetime.ts +3 -0
  86. package/src/enum.ts +2 -0
  87. package/src/env.ts +2 -0
  88. package/src/general.ts +1 -0
  89. package/src/math.ts +3 -0
  90. package/src/number.ts +1 -0
  91. package/src/pino.ts +1 -1
  92. package/src/random.ts +8 -7
  93. package/src/string.ts +1 -0
  94. package/src/url.ts +16 -0
  95. package/src/vue.ts +62 -0
  96. package/src/web.ts +13 -0
@@ -1 +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;;;;"}
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 *\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;;;;;;;;;;;;;;;;;AAiBG;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;;;;"}
package/dist/number.d.ts CHANGED
@@ -6,6 +6,7 @@ import { millify } from 'millify';
6
6
  *
7
7
  * @param {number} value - The number to format.
8
8
  * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`.
9
+ *
9
10
  * @returns {string} The compact number string.
10
11
  *
11
12
  * @example
@@ -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;;;;;;;;;;;;;;;;GAgBG;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","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"}
package/dist/number.mjs CHANGED
@@ -7,6 +7,7 @@ import { millify } from 'millify';
7
7
  *
8
8
  * @param {number} value - The number to format.
9
9
  * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`.
10
+ *
10
11
  * @returns {string} The compact number string.
11
12
  *
12
13
  * @example
@@ -1 +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;;;;"}
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 *\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;;;;;;;;;;;;;;;;;AAiBG;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 CHANGED
@@ -24,7 +24,7 @@ const stream = pinoPretty.PinoPretty({
24
24
  *
25
25
  * @example
26
26
  * ```typescript
27
- * import logger from '@kikiutils/shared/pino';
27
+ * import { logger } from '@kikiutils/shared/pino';
28
28
  *
29
29
  * logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test
30
30
  *
package/dist/pino.cjs.map CHANGED
@@ -1 +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;;;;;"}
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 CHANGED
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * @example
13
13
  * ```typescript
14
- * import logger from '@kikiutils/shared/pino';
14
+ * import { logger } from '@kikiutils/shared/pino';
15
15
  *
16
16
  * logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test
17
17
  *
package/dist/pino.mjs CHANGED
@@ -22,7 +22,7 @@ const stream = PinoPretty({
22
22
  *
23
23
  * @example
24
24
  * ```typescript
25
- * import logger from '@kikiutils/shared/pino';
25
+ * import { logger } from '@kikiutils/shared/pino';
26
26
  *
27
27
  * logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test
28
28
  *
package/dist/pino.mjs.map CHANGED
@@ -1 +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;;;;"}
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;;;;"}
package/dist/random.cjs CHANGED
@@ -10,14 +10,15 @@
10
10
  *
11
11
  * This function supports any return type by using a generic type parameter.
12
12
  *
13
- * @typeParam T - The return type of the generator function.
13
+ * @template T - The return type of the generator function.
14
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.
15
+ * @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T.
16
+ * @param {number} minMin - Lower bound of the first random range.
17
+ * @param {number} minMax - Upper bound of the first random range.
18
+ * @param {number} maxMin - Lower bound of the second random range.
19
+ * @param {number} maxMax - Upper bound of the second random range.
20
+ *
21
+ * @returns {T} The result of the generator function using the computed final length.
21
22
  */
22
23
  function generateWithNestedRandomLength(generator, minMin, minMax, maxMin, maxMax) {
23
24
  const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
@@ -1 +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;;;;"}
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 * @template T - The return type of the generator function.\n *\n * @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T.\n * @param {number} minMin - Lower bound of the first random range.\n * @param {number} minMax - Upper bound of the first random range.\n * @param {number} maxMin - Lower bound of the second random range.\n * @param {number} maxMax - Upper bound of the second random range.\n *\n * @returns {T} 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;;;;;;;;;;;;;;;;;;;AAmBG;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;;;;"}
package/dist/random.d.ts CHANGED
@@ -8,14 +8,15 @@
8
8
  *
9
9
  * This function supports any return type by using a generic type parameter.
10
10
  *
11
- * @typeParam T - The return type of the generator function.
11
+ * @template T - The return type of the generator function.
12
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.
13
+ * @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T.
14
+ * @param {number} minMin - Lower bound of the first random range.
15
+ * @param {number} minMax - Upper bound of the first random range.
16
+ * @param {number} maxMin - Lower bound of the second random range.
17
+ * @param {number} maxMax - Upper bound of the second random range.
18
+ *
19
+ * @returns {T} The result of the generator function using the computed final length.
19
20
  */
20
21
  export declare function generateWithNestedRandomLength<T = string>(generator: (length: number) => T, minMin: number, minMax: number, maxMin: number, maxMax: number): T;
21
22
  //# sourceMappingURL=random.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;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"}
package/dist/random.mjs CHANGED
@@ -8,14 +8,15 @@
8
8
  *
9
9
  * This function supports any return type by using a generic type parameter.
10
10
  *
11
- * @typeParam T - The return type of the generator function.
11
+ * @template T - The return type of the generator function.
12
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.
13
+ * @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T.
14
+ * @param {number} minMin - Lower bound of the first random range.
15
+ * @param {number} minMax - Upper bound of the first random range.
16
+ * @param {number} maxMin - Lower bound of the second random range.
17
+ * @param {number} maxMax - Upper bound of the second random range.
18
+ *
19
+ * @returns {T} The result of the generator function using the computed final length.
19
20
  */
20
21
  function generateWithNestedRandomLength(generator, minMin, minMax, maxMin, maxMax) {
21
22
  const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
@@ -1 +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;;;;"}
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 * @template T - The return type of the generator function.\n *\n * @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T.\n * @param {number} minMin - Lower bound of the first random range.\n * @param {number} minMax - Upper bound of the first random range.\n * @param {number} maxMin - Lower bound of the second random range.\n * @param {number} maxMax - Upper bound of the second random range.\n *\n * @returns {T} 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;;;;;;;;;;;;;;;;;;;AAmBG;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;;;;"}
package/dist/string.cjs CHANGED
@@ -17,6 +17,7 @@ const CHARSETS = {
17
17
  *
18
18
  * @param {number} length - The length of the string to generate. Must be a positive integer.
19
19
  * @param {RandomStringMode} [mode] - The character set to use.
20
+ *
20
21
  * @returns {string} The generated random string.
21
22
  *
22
23
  * @throws {Error} If the length is not a positive integer or the mode is unsupported.
@@ -1 +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;;;;"}
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 *\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;;;;;;;;;;;;;;;;;;AAkBG;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;;;;"}
package/dist/string.d.ts CHANGED
@@ -4,6 +4,7 @@ export type RandomStringMode = 'alphabetic' | 'alphanumeric' | 'lowercase' | 'lo
4
4
  *
5
5
  * @param {number} length - The length of the string to generate. Must be a positive integer.
6
6
  * @param {RandomStringMode} [mode] - The character set to use.
7
+ *
7
8
  * @returns {string} The generated random string.
8
9
  *
9
10
  * @throws {Error} If the length is not a positive integer or the mode is unsupported.
@@ -1 +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"}
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;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,gBAA+B,UAQjF"}
package/dist/string.mjs CHANGED
@@ -15,6 +15,7 @@ const CHARSETS = {
15
15
  *
16
16
  * @param {number} length - The length of the string to generate. Must be a positive integer.
17
17
  * @param {RandomStringMode} [mode] - The character set to use.
18
+ *
18
19
  * @returns {string} The generated random string.
19
20
  *
20
21
  * @throws {Error} If the length is not a positive integer or the mode is unsupported.
@@ -1 +1 @@
1
- {"version":3,"file":"string.mjs","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;;;;"}
1
+ {"version":3,"file":"string.mjs","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 *\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;;;;;;;;;;;;;;;;;;AAkBG;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;;;;"}
package/dist/url.cjs ADDED
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Appends or updates the `redirect` query parameter on a given URL.
5
+ *
6
+ * Typically used to preserve the user's current path for post-login navigation.
7
+ *
8
+ * @param {string} url - The target URL to modify.
9
+ * @param {string} redirectPath - The path to use as the redirect destination.
10
+ *
11
+ * @returns {string} A new URL string with the `redirect` query parameter.
12
+ */
13
+ function appendRedirectParamToUrl(url, redirectPath) {
14
+ const [base, rawQuery = ''] = url.split('?');
15
+ const searchParams = new URLSearchParams(rawQuery);
16
+ searchParams.set('redirect', redirectPath);
17
+ return `${base}?${searchParams.toString()}`;
18
+ }
19
+
20
+ exports.appendRedirectParamToUrl = appendRedirectParamToUrl;
21
+ //# sourceMappingURL=url.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.cjs","sources":["../src/url.ts"],"sourcesContent":["/**\n * Appends or updates the `redirect` query parameter on a given URL.\n *\n * Typically used to preserve the user's current path for post-login navigation.\n *\n * @param {string} url - The target URL to modify.\n * @param {string} redirectPath - The path to use as the redirect destination.\n *\n * @returns {string} A new URL string with the `redirect` query parameter.\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n const [base, rawQuery = ''] = url.split('?');\n const searchParams = new URLSearchParams(rawQuery);\n searchParams.set('redirect', redirectPath);\n return `${base}?${searchParams.toString()}`;\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;AASG;AACa,SAAA,wBAAwB,CAAC,GAAW,EAAE,YAAoB,EAAA;AACtE,IAAA,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC;AAC5C,IAAA,MAAM,YAAY,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC;AAClD,IAAA,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC;IAC1C,OAAO,CAAA,EAAG,IAAI,CAAI,CAAA,EAAA,YAAY,CAAC,QAAQ,EAAE,EAAE;AAC/C;;;;"}
package/dist/url.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Appends or updates the `redirect` query parameter on a given URL.
3
+ *
4
+ * Typically used to preserve the user's current path for post-login navigation.
5
+ *
6
+ * @param {string} url - The target URL to modify.
7
+ * @param {string} redirectPath - The path to use as the redirect destination.
8
+ *
9
+ * @returns {string} A new URL string with the `redirect` query parameter.
10
+ */
11
+ export declare function appendRedirectParamToUrl(url: string, redirectPath: string): string;
12
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAKzE"}
package/dist/url.mjs ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Appends or updates the `redirect` query parameter on a given URL.
3
+ *
4
+ * Typically used to preserve the user's current path for post-login navigation.
5
+ *
6
+ * @param {string} url - The target URL to modify.
7
+ * @param {string} redirectPath - The path to use as the redirect destination.
8
+ *
9
+ * @returns {string} A new URL string with the `redirect` query parameter.
10
+ */
11
+ function appendRedirectParamToUrl(url, redirectPath) {
12
+ const [base, rawQuery = ''] = url.split('?');
13
+ const searchParams = new URLSearchParams(rawQuery);
14
+ searchParams.set('redirect', redirectPath);
15
+ return `${base}?${searchParams.toString()}`;
16
+ }
17
+
18
+ export { appendRedirectParamToUrl };
19
+ //# sourceMappingURL=url.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.mjs","sources":["../src/url.ts"],"sourcesContent":["/**\n * Appends or updates the `redirect` query parameter on a given URL.\n *\n * Typically used to preserve the user's current path for post-login navigation.\n *\n * @param {string} url - The target URL to modify.\n * @param {string} redirectPath - The path to use as the redirect destination.\n *\n * @returns {string} A new URL string with the `redirect` query parameter.\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n const [base, rawQuery = ''] = url.split('?');\n const searchParams = new URLSearchParams(rawQuery);\n searchParams.set('redirect', redirectPath);\n return `${base}?${searchParams.toString()}`;\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;;AASG;AACa,SAAA,wBAAwB,CAAC,GAAW,EAAE,YAAoB,EAAA;AACtE,IAAA,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC;AAC5C,IAAA,MAAM,YAAY,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC;AAClD,IAAA,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC;IAC1C,OAAO,CAAA,EAAG,IAAI,CAAI,CAAA,EAAA,YAAY,CAAC,QAAQ,EAAE,EAAE;AAC/C;;;;"}
package/dist/vue.cjs ADDED
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ const vue = require('vue');
4
+ const vueRouter = require('vue-router');
5
+ const url = require('./url.cjs');
6
+
7
+ /**
8
+ * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
9
+ *
10
+ * @param {string} url - The base URL to modify.
11
+ *
12
+ * @returns {string} A new URL with the current route fullPath as the `redirect` parameter.
13
+ */
14
+ function appendRedirectParamFromCurrentRouteToUrl(url$1) {
15
+ return url.appendRedirectParamToUrl(url$1, vueRouter.useRoute().fullPath);
16
+ }
17
+ /**
18
+ * Clears an interval referenced by a Vue ref and sets it to null.
19
+ *
20
+ * @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null.
21
+ */
22
+ function clearIntervalRef(intervalRef) {
23
+ if (intervalRef.value)
24
+ clearInterval(intervalRef.value);
25
+ intervalRef.value = null;
26
+ }
27
+ /**
28
+ * Clears a timeout referenced by a Vue ref and sets it to null.
29
+ *
30
+ * @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null.
31
+ */
32
+ function clearTimeoutRef(timeoutRef) {
33
+ if (timeoutRef.value)
34
+ clearTimeout(timeoutRef.value);
35
+ timeoutRef.value = null;
36
+ }
37
+ /**
38
+ * A Vue composition function that remembers and restores scroll position
39
+ * of a scrollable container across route changes and keep-alive activation.
40
+ *
41
+ * @template T - The type of the scrollable element (defaults to HTMLElement).
42
+ *
43
+ * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element.
44
+ */
45
+ function usePreserveScroll(containerRef) {
46
+ let scrollLeft = 0;
47
+ let scrollTop = 0;
48
+ vue.onActivated(() => {
49
+ if (!containerRef.value)
50
+ return;
51
+ containerRef.value.scrollLeft = scrollLeft;
52
+ containerRef.value.scrollTop = scrollTop;
53
+ });
54
+ vueRouter.onBeforeRouteLeave(() => {
55
+ scrollLeft = containerRef.value?.scrollLeft || 0;
56
+ scrollTop = containerRef.value?.scrollTop || 0;
57
+ });
58
+ }
59
+
60
+ exports.appendRedirectParamFromCurrentRouteToUrl = appendRedirectParamFromCurrentRouteToUrl;
61
+ exports.clearIntervalRef = clearIntervalRef;
62
+ exports.clearTimeoutRef = clearTimeoutRef;
63
+ exports.usePreserveScroll = usePreserveScroll;
64
+ //# sourceMappingURL=vue.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.cjs","sources":["../src/vue.ts"],"sourcesContent":["import { onActivated } from 'vue';\nimport type { Ref } from 'vue';\nimport {\n onBeforeRouteLeave,\n useRoute,\n} from 'vue-router';\n\nimport { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify.\n *\n * @returns {string} A new URL with the current route fullPath as the `redirect` parameter.\n */\nexport function appendRedirectParamFromCurrentRouteToUrl(url: string) {\n return appendRedirectParamToUrl(url, useRoute().fullPath);\n}\n\n/**\n * Clears an interval referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null.\n */\nexport function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>) {\n if (intervalRef.value) clearInterval(intervalRef.value);\n intervalRef.value = null;\n}\n\n/**\n * Clears a timeout referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null.\n */\nexport function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>) {\n if (timeoutRef.value) clearTimeout(timeoutRef.value);\n timeoutRef.value = null;\n}\n\n/**\n * A Vue composition function that remembers and restores scroll position\n * of a scrollable container across route changes and keep-alive activation.\n *\n * @template T - The type of the scrollable element (defaults to HTMLElement).\n *\n * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element.\n */\nexport function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>) {\n let scrollLeft = 0;\n let scrollTop = 0;\n onActivated(() => {\n if (!containerRef.value) return;\n containerRef.value.scrollLeft = scrollLeft;\n containerRef.value.scrollTop = scrollTop;\n });\n\n onBeforeRouteLeave(() => {\n scrollLeft = containerRef.value?.scrollLeft || 0;\n scrollTop = containerRef.value?.scrollTop || 0;\n });\n}\n"],"names":["url","appendRedirectParamToUrl","useRoute","onActivated","onBeforeRouteLeave"],"mappings":";;;;;;AASA;;;;;;AAMG;AACG,SAAU,wCAAwC,CAACA,KAAW,EAAA;IAChE,OAAOC,4BAAwB,CAACD,KAAG,EAAEE,kBAAQ,EAAE,CAAC,QAAQ,CAAC;AAC7D;AAEA;;;;AAIG;AACG,SAAU,gBAAgB,CAAC,WAAuD,EAAA;IACpF,IAAI,WAAW,CAAC,KAAK;AAAE,QAAA,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC;AACvD,IAAA,WAAW,CAAC,KAAK,GAAG,IAAI;AAC5B;AAEA;;;;AAIG;AACG,SAAU,eAAe,CAAC,UAAqD,EAAA;IACjF,IAAI,UAAU,CAAC,KAAK;AAAE,QAAA,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC;AACpD,IAAA,UAAU,CAAC,KAAK,GAAG,IAAI;AAC3B;AAEA;;;;;;;AAOG;AACG,SAAU,iBAAiB,CAAkC,YAA2B,EAAA;IAC1F,IAAI,UAAU,GAAG,CAAC;IAClB,IAAI,SAAS,GAAG,CAAC;IACjBC,eAAW,CAAC,MAAK;QACb,IAAI,CAAC,YAAY,CAAC,KAAK;YAAE;AACzB,QAAA,YAAY,CAAC,KAAK,CAAC,UAAU,GAAG,UAAU;AAC1C,QAAA,YAAY,CAAC,KAAK,CAAC,SAAS,GAAG,SAAS;AAC5C,KAAC,CAAC;IAEFC,4BAAkB,CAAC,MAAK;QACpB,UAAU,GAAG,YAAY,CAAC,KAAK,EAAE,UAAU,IAAI,CAAC;QAChD,SAAS,GAAG,YAAY,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC;AAClD,KAAC,CAAC;AACN;;;;;;;"}
package/dist/vue.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { Ref } from 'vue';
2
+ /**
3
+ * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
4
+ *
5
+ * @param {string} url - The base URL to modify.
6
+ *
7
+ * @returns {string} A new URL with the current route fullPath as the `redirect` parameter.
8
+ */
9
+ export declare function appendRedirectParamFromCurrentRouteToUrl(url: string): string;
10
+ /**
11
+ * Clears an interval referenced by a Vue ref and sets it to null.
12
+ *
13
+ * @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null.
14
+ */
15
+ export declare function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>): void;
16
+ /**
17
+ * Clears a timeout referenced by a Vue ref and sets it to null.
18
+ *
19
+ * @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null.
20
+ */
21
+ export declare function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>): void;
22
+ /**
23
+ * A Vue composition function that remembers and restores scroll position
24
+ * of a scrollable container across route changes and keep-alive activation.
25
+ *
26
+ * @template T - The type of the scrollable element (defaults to HTMLElement).
27
+ *
28
+ * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element.
29
+ */
30
+ export declare function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>): void;
31
+ //# sourceMappingURL=vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAQ/B;;;;;;GAMG;AACH,wBAAgB,wCAAwC,CAAC,GAAG,EAAE,MAAM,UAEnE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,QAGvF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,QAGpF;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,OAAO,GAAG,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,QAa7F"}
package/dist/vue.mjs ADDED
@@ -0,0 +1,59 @@
1
+ import { onActivated } from 'vue';
2
+ import { useRoute, onBeforeRouteLeave } from 'vue-router';
3
+ import { appendRedirectParamToUrl } from './url.mjs';
4
+
5
+ /**
6
+ * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
7
+ *
8
+ * @param {string} url - The base URL to modify.
9
+ *
10
+ * @returns {string} A new URL with the current route fullPath as the `redirect` parameter.
11
+ */
12
+ function appendRedirectParamFromCurrentRouteToUrl(url) {
13
+ return appendRedirectParamToUrl(url, useRoute().fullPath);
14
+ }
15
+ /**
16
+ * Clears an interval referenced by a Vue ref and sets it to null.
17
+ *
18
+ * @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null.
19
+ */
20
+ function clearIntervalRef(intervalRef) {
21
+ if (intervalRef.value)
22
+ clearInterval(intervalRef.value);
23
+ intervalRef.value = null;
24
+ }
25
+ /**
26
+ * Clears a timeout referenced by a Vue ref and sets it to null.
27
+ *
28
+ * @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null.
29
+ */
30
+ function clearTimeoutRef(timeoutRef) {
31
+ if (timeoutRef.value)
32
+ clearTimeout(timeoutRef.value);
33
+ timeoutRef.value = null;
34
+ }
35
+ /**
36
+ * A Vue composition function that remembers and restores scroll position
37
+ * of a scrollable container across route changes and keep-alive activation.
38
+ *
39
+ * @template T - The type of the scrollable element (defaults to HTMLElement).
40
+ *
41
+ * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element.
42
+ */
43
+ function usePreserveScroll(containerRef) {
44
+ let scrollLeft = 0;
45
+ let scrollTop = 0;
46
+ onActivated(() => {
47
+ if (!containerRef.value)
48
+ return;
49
+ containerRef.value.scrollLeft = scrollLeft;
50
+ containerRef.value.scrollTop = scrollTop;
51
+ });
52
+ onBeforeRouteLeave(() => {
53
+ scrollLeft = containerRef.value?.scrollLeft || 0;
54
+ scrollTop = containerRef.value?.scrollTop || 0;
55
+ });
56
+ }
57
+
58
+ export { appendRedirectParamFromCurrentRouteToUrl, clearIntervalRef, clearTimeoutRef, usePreserveScroll };
59
+ //# sourceMappingURL=vue.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.mjs","sources":["../src/vue.ts"],"sourcesContent":["import { onActivated } from 'vue';\nimport type { Ref } from 'vue';\nimport {\n onBeforeRouteLeave,\n useRoute,\n} from 'vue-router';\n\nimport { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify.\n *\n * @returns {string} A new URL with the current route fullPath as the `redirect` parameter.\n */\nexport function appendRedirectParamFromCurrentRouteToUrl(url: string) {\n return appendRedirectParamToUrl(url, useRoute().fullPath);\n}\n\n/**\n * Clears an interval referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null.\n */\nexport function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>) {\n if (intervalRef.value) clearInterval(intervalRef.value);\n intervalRef.value = null;\n}\n\n/**\n * Clears a timeout referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null.\n */\nexport function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>) {\n if (timeoutRef.value) clearTimeout(timeoutRef.value);\n timeoutRef.value = null;\n}\n\n/**\n * A Vue composition function that remembers and restores scroll position\n * of a scrollable container across route changes and keep-alive activation.\n *\n * @template T - The type of the scrollable element (defaults to HTMLElement).\n *\n * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element.\n */\nexport function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>) {\n let scrollLeft = 0;\n let scrollTop = 0;\n onActivated(() => {\n if (!containerRef.value) return;\n containerRef.value.scrollLeft = scrollLeft;\n containerRef.value.scrollTop = scrollTop;\n });\n\n onBeforeRouteLeave(() => {\n scrollLeft = containerRef.value?.scrollLeft || 0;\n scrollTop = containerRef.value?.scrollTop || 0;\n });\n}\n"],"names":[],"mappings":";;;;AASA;;;;;;AAMG;AACG,SAAU,wCAAwC,CAAC,GAAW,EAAA;IAChE,OAAO,wBAAwB,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC;AAC7D;AAEA;;;;AAIG;AACG,SAAU,gBAAgB,CAAC,WAAuD,EAAA;IACpF,IAAI,WAAW,CAAC,KAAK;AAAE,QAAA,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC;AACvD,IAAA,WAAW,CAAC,KAAK,GAAG,IAAI;AAC5B;AAEA;;;;AAIG;AACG,SAAU,eAAe,CAAC,UAAqD,EAAA;IACjF,IAAI,UAAU,CAAC,KAAK;AAAE,QAAA,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC;AACpD,IAAA,UAAU,CAAC,KAAK,GAAG,IAAI;AAC3B;AAEA;;;;;;;AAOG;AACG,SAAU,iBAAiB,CAAkC,YAA2B,EAAA;IAC1F,IAAI,UAAU,GAAG,CAAC;IAClB,IAAI,SAAS,GAAG,CAAC;IACjB,WAAW,CAAC,MAAK;QACb,IAAI,CAAC,YAAY,CAAC,KAAK;YAAE;AACzB,QAAA,YAAY,CAAC,KAAK,CAAC,UAAU,GAAG,UAAU;AAC1C,QAAA,YAAY,CAAC,KAAK,CAAC,SAAS,GAAG,SAAS;AAC5C,KAAC,CAAC;IAEF,kBAAkB,CAAC,MAAK;QACpB,UAAU,GAAG,YAAY,CAAC,KAAK,EAAE,UAAU,IAAI,CAAC;QAChD,SAAS,GAAG,YAAY,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC;AAClD,KAAC,CAAC;AACN;;;;"}
package/dist/web.cjs ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const url = require('./url.cjs');
4
+
5
+ /**
6
+ * Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
7
+ *
8
+ * @param {string} url - The base URL to modify.
9
+ *
10
+ * @returns {string} A new URL with the current location as the `redirect` parameter.
11
+ */
12
+ function appendRedirectParamFromCurrentLocationToUrl(url$1) {
13
+ const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;
14
+ return url.appendRedirectParamToUrl(url$1, currentPath);
15
+ }
16
+
17
+ exports.appendRedirectParamFromCurrentLocationToUrl = appendRedirectParamFromCurrentLocationToUrl;
18
+ //# sourceMappingURL=web.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.cjs","sources":["../src/web.ts"],"sourcesContent":["import { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify.\n *\n * @returns {string} A new URL with the current location as the `redirect` parameter.\n */\nexport function appendRedirectParamFromCurrentLocationToUrl(url: string) {\n const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;\n return appendRedirectParamToUrl(url, currentPath);\n}\n"],"names":["url","appendRedirectParamToUrl"],"mappings":";;;;AAEA;;;;;;AAMG;AACG,SAAU,2CAA2C,CAACA,KAAW,EAAA;IACnE,MAAM,WAAW,GAAG,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA,CAAE;AACjG,IAAA,OAAOC,4BAAwB,CAACD,KAAG,EAAE,WAAW,CAAC;AACrD;;;;"}
package/dist/web.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
3
+ *
4
+ * @param {string} url - The base URL to modify.
5
+ *
6
+ * @returns {string} A new URL with the current location as the `redirect` parameter.
7
+ */
8
+ export declare function appendRedirectParamFromCurrentLocationToUrl(url: string): string;
9
+ //# sourceMappingURL=web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,2CAA2C,CAAC,GAAG,EAAE,MAAM,UAGtE"}
package/dist/web.mjs ADDED
@@ -0,0 +1,16 @@
1
+ import { appendRedirectParamToUrl } from './url.mjs';
2
+
3
+ /**
4
+ * Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
5
+ *
6
+ * @param {string} url - The base URL to modify.
7
+ *
8
+ * @returns {string} A new URL with the current location as the `redirect` parameter.
9
+ */
10
+ function appendRedirectParamFromCurrentLocationToUrl(url) {
11
+ const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;
12
+ return appendRedirectParamToUrl(url, currentPath);
13
+ }
14
+
15
+ export { appendRedirectParamFromCurrentLocationToUrl };
16
+ //# sourceMappingURL=web.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.mjs","sources":["../src/web.ts"],"sourcesContent":["import { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify.\n *\n * @returns {string} A new URL with the current location as the `redirect` parameter.\n */\nexport function appendRedirectParamFromCurrentLocationToUrl(url: string) {\n const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;\n return appendRedirectParamToUrl(url, currentPath);\n}\n"],"names":[],"mappings":";;AAEA;;;;;;AAMG;AACG,SAAU,2CAA2C,CAAC,GAAW,EAAA;IACnE,MAAM,WAAW,GAAG,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA,CAAE;AACjG,IAAA,OAAO,wBAAwB,CAAC,GAAG,EAAE,WAAW,CAAC;AACrD;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/shared",
3
- "version": "9.0.0",
3
+ "version": "9.1.0",
4
4
  "description": "A lightweight modular utility library for JavaScript and TypeScript, offering secure hashing, flexible logging, date utilities, Vue/web helpers, and more.",
5
5
  "author": "kiki-kanri",
6
6
  "license": "MIT",
@@ -66,12 +66,15 @@
66
66
  "date-fns": "^4.1.0",
67
67
  "decimal.js": "^10.5.0",
68
68
  "jest": "^29.7.0",
69
+ "jest-environment-jsdom": "^29.7.0",
69
70
  "millify": "^6.1.0",
70
71
  "pino": "^9.6.0",
71
72
  "pino-pretty": "^13.0.0",
72
73
  "ts-jest": "^29.3.2",
73
74
  "ts-project-builder": "5.0.1",
74
- "typescript": "^5.8.3"
75
+ "typescript": "^5.8.3",
76
+ "vue": "^3.5.13",
77
+ "vue-router": "^4.5.1"
75
78
  },
76
79
  "pnpm": {
77
80
  "onlyBuiltDependencies": [