@rzl-zone/utils-js 3.12.0 → 3.12.1-beta.1

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 (286) hide show
  1. package/{LICENSE.md → LICENSE} +3 -3
  2. package/README.md +69 -96
  3. package/dist/.references/index.d.cts +25 -0
  4. package/dist/.references/index.d.ts +25 -0
  5. package/dist/assertIsArray-DJXkjHZs.cjs +26 -0
  6. package/dist/assertIsArray-DJXkjHZs.cjs.map +1 -0
  7. package/dist/assertIsArray-bTA3XLjq.js +20 -0
  8. package/dist/assertIsArray-bTA3XLjq.js.map +1 -0
  9. package/dist/assertIsBoolean-C8WEXVr2.cjs +1283 -0
  10. package/dist/assertIsBoolean-C8WEXVr2.cjs.map +1 -0
  11. package/dist/assertIsBoolean-DR1SaXPD.js +1073 -0
  12. package/dist/assertIsBoolean-DR1SaXPD.js.map +1 -0
  13. package/dist/assertIsString-BiHQSrB2.cjs +26 -0
  14. package/dist/assertIsString-BiHQSrB2.cjs.map +1 -0
  15. package/dist/assertIsString-CEB07_83.js +20 -0
  16. package/dist/assertIsString-CEB07_83.js.map +1 -0
  17. package/dist/assertions/index.cjs +37 -40
  18. package/dist/assertions/index.cjs.map +1 -0
  19. package/dist/assertions/index.d.cts +12 -0
  20. package/dist/assertions/index.d.ts +10 -824
  21. package/dist/assertions/index.js +30 -13
  22. package/dist/assertions/index.js.map +1 -0
  23. package/dist/conversions/index.cjs +34 -103
  24. package/dist/conversions/index.d.cts +12 -0
  25. package/dist/conversions/index.d.ts +10 -1791
  26. package/dist/conversions/index.js +14 -24
  27. package/dist/conversions-BNIh_tCH.js +380 -0
  28. package/dist/conversions-BNIh_tCH.js.map +1 -0
  29. package/dist/conversions-D_Kh0a_C.cjs +446 -0
  30. package/dist/conversions-D_Kh0a_C.cjs.map +1 -0
  31. package/dist/events/index.cjs +55 -31
  32. package/dist/events/index.cjs.map +1 -0
  33. package/dist/events/index.d.cts +176 -0
  34. package/dist/events/index.d.ts +164 -166
  35. package/dist/events/index.js +50 -12
  36. package/dist/events/index.js.map +1 -0
  37. package/dist/formatEnvPort-B3OLxQk9.cjs +171 -0
  38. package/dist/formatEnvPort-B3OLxQk9.cjs.map +1 -0
  39. package/dist/formatEnvPort-ByFVLjSV.js +159 -0
  40. package/dist/formatEnvPort-ByFVLjSV.js.map +1 -0
  41. package/dist/formatters/index.cjs +21 -61
  42. package/dist/formatters/index.d.cts +12 -0
  43. package/dist/formatters/index.d.ts +10 -2152
  44. package/dist/formatters/index.js +10 -18
  45. package/dist/formatters--1m_vpE8.js +369 -0
  46. package/dist/formatters--1m_vpE8.js.map +1 -0
  47. package/dist/formatters-Cbij0XLU.cjs +429 -0
  48. package/dist/formatters-Cbij0XLU.cjs.map +1 -0
  49. package/dist/generators/index.cjs +165 -41
  50. package/dist/generators/index.cjs.map +1 -0
  51. package/dist/generators/index.d.cts +12 -0
  52. package/dist/generators/index.d.ts +10 -338
  53. package/dist/generators/index.js +158 -14
  54. package/dist/generators/index.js.map +1 -0
  55. package/dist/index-59zbLcPr.d.ts +340 -0
  56. package/dist/index-B6tawc8L.d.cts +1716 -0
  57. package/dist/index-C267akkJ.d.ts +2158 -0
  58. package/dist/index-CeBC2Vvl.d.cts +2361 -0
  59. package/dist/index-CgRDTI6f.d.ts +822 -0
  60. package/dist/index-CoiUBVmr.d.ts +720 -0
  61. package/dist/index-D4fcasfZ.d.cts +720 -0
  62. package/dist/index-DDrSQKIc.d.ts +1716 -0
  63. package/dist/index-DsGxO31H.d.cts +765 -0
  64. package/dist/index-Hg1qJkjl.d.ts +765 -0
  65. package/dist/index-Qm3iFwd0.d.cts +2158 -0
  66. package/dist/index-UPp94Agr.d.ts +2361 -0
  67. package/dist/index-gBA_8SuF.d.cts +340 -0
  68. package/dist/index-jyDqzicx.d.cts +822 -0
  69. package/dist/isBigInt-C4krUeAw.cjs +20 -0
  70. package/dist/isBigInt-C4krUeAw.cjs.map +1 -0
  71. package/dist/isBigInt-DKe0M6hp.js +14 -0
  72. package/dist/isBigInt-DKe0M6hp.js.map +1 -0
  73. package/dist/isEmptyObject-DCipFwxJ.js +25 -0
  74. package/dist/isEmptyObject-DCipFwxJ.js.map +1 -0
  75. package/dist/isEmptyObject-ZkSwRC_D.cjs +37 -0
  76. package/dist/isEmptyObject-ZkSwRC_D.cjs.map +1 -0
  77. package/dist/isEmptyString-BXzKAC2j.js +15 -0
  78. package/dist/isEmptyString-BXzKAC2j.js.map +1 -0
  79. package/dist/isEmptyString-UiiUsSQj.cjs +21 -0
  80. package/dist/isEmptyString-UiiUsSQj.cjs.map +1 -0
  81. package/dist/isEmptyValue-BQzcjVaL.cjs +30 -0
  82. package/dist/isEmptyValue-BQzcjVaL.cjs.map +1 -0
  83. package/dist/isEmptyValue-jqOr7OHD.js +24 -0
  84. package/dist/isEmptyValue-jqOr7OHD.js.map +1 -0
  85. package/dist/isEqual-BX49cF9m.js +87 -0
  86. package/dist/isEqual-BX49cF9m.js.map +1 -0
  87. package/dist/isEqual-BvumA3RA.cjs +111 -0
  88. package/dist/isEqual-BvumA3RA.cjs.map +1 -0
  89. package/dist/isFinite-BCnaDpod.js +15 -0
  90. package/dist/isFinite-BCnaDpod.js.map +1 -0
  91. package/dist/isFinite-D24ZaE6c.cjs +21 -0
  92. package/dist/isFinite-D24ZaE6c.cjs.map +1 -0
  93. package/dist/isInteger-Caeuz0rB.cjs +20 -0
  94. package/dist/isInteger-Caeuz0rB.cjs.map +1 -0
  95. package/dist/isInteger-naMbJsxJ.js +14 -0
  96. package/dist/isInteger-naMbJsxJ.js.map +1 -0
  97. package/dist/isPlainObject-BF-2-phb.d.cts +339 -0
  98. package/dist/isPlainObject-DxNDL8XU.d.ts +339 -0
  99. package/dist/isServer-BJHVnixd.cjs +20 -0
  100. package/dist/isServer-BJHVnixd.cjs.map +1 -0
  101. package/dist/isServer-Da3o3XSs.js +14 -0
  102. package/dist/isServer-Da3o3XSs.js.map +1 -0
  103. package/dist/isTypedArray-DuNA8tK6.js +31 -0
  104. package/dist/isTypedArray-DuNA8tK6.js.map +1 -0
  105. package/dist/isTypedArray-TJptiw2b.cjs +43 -0
  106. package/dist/isTypedArray-TJptiw2b.cjs.map +1 -0
  107. package/dist/isURL-C-kSk6KJ.js +14 -0
  108. package/dist/isURL-C-kSk6KJ.js.map +1 -0
  109. package/dist/isURL-DeUPO_oR.cjs +20 -0
  110. package/dist/isURL-DeUPO_oR.cjs.map +1 -0
  111. package/dist/isValidDomain-BB9IGhJs.cjs +1845 -0
  112. package/dist/isValidDomain-BB9IGhJs.cjs.map +1 -0
  113. package/dist/isValidDomain-DoE98yhJ.js +1827 -0
  114. package/dist/isValidDomain-DoE98yhJ.js.map +1 -0
  115. package/dist/next/index.cjs +119 -214
  116. package/dist/next/index.cjs.map +1 -0
  117. package/dist/next/index.d.cts +220 -0
  118. package/dist/next/index.d.ts +203 -214
  119. package/dist/next/index.js +117 -212
  120. package/dist/next/index.js.map +1 -0
  121. package/dist/next/server/index.cjs +25 -40
  122. package/dist/next/server/index.cjs.map +1 -0
  123. package/dist/next/server/index.d.cts +39 -0
  124. package/dist/next/server/index.d.ts +34 -35
  125. package/dist/next/server/index.js +23 -38
  126. package/dist/next/server/index.js.map +1 -0
  127. package/dist/noop-B13_ii35.cjs +18 -0
  128. package/dist/noop-B13_ii35.cjs.map +1 -0
  129. package/dist/noop-ubqAIbHD.js +12 -0
  130. package/dist/noop-ubqAIbHD.js.map +1 -0
  131. package/dist/normalizeSpaces-Bg2IZW7W.js +23 -0
  132. package/dist/normalizeSpaces-Bg2IZW7W.js.map +1 -0
  133. package/dist/normalizeSpaces-ZXnR4Qzp.cjs +29 -0
  134. package/dist/normalizeSpaces-ZXnR4Qzp.cjs.map +1 -0
  135. package/dist/normalizeString-BDdkaXui.js +15 -0
  136. package/dist/normalizeString-BDdkaXui.js.map +1 -0
  137. package/dist/normalizeString-BE6ELqEb.cjs +21 -0
  138. package/dist/normalizeString-BE6ELqEb.cjs.map +1 -0
  139. package/dist/operations/index.cjs +65 -32
  140. package/dist/operations/index.cjs.map +1 -0
  141. package/dist/operations/index.d.cts +139 -0
  142. package/dist/operations/index.d.ts +129 -134
  143. package/dist/operations/index.js +61 -17
  144. package/dist/operations/index.js.map +1 -0
  145. package/dist/parsers/index.cjs +12 -19
  146. package/dist/parsers/index.d.cts +239 -0
  147. package/dist/parsers/index.d.ts +234 -235
  148. package/dist/parsers/index.js +10 -12
  149. package/dist/parsers-BSBPgvsq.js +643 -0
  150. package/dist/parsers-BSBPgvsq.js.map +1 -0
  151. package/dist/parsers-OqDeffqc.cjs +649 -0
  152. package/dist/parsers-OqDeffqc.cjs.map +1 -0
  153. package/dist/parsing-Cao8b358.js +50 -0
  154. package/dist/parsing-Cao8b358.js.map +1 -0
  155. package/dist/parsing-DOGSCH6N.cjs +56 -0
  156. package/dist/parsing-DOGSCH6N.cjs.map +1 -0
  157. package/dist/predicates/index.cjs +91 -296
  158. package/dist/predicates/index.d.cts +13 -0
  159. package/dist/predicates/index.d.ts +12 -2482
  160. package/dist/predicates/index.js +23 -25
  161. package/dist/predicates-Bj6meyXV.js +256 -0
  162. package/dist/predicates-Bj6meyXV.js.map +1 -0
  163. package/dist/predicates-D0ubqgqy.cjs +412 -0
  164. package/dist/predicates-D0ubqgqy.cjs.map +1 -0
  165. package/dist/promises/index.cjs +76 -24
  166. package/dist/promises/index.cjs.map +1 -0
  167. package/dist/promises/index.d.cts +123 -0
  168. package/dist/promises/index.d.ts +116 -119
  169. package/dist/promises/index.js +73 -13
  170. package/dist/promises/index.js.map +1 -0
  171. package/dist/punyCode-8SrbMWfM.js +179 -0
  172. package/dist/punyCode-8SrbMWfM.js.map +1 -0
  173. package/dist/punyCode-D-Qu6nj6.cjs +185 -0
  174. package/dist/punyCode-D-Qu6nj6.cjs.map +1 -0
  175. package/dist/removeSpaces-Bmc5DX4F.js +19 -0
  176. package/dist/removeSpaces-Bmc5DX4F.js.map +1 -0
  177. package/dist/removeSpaces-CWIvhZHg.cjs +25 -0
  178. package/dist/removeSpaces-CWIvhZHg.cjs.map +1 -0
  179. package/dist/rzl-utils.global.js +20 -9
  180. package/dist/safeJsonParse-BP38mwlj.js +184 -0
  181. package/dist/safeJsonParse-BP38mwlj.js.map +1 -0
  182. package/dist/safeJsonParse-Sms2CJf4.cjs +208 -0
  183. package/dist/safeJsonParse-Sms2CJf4.cjs.map +1 -0
  184. package/dist/safeStableStringify-CJtP89qn.cjs +106 -0
  185. package/dist/safeStableStringify-CJtP89qn.cjs.map +1 -0
  186. package/dist/safeStableStringify-CXOZ9Ub8.js +88 -0
  187. package/dist/safeStableStringify-CXOZ9Ub8.js.map +1 -0
  188. package/dist/strings/index.cjs +79 -81
  189. package/dist/strings/index.cjs.map +1 -0
  190. package/dist/strings/index.d.cts +12 -0
  191. package/dist/strings/index.d.ts +10 -775
  192. package/dist/strings/index.js +62 -14
  193. package/dist/strings/index.js.map +1 -0
  194. package/dist/tailwind/index.cjs +19 -47
  195. package/dist/tailwind/index.d.cts +12 -0
  196. package/dist/tailwind/index.d.ts +11 -712
  197. package/dist/tailwind/index.js +10 -12
  198. package/dist/tailwind-B2ssevxq.js +199 -0
  199. package/dist/tailwind-B2ssevxq.js.map +1 -0
  200. package/dist/tailwind-CHIx9uxu.cjs +247 -0
  201. package/dist/tailwind-CHIx9uxu.cjs.map +1 -0
  202. package/dist/toStringArrayUnRecursive-C4zYCja7.cjs +51 -0
  203. package/dist/toStringArrayUnRecursive-C4zYCja7.cjs.map +1 -0
  204. package/dist/toStringArrayUnRecursive-DJGtPsFb.js +39 -0
  205. package/dist/toStringArrayUnRecursive-DJGtPsFb.js.map +1 -0
  206. package/dist/urls/index.cjs +130 -57
  207. package/dist/urls/index.cjs.map +1 -0
  208. package/dist/urls/index.d.cts +737 -0
  209. package/dist/urls/index.d.ts +699 -708
  210. package/dist/urls/index.js +122 -26
  211. package/dist/urls/index.js.map +1 -0
  212. package/package.json +203 -194
  213. package/dist/chunk-2AFQ33D3.cjs +0 -64
  214. package/dist/chunk-2CYDJVGM.js +0 -246
  215. package/dist/chunk-2MW4JDQ2.cjs +0 -598
  216. package/dist/chunk-2VTDXC3N.cjs +0 -1825
  217. package/dist/chunk-44XX2P34.js +0 -209
  218. package/dist/chunk-4YLBKLGS.cjs +0 -18
  219. package/dist/chunk-566CXQW7.cjs +0 -560
  220. package/dist/chunk-57EPKYID.cjs +0 -397
  221. package/dist/chunk-5MGEC3YG.js +0 -63
  222. package/dist/chunk-6EF52423.cjs +0 -249
  223. package/dist/chunk-6SCOKU3S.js +0 -109
  224. package/dist/chunk-6VUXD3CF.js +0 -119
  225. package/dist/chunk-7B76BSNK.cjs +0 -118
  226. package/dist/chunk-7Y6I2DSU.cjs +0 -101
  227. package/dist/chunk-A7S7E2EE.cjs +0 -308
  228. package/dist/chunk-AJZ6PMMZ.js +0 -16
  229. package/dist/chunk-AXGBL2IO.cjs +0 -251
  230. package/dist/chunk-B4TC6FBV.cjs +0 -678
  231. package/dist/chunk-BAV5T2E3.cjs +0 -15
  232. package/dist/chunk-BKIJBNIE.js +0 -21
  233. package/dist/chunk-BNIMTFK5.js +0 -59
  234. package/dist/chunk-BXW7YXB7.js +0 -1823
  235. package/dist/chunk-CFYZC4S6.js +0 -53
  236. package/dist/chunk-CSG4SCL3.js +0 -1587
  237. package/dist/chunk-CWQW7AKK.js +0 -676
  238. package/dist/chunk-DVMHRLKP.cjs +0 -16
  239. package/dist/chunk-EN7LVZBZ.js +0 -548
  240. package/dist/chunk-EV4Y7HCY.cjs +0 -26
  241. package/dist/chunk-F66VDYIZ.cjs +0 -18
  242. package/dist/chunk-FLJX37EL.cjs +0 -30
  243. package/dist/chunk-GKC3UDMC.cjs +0 -1623
  244. package/dist/chunk-H65I3GRZ.cjs +0 -106
  245. package/dist/chunk-HHYWB7VZ.js +0 -24
  246. package/dist/chunk-HNGGISFL.cjs +0 -65
  247. package/dist/chunk-HNSQAVSZ.cjs +0 -35
  248. package/dist/chunk-HSP6IWZK.js +0 -17
  249. package/dist/chunk-IDZS7J6T.js +0 -242
  250. package/dist/chunk-JS6R55VL.js +0 -302
  251. package/dist/chunk-JZVT5FK7.js +0 -232
  252. package/dist/chunk-KHO2SBNA.cjs +0 -16
  253. package/dist/chunk-KIDJCMNJ.js +0 -33
  254. package/dist/chunk-KOLEURVT.cjs +0 -38
  255. package/dist/chunk-L4V53MQK.cjs +0 -269
  256. package/dist/chunk-L5RDAVVH.js +0 -14
  257. package/dist/chunk-NODTV4F3.js +0 -16
  258. package/dist/chunk-NYK5K3V2.cjs +0 -211
  259. package/dist/chunk-ODUO3RTL.cjs +0 -113
  260. package/dist/chunk-ONZFBJVW.js +0 -14
  261. package/dist/chunk-PFXCTE37.js +0 -28
  262. package/dist/chunk-PPST7QAQ.js +0 -587
  263. package/dist/chunk-Q5IMYDFL.cjs +0 -33
  264. package/dist/chunk-QFFBIOJ4.js +0 -31
  265. package/dist/chunk-QNKGP5DY.js +0 -14
  266. package/dist/chunk-RRQHMOPE.cjs +0 -19
  267. package/dist/chunk-RU5OSRBU.js +0 -95
  268. package/dist/chunk-SDMPEJ4F.js +0 -35
  269. package/dist/chunk-SYNL5IKP.js +0 -115
  270. package/dist/chunk-TCDOWZQE.js +0 -16
  271. package/dist/chunk-TQPGXGKB.cjs +0 -123
  272. package/dist/chunk-TULOI4GL.js +0 -370
  273. package/dist/chunk-UBHCP4N5.cjs +0 -36
  274. package/dist/chunk-UCHF3M34.cjs +0 -56
  275. package/dist/chunk-UDA26MCU.cjs +0 -16
  276. package/dist/chunk-V3C4FYZL.cjs +0 -18
  277. package/dist/chunk-VAAHZFBF.js +0 -32
  278. package/dist/chunk-VJDDGRIK.cjs +0 -16
  279. package/dist/chunk-WVSPXFTY.js +0 -14
  280. package/dist/chunk-WYP76WXB.js +0 -101
  281. package/dist/chunk-YDE4ZBB7.cjs +0 -237
  282. package/dist/chunk-YKQEOO7C.cjs +0 -23
  283. package/dist/chunk-YSZC56SZ.js +0 -264
  284. package/dist/chunk-YWHHVDT4.js +0 -13
  285. package/dist/index.d.ts +0 -24
  286. package/dist/isPlainObject-DTJVV2Kf.d.ts +0 -536
@@ -1,340 +1,12 @@
1
1
  /*!
2
- * ====================================================
3
- * Rzl Utils-JS.
4
- * ----------------------------------------------------
5
- * Version: 3.12.0.
6
- * Author: Rizalvin Dwiky.
7
- * Repository: https://github.com/rzl-zone/utils-js.
8
- * ====================================================
9
- */
10
- import { NullToUndefined, FixNeverArrayRecursive, IfNonEmptyArray, Extends } from '@rzl-zone/ts-types-plus';
11
-
12
- /** ---------------------------------
13
- * * ***Utility: `getRandomItem`.***
14
- * ---------------------------------
15
- * **Function to get a random element from a given array.**
16
- * @template T - The type of the input array.
17
- * @param {*} array - The input array, can be `null`, `undefined`, or an empty array.
18
- * @returns
19
- * - If `array` is a non-empty tuple, returns one of its elements.
20
- * - If `array` is empty, `null`, or `undefined`, returns `undefined`.
21
- * @example
22
- * getRandomItem([]);
23
- * // ➔ undefined
24
- * getRandomItem(null);
25
- * // ➔ undefined
26
- * getRandomItem(undefined);
27
- * // ➔ undefined
28
- * getRandomItem([1, 2, 3, 4]);
29
- * // ➔ number
30
- * getRandomItem(["apple", "banana", "cherry"]);
31
- * // ➔ string
32
- * getRandomItem(["apple", 123, true]);
33
- * // ➔ string | number | boolean
34
- * getRandomItem(["apple", 123, true, null]);
35
- * // ➔ string | number | boolean | undefined
36
- * getRandomItem(["apple", 123, true, undefined]);
37
- * // ➔ string | number | boolean | undefined
38
- *
39
- * // Tuple example:
40
- * const tuple = [1, "two", true] as const;
41
- * getRandomItem(tuple); // 1 | "two" | true
42
- */
43
- declare function getRandomItem(array: undefined): undefined;
44
- declare function getRandomItem(array: []): undefined;
45
- declare function getRandomItem<T extends readonly unknown[]>(array: T): T extends never[][] ? undefined : number extends T["length"] ? NullToUndefined<FixNeverArrayRecursive<T[number]>> : IfNonEmptyArray<T, NullToUndefined<FixNeverArrayRecursive<T[number]>>, undefined>;
46
- declare function getRandomItem<T extends readonly unknown[] | undefined | null>(array: T): T extends readonly unknown[] ? NullToUndefined<FixNeverArrayRecursive<T[number]>> | undefined : undefined;
47
- declare function getRandomItem<T>(array: T): unknown extends T ? unknown : Extends<any[] | readonly any[], T> extends true ? Extract<T, unknown[] | readonly unknown[]>[number] | undefined : Extends<any[], T> extends true ? Extract<T, unknown[] | readonly unknown[]>[number] | undefined : Extends<readonly any[], T> extends true ? Extract<T, unknown[] | readonly unknown[]>[number] | undefined : undefined;
48
-
49
- /** -----------------------------------------------------------------------
50
- * * ***Utility: `randomInt`.***
51
- * ------------------------------------------------------------------------
52
- * **Generates a random integer within a specified range (inclusive).**
53
- * - **Generates a random integer between `min` and `max` (inclusive), with safety constraints:**
54
- * - `min` will be forced to be at least `1`.
55
- * - `max` will be capped at `Number.MAX_SAFE_INTEGER`.
56
- * @param {number} min - The minimum value (inclusive), must be an integer.
57
- * @param {number} max - The maximum value (inclusive), must be an integer.
58
- * @returns {number} A random integer N where `min ≤ N ≤ max`.
59
- * @throws **{@link TypeError | `TypeError`}** if:
60
- * - `min` or `max` is not an integer, or value is `Number.MIN_VALUE`.
61
- * - `min` is greater than `max`.
62
- * @example
63
- * randomInt(1, 10); // ➔ returns 1 up-to 10 (random)
64
- * randomInt(50, 100); // ➔ returns 50 up-to 100 (random)
65
- * randomInt(5, 5); // ➔ always returns 5 (exact)
66
- * randomInt(-5, 3); // ➔ always returns ≥ 1, since min is adjusted (exact)
67
- * randomInt(1, Number.MAX_SAFE_INTEGER + 10000);
68
- * // ➔ still safely capped at MAX_SAFE_INTEGER
69
- * randomInt(Number.MIN_VALUE, 3);
70
- * // ➔ Error, min or max cant be as `Number.MIN_VALUE` value.
71
- */
72
- declare const randomInt: (min: number, max: number) => number;
73
-
74
- type OptionsRandomIntByLength = {
75
- /** * Minimum length of the random number, the `allowed minimal value` `integer` is `1` `and not bigger than value of` `maxLength`, defaultValue: `1`.
76
- *
77
- * @default 1
78
- */
79
- minLength?: number;
80
- /** * Maximum length of the random number, the `allowed maximal value` `integer` is `16`, defaultValue: `16`.
81
- *
82
- * @default 16
83
- */
84
- maxLength?: number;
85
- /** * If true, prevents the result from being zero, defaultValue: `false`.
86
- *
87
- * @default false
88
- */
89
- avoidZero?: boolean;
90
- };
91
- /** ----------------------------------------------------------------------------
92
- * * ***Utility: `randomIntByLength`.***
93
- * -----------------------------------------------------------------------------
94
- * **Generates a random integer within a specified range of digit lengths.**
95
- * @description
96
- * This function allows generating random integers that strictly conform to a specified minimum and
97
- * maximum digit length, it is useful for scenarios such as generating realistic-looking IDs, codes,
98
- * or random test data.
99
- * - **The function ensures:**
100
- * - `minLength` is at least 1 and not greater than `maxLength`.
101
- * - `maxLength` is no more than 16 (due to JavaScript's `Number.MAX_SAFE_INTEGER`).
102
- * - If `avoidZero` is `true`, ensures that `0` is never returned.
103
- * @param {OptionsRandomIntByLength} [options] - Configuration options.
104
- * @param {OptionsRandomIntByLength["minLength"]} [options.minLength=1] - Minimum number of digits (must be ≥ `1` and ≤ `maxLength`).
105
- * @param {OptionsRandomIntByLength["maxLength"]} [options.maxLength=16] - Maximum number of digits (must be ≤ `16`).
106
- * @param {OptionsRandomIntByLength["avoidZero"]} [options.avoidZero=false] - If true, will ensure the result is never zero.
107
- * @returns {number} A randomly generated integer within the specified constraints.
108
- * @throws **{@link TypeError | `TypeError`}** if parameters are invalid, such as:
109
- * - `minLength` < `1`
110
- * - `maxLength` > `16`
111
- * - `minLength` > `maxLength`
112
- * - non-integer values for `minLength` or `maxLength`
113
- * @example
114
- * randomIntByLength({ minLength: 3, maxLength: 5 });
115
- * // ➔ `4829` (random), `192` (random) or `71492` (random).
116
- * randomIntByLength({ minLength: 4, maxLength: 4 });
117
- * // ➔ `5930` (exact 4 digits)
118
- * randomIntByLength({ avoidZero: true });
119
- * // ➔ never 0
120
- */
121
- declare const randomIntByLength: (options?: OptionsRandomIntByLength) => number;
122
-
123
- type OptionsRandomStr = {
124
- /** ***Ensures no whitespace characters in the generated string, defaultValue: `true`.***
125
- * @default true
126
- */
127
- avoidWhiteSpace?: boolean;
128
- /** ***Custom characters to replace the default number set if `type` is `"number"`, defaultValue: `undefined`.***
129
- * @default undefined
130
- */
131
- replaceGenInt?: string;
132
- /** ***Custom characters to replace the default string set if `type` is `"string"`, defaultValue: `undefined`.***
133
- * @default undefined
134
- */
135
- replaceGenStr?: string;
136
- /** ***Additional characters to include in the generated string, defaultValue: `undefined`.***
137
- * @default undefined
138
- */
139
- addChar?: string;
140
- /** ***Minimum length of the generated string (1 to 5000), defaultValue: `40`.***
141
- * @default 40
142
- */
143
- minLength?: number;
144
- /** ***Maximum length of the generated string (1 to 5000), defaultValue: `40`.***
145
- * @default 40
146
- */
147
- maxLength?: number;
148
- /** ***Type of output: `"string"` or `"number"`, defaultValue: `"string"`.***
149
- * @default "string"
150
- */
151
- type?: "string" | "number";
152
- };
153
-
154
- /** ---------------------------------------------------------------------------------
155
- * * ***Utility: `randomStr`.***
156
- * ---------------------------------------------------------------------------------
157
- * **Generates a random alphanumeric string or number with a specified length range.**
158
- * @description
159
- * This function allows you to generate random strings or numbers with fully
160
- * customizable options, such as length range, character sets, inclusion of
161
- * additional characters, and whether to avoid whitespace.
162
- * @param {OptionsRandomStr} [options] - Configuration options for generating the string.
163
- * @param {OptionsRandomStr["minLength"]} [options.minLength=40] - Minimum length of the generated string (must be `≥` `1`).
164
- * @param {OptionsRandomStr["maxLength"]} [options.maxLength=40] - Maximum length of the generated string (must be `≤` `5000`).
165
- * @param {OptionsRandomStr["type"]} [options.type="string"] - Whether to generate a general alphanumeric string or purely numeric string.
166
- * @param {OptionsRandomStr["avoidWhiteSpace"]} [options.avoidWhiteSpace=true] - If true, removes all whitespace, tabs, and newlines from the character set before generating.
167
- * @param {OptionsRandomStr["replaceGenStr"]} [options.replaceGenStr] - A custom character set to use when `type` is `"string"`.
168
- * @param {OptionsRandomStr["replaceGenInt"]} [options.replaceGenInt] - A custom character set to use when `type` is `"number"`.
169
- * @param {OptionsRandomStr["addChar"]} [options.addChar] - Additional characters to always include in the character set.
170
- * @returns {string} The randomly generated string or numeric string of the desired length.
171
- * @throws **{@link TypeError | `TypeError`}** if provided options are invalid (such as minLength > maxLength, invalid type, or empty character set).
172
- * @example
173
- * randomStr();
174
- * // ➔ Generates a 40-character random alphanumeric string
175
- * randomStr({ minLength: 10, maxLength: 20 });
176
- * // ➔ Generates a string between 10 and 20 characters
177
- * randomStr({ type: "number", minLength: 5, maxLength: 5 });
178
- * // ➔ "48302"
179
- * randomStr({ replaceGenStr: "ABC ", avoidWhiteSpace: false });
180
- * // ➔ String using A, B, C and space
181
- * randomStr({ addChar: "!@#", minLength: 15, maxLength: 15 });
182
- * // ➔ Guaranteed to include !@# in the set
183
- */
184
- declare const randomStr: (options?: OptionsRandomStr) => string;
185
-
186
- /**
187
- * Configuration options for `randomUUID()`.
188
- */
189
- type OptionsRandomUUID = {
190
- /**
191
- * Specifies which UUID version to generate.
192
- *
193
- * - `"v4"` — Fully random UUID (RFC 4122). No timestamp, no ordering guarantees.
194
- * - `"v7"` — Time-ordered UUID (RFC 9562). Uses Unix timestamp + randomness.
195
- *
196
- * @default "v4"
197
- *
198
- * @example
199
- * // Random v4 UUID
200
- * randomUUID({ version: "v4" }); // ➔ "3ec0de5a-b8a9-4ffb-a62a-fcc76851e9c2"
201
- *
202
- * @example
203
- * // Time-ordered v7 UUID
204
- * randomUUID({ version: "v7" }); // ➔ "0199f3f6-3c5e-744b-affa-46b2cfd496f8"
205
- */
206
- version?: "v4" | "v7";
207
- /**
208
- * Enables monotonic sequencing for UUID v7.
209
- *
210
- * - Guarantees that multiple UUIDs generated within the same millisecond
211
- * are strictly non-decreasing (lexicographically and timestamp-wise).
212
- * - Only valid when `version === "v7"`. Using with `v4` will throw a `TypeError`.
213
- * - Useful for database inserts, logs, or any system where order matters.
214
- *
215
- * @default false
216
- *
217
- * @example
218
- * // Monotonic v7 UUIDs
219
- * const a = randomUUID({ version: "v7", monotonic: true });
220
- * const b = randomUUID({ version: "v7", monotonic: true });
221
- * console.log(a < b); // true, guaranteed
222
- */
223
- monotonic?: boolean;
224
- };
225
- /** -----------------------------------------------------------------------
226
- * * ***Utility: `randomUUID`.***
227
- * ------------------------------------------------------------------------
228
- * **Generates a UUID string according to the specified version and options.**
229
- *
230
- * - **Supported versions**:
231
- * - **`"v4"` (default)** ➔ Fully random UUID, RFC 4122 compliant.
232
- * - Uses `crypto.randomUUID()` if available.
233
- * - Falls back to `crypto.getRandomValues()` or `Math.random()`
234
- * if needed.
235
- * - **`"v7"`** ➔ Time-ordered UUID, RFC 9562 compliant.
236
- * - Timestamp (Unix ms, 48 bits) + 80 bits randomness.
237
- * - Good for database indexing / sorting.
238
- * - **`"v7"` + `monotonic: true`** ➔ Ensures strictly non-decreasing UUIDs
239
- * for multiple calls in the same millisecond (per-process).
240
- *
241
- * - **Behavior / Safety Notes**:
242
- * - **v4**: Fully random; probability of duplicates is astronomically low.
243
- * - **v7**: Time-ordered; collisions extremely unlikely unless same ms + random repeat.
244
- * - **Monotonic v7**: Guaranteed ordering per-process if multiple UUIDs are generated
245
- * in the same millisecond.
246
- * - **All versions**: Fallback safely if `crypto` APIs are unavailable.
247
- *
248
- * @param {object} [options] - Optional settings object.
249
- * @param {"v4" | "v7"} [options.version="v4"] - UUID version to generate.
250
- * @param {boolean} [options.monotonic=false] - For v7 only: generate monotonic UUIDs
251
- * to maintain strict lexicographic order
252
- * when generating multiple UUIDs within the same ms.
253
- *
254
- * @returns {string} A 36-character UUID string compliant with the selected version.
255
- *
256
- * @throws **{@link TypeError | `TypeError`}** if:
257
- * - `options` is not a plain object.
258
- * - `options.version` is provided but not a string.
259
- * - `options.monotonic` is provided but not a boolean.
260
- * - `monotonic: true` is used with `version` other than `"v7"`.
261
- * @throws **{@link RangeError | `RangeError`}** if `options.version` is provided but not `"v4"` or `"v7"`.
262
- *
263
- * @example
264
- * // Default (v4)
265
- * const id = randomUUID();
266
- * // ➔ "3b12f1df-5232-4804-897e-917bf397618a"
267
- *
268
- * @example
269
- * // Explicit v4
270
- * const id4 = randomUUID({ version: "v4" });
271
- *
272
- * @example
273
- * // Time-ordered v7
274
- * const id7 = randomUUID({ version: "v7" });
275
- * // ➔ "018f48d2-84c1-7ccd-b5a3-2f9463b3a889"
276
- *
277
- * @example
278
- * // Monotonic v7
279
- * const a = randomUUID({ version: "v7", monotonic: true });
280
- * const b = randomUUID({ version: "v7", monotonic: true });
281
- * // a < b lexicographically (guaranteed)
282
- *
283
- * @example
284
- * // Throws TypeError
285
- * randomUUID("v4" as any); // options must be object
286
- * randomUUID({ version: 123 as any }); // version must be string
287
- * randomUUID({ version: "v4", monotonic: true } as any); // monotonic only for v7
288
- *
289
- * @example
290
- * // Throws RangeError
291
- * randomUUID({ version: "v1" as any }); // unsupported version
292
- */
293
- declare function randomUUID(options?: OptionsRandomUUID): string;
294
-
295
- /**
296
- * --------------------------------------------------
297
- * * ***Utility: `noop`.***
298
- * --------------------------------------------------
299
- * **A no-operation function that performs no action.**
300
- *
301
- * @description
302
- * Commonly used as a **placeholder**, **default callback**, or **stub function**.
303
- *
304
- * - **Behavior**:
305
- * - Does not return any meaningful value (`void`).
306
- * - Safely callable in any context without side effects.
307
- *
308
- * @remarks
309
- * Although this function returns `void`, it implicitly results in `undefined`,
310
- * but the return value should never be relied upon.
311
- *
312
- * @example
313
- * **1. Basic usage** — does nothing and returns undefined implicitly:
314
- * ```
315
- * import { noop } from "@rzl-zone/utils-js/generators";
316
- *
317
- * noop(); // ➔ no effect (void)
318
- * ```
319
- * @example
320
- * **2. Using with type-checking helpers:**
321
- * ```ts
322
- * import { noop } from "@rzl-zone/utils-js/generators";
323
- * import { isFunction, isUndefined } from "@rzl-zone/utils-js/predicates";
324
- *
325
- * isFunction(noop); // ➔ true — `noop` is a function
326
- * isUndefined(noop()); // ➔ true — calling `noop()` returns `undefined`
327
- * isFunction(noop()); // ➔ false — the return value is `undefined`, not a function
328
- * ```
329
- * @example
330
- * **3. As a default callback:**
331
- * ```ts
332
- * import { noop } from "@rzl-zone/utils-js/generators";
333
- *
334
- * const callback = noop;
335
- * callback(); // ➔ no effect (void)
336
- * ```
337
- */
338
- declare const noop: () => void;
339
-
2
+ * ========================================================================
3
+ * @rzl-zone/utils-js
4
+ * ------------------------------------------------------------------------
5
+ * Version: `3.12.1-beta.1`
6
+ * Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
7
+ * Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
8
+ * ========================================================================
9
+ */
10
+
11
+ import { a as randomInt, i as randomIntByLength, n as randomUUID, o as getRandomItem, r as randomStr, t as noop } from "../index-59zbLcPr.js";
340
12
  export { getRandomItem, noop, randomInt, randomIntByLength, randomStr, randomUUID };
@@ -1,15 +1,159 @@
1
1
  /*!
2
- * ====================================================
3
- * Rzl Utils-JS.
4
- * ----------------------------------------------------
5
- * Version: 3.12.0.
6
- * Author: Rizalvin Dwiky.
7
- * Repository: https://github.com/rzl-zone/utils-js.
8
- * ====================================================
9
- */
10
- export { getRandomItem, randomInt, randomIntByLength, randomStr, randomUUID } from '../chunk-JS6R55VL.js';
11
- import '../chunk-WVSPXFTY.js';
12
- export { noop } from '../chunk-YWHHVDT4.js';
13
- import '../chunk-6VUXD3CF.js';
14
- import '../chunk-QNKGP5DY.js';
15
- import '../chunk-CSG4SCL3.js';
2
+ * ========================================================================
3
+ * @rzl-zone/utils-js
4
+ * ------------------------------------------------------------------------
5
+ * Version: `3.12.1-beta.1`
6
+ * Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
7
+ * Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
8
+ * ========================================================================
9
+ */
10
+ import { A as isPlainObject, D as isNaN, F as isBoolean, p as isNonEmptyArray, r as getPreciseType, t as assertIsBoolean, w as isNumber, y as isNonEmptyString } from "../assertIsBoolean-DR1SaXPD.js";
11
+ import { t as safeStableStringify } from "../safeStableStringify-CXOZ9Ub8.js";
12
+ import { t as noop } from "../noop-ubqAIbHD.js";
13
+ import { t as isInteger } from "../isInteger-naMbJsxJ.js";
14
+ function getRandomItem(array) {
15
+ if (!isNonEmptyArray(array)) return void 0;
16
+ return array[Math.floor(Math.random() * (array.length || 0))];
17
+ }
18
+ const randomInt = (min, max) => {
19
+ if (!isInteger(min) || !isInteger(max)) throw new TypeError(`First parameter (\`min\`) and second parameter (\`max\`) must be of type \`integer-number\`${minValueNote(min, max)}value, but received: ['min': \`${getPreciseType(min)}\` - (with value: \`${safeStableStringify(min, { keepUndefined: true })})\`, 'max': \`${getPreciseType(max)}\` - (with value: \`${safeStableStringify(max, { keepUndefined: true })}\`)].`);
20
+ if (min > max) throw new RangeError(`First parameter (\`min\`) must be less than or equal to second parameter (\`max\`), but received: ['min': ${formatValue(min)} - (with value: \`${safeStableStringify(min, { keepUndefined: true })})\`, 'max': ${formatValue(max)} - (with value: \`${safeStableStringify(max, { keepUndefined: true })})\`].`);
21
+ min = Math.max(1, min);
22
+ max = Math.min(Number.MAX_SAFE_INTEGER, max);
23
+ return Math.floor(Math.random() * (max - min + 1)) + min;
24
+ };
25
+ const formatValue = (value) => {
26
+ return isNumber(value, { includeNaN: true }) ? value === Number.MIN_VALUE ? "`Number.MIN_VALUE`" : `${value}` : `\`${getPreciseType(value)}\``;
27
+ };
28
+ const minValueNote = (...values) => {
29
+ return values.some((v) => isNumber(v, { includeNaN: true }) && v === Number.MIN_VALUE) ? " and can't be `Number.MIN_VALUE` " : " ";
30
+ };
31
+ const randomIntByLength = (options) => {
32
+ if (!isPlainObject(options)) options = {};
33
+ const { minLength = 1, maxLength = 16, avoidZero = false } = options;
34
+ assertIsBoolean(avoidZero, { message({ currentType, validType }) {
35
+ return `Parameters \`avoidZero\` must be of type \`${validType}\`, but received: \`${currentType}\`.`;
36
+ } });
37
+ if (!isInteger(minLength) || !isInteger(maxLength)) throw new TypeError(`Parameters \`minLength\` and \`maxLength\` must be of type \`integer-number\`, but received: ['minLength': \`${getPreciseType(minLength)}\` - (with value: ${safeStableStringify(minLength, { keepUndefined: true })}), 'maxLength': \`${getPreciseType(maxLength)}\` - (with value: ${safeStableStringify(maxLength, { keepUndefined: true })})].`);
38
+ if (minLength < 1 || maxLength > 16 || minLength > maxLength) throw new RangeError(`Invalid range at parameters \`minLength\` must be ≥ 1, \`maxLength\` must be ≤ 16, and \`minLength\` ≤ \`maxLength\`, but received: ['minLength': \`${minLength}\`, 'maxLength': \`${maxLength}\`].`);
39
+ const randomLength = minLength === maxLength ? minLength : randomInt(minLength, maxLength);
40
+ const minValue = 10 ** (randomLength - 1);
41
+ let result = randomInt(minValue, 10 ** randomLength - 1);
42
+ if (avoidZero && result === 0) result = minValue;
43
+ return result;
44
+ };
45
+ const randomStr = (options) => {
46
+ if (!isPlainObject(options)) options = {};
47
+ const { minLength = 40, maxLength = 40, type = "string", avoidWhiteSpace = true } = options;
48
+ assertIsBoolean(avoidWhiteSpace, { message({ currentType, validType }) {
49
+ return `Parameters \`avoidWhiteSpace\` property of the \`options\` (first-parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`;
50
+ } });
51
+ if (!isInteger(minLength) || !isInteger(maxLength)) throw new TypeError(`Parameters \`minLength\` and \`maxLength\` must be of type \`integer-number\`, but received: ['minLength': \`${getPreciseType(minLength)}\` - (with value: ${safeStableStringify(minLength, { keepUndefined: true })}), 'maxLength': \`${getPreciseType(maxLength)}\` - (with value: ${safeStableStringify(maxLength, { keepUndefined: true })})].`);
52
+ if (minLength < 1 || maxLength > 5e3 || minLength > maxLength) throw new RangeError(`Invalid range at parameters \`minLength\` must be ≥ 1, \`maxLength\` must be ≤ 5000, and \`minLength\` ≤ \`maxLength\`, but received: ['minLength': \`${minLength}\`, 'maxLength': \`${maxLength}\`].`);
53
+ if (type !== "string" && type !== "number") throw new TypeError(`Parameter \`type\` must be of type \`string\` with value one of "string" | "number", but received: \`${getPreciseType(type)}\`, with value: ${safeStableStringify(type, { keepUndefined: true })}.`);
54
+ const length = randomInt(minLength, maxLength);
55
+ const cleanCharacters = (charSet) => {
56
+ return avoidWhiteSpace ? charSet.replace(/\s|\n|\t/g, "") : charSet;
57
+ };
58
+ const characterSet = cleanCharacters(type === "number" ? (!isNaN(Number(options.replaceGenInt)) ? options.replaceGenInt : void 0) ?? "0123456789" : (options.replaceGenStr ? options.replaceGenStr : void 0) ?? "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") + (options.addChar || "");
59
+ if (!characterSet.length) {
60
+ const errCharSet = () => {
61
+ if (type === "number") {
62
+ if (avoidWhiteSpace) return "If `avoidWhiteSpace` is true, and `replaceGenInt` cant be empty-string value, ensure `replaceGenInt` has valid characters and non-nan string number.";
63
+ return "Ensure `replaceGenInt` has valid characters and not a NaN number string while convert to number.";
64
+ }
65
+ return "Ensure `replaceGenStr` has valid characters and non empty string.";
66
+ };
67
+ throw new Error(`Character set is empty. ${errCharSet()}`);
68
+ }
69
+ let result = "";
70
+ for (let i = 0; i < length; i++) result += characterSet.charAt(Math.floor(Math.random() * characterSet.length));
71
+ return result;
72
+ };
73
+ function randomUUID(options = {}) {
74
+ if (!isPlainObject(options)) throw new TypeError(`First parameter (\`options\`) must be a plain object with optional properties \`version\` and \`monotonic\`, but received: \`${getPreciseType(options)}\` - (with value: \`${safeStableStringify(options, { keepUndefined: true })}\`).`);
75
+ const { version = "v4", monotonic = false } = options;
76
+ if (!isNonEmptyString(version)) throw new TypeError(`Parameter \`version\` property of the \`options\` (first parameter) must be a \`string\` of either "v4" or "v7", but received type: \`${getPreciseType(version)}\` - (with value: \`${safeStableStringify(version, { keepUndefined: true })}\`).`);
77
+ if (version !== "v4" && version !== "v7") throw new RangeError(`Unsupported UUID version. Allowed values are "v4" or "v7". (received: \`${safeStableStringify(version, { keepUndefined: true })}\`).`);
78
+ if (!isBoolean(monotonic)) throw new TypeError(`Parameter \`monotonic\` property of the \`options\` (first parameter) must be a \`boolean\` when provided, but received type: \`${getPreciseType(monotonic)}\` - (with value: \`${safeStableStringify(monotonic, { keepUndefined: true })}\`).`);
79
+ if (monotonic && version !== "v7") throw new TypeError(`Parameter \`monotonic\` property of the \`options\` (first parameter) is only supported for version "v7". Received: version=${safeStableStringify(version, { keepUndefined: true })}.`);
80
+ if (version === "v4") return generateUUIDv4();
81
+ return generateUUIDv7({ monotonic });
82
+ }
83
+ function hasCryptoGetRandomValues() {
84
+ return typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function";
85
+ }
86
+ function hasCryptoRandomUUID() {
87
+ return typeof crypto !== "undefined" && typeof crypto.randomUUID === "function";
88
+ }
89
+ function getRandomBytes(len) {
90
+ if (hasCryptoGetRandomValues()) return crypto.getRandomValues(new Uint8Array(len));
91
+ const arr = new Uint8Array(len);
92
+ for (let i = 0; i < len; i++) arr[i] = Math.floor(Math.random() * 256);
93
+ return arr;
94
+ }
95
+ const byteToHex = (() => {
96
+ const arr = [];
97
+ for (let i = 0; i < 256; ++i) arr.push((i + 256).toString(16).substring(1));
98
+ return arr;
99
+ })();
100
+ function generateUUIDv4() {
101
+ if (hasCryptoRandomUUID()) return crypto.randomUUID();
102
+ if (hasCryptoGetRandomValues()) {
103
+ const rnd = crypto.getRandomValues(new Uint8Array(16));
104
+ if (!rnd[0] || !rnd[1] || !rnd[2] || !rnd[3] || !rnd[4] || !rnd[5] || !rnd[6] || !rnd[7] || !rnd[8] || !rnd[9] || !rnd[10] || !rnd[11] || !rnd[12] || !rnd[13] || !rnd[14] || !rnd[15]) return "";
105
+ const byteToHex0 = byteToHex[rnd[0]];
106
+ const byteToHex1 = byteToHex[rnd[1]];
107
+ if (!byteToHex0 || !byteToHex1) return "";
108
+ rnd[6] = rnd[6] & 15 | 64;
109
+ rnd[8] = rnd[8] & 63 | 128;
110
+ return byteToHex0 + byteToHex1 + byteToHex[rnd[2]] + byteToHex[rnd[3]] + "-" + byteToHex[rnd[4]] + byteToHex[rnd[5]] + "-" + byteToHex[rnd[6]] + byteToHex[rnd[7]] + "-" + byteToHex[rnd[8]] + byteToHex[rnd[9]] + "-" + byteToHex[rnd[10]] + byteToHex[rnd[11]] + byteToHex[rnd[12]] + byteToHex[rnd[13]] + byteToHex[rnd[14]] + byteToHex[rnd[15]];
111
+ }
112
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
113
+ const r = Math.random() * 16 | 0;
114
+ return (c === "x" ? r : r & 3 | 8).toString(16);
115
+ });
116
+ }
117
+ const monotonicState = {
118
+ lastTimestampMs: -1,
119
+ lastRand: null
120
+ };
121
+ function incrementUint8ArrayBigEndian(arr) {
122
+ for (let i = arr.length - 1; i >= 0; i--) {
123
+ if (arr[i] === 255) {
124
+ arr[i] = 0;
125
+ continue;
126
+ }
127
+ arr[i] = arr[i] + 1 & 255;
128
+ return false;
129
+ }
130
+ return true;
131
+ }
132
+ function generateUUIDv7({ monotonic = false } = {}) {
133
+ const nowMs = Date.now();
134
+ const tsHex = BigInt(nowMs).toString(16).padStart(12, "0");
135
+ let rand = getRandomBytes(10);
136
+ if (monotonic) if (monotonicState.lastTimestampMs === nowMs && monotonicState.lastRand) {
137
+ const copy = new Uint8Array(monotonicState.lastRand);
138
+ if (incrementUint8ArrayBigEndian(copy)) throw new RangeError("Monotonic UUID sequence overflow: too many UUIDs generated within the same millisecond.");
139
+ rand = copy;
140
+ monotonicState.lastRand = copy;
141
+ } else {
142
+ const fresh = getRandomBytes(10);
143
+ monotonicState.lastRand = new Uint8Array(fresh);
144
+ monotonicState.lastTimestampMs = nowMs;
145
+ rand = fresh;
146
+ }
147
+ rand[0] = rand[0] ? rand[0] & 15 | 112 : 0;
148
+ rand[2] = rand[2] ? rand[2] & 63 | 128 : 0;
149
+ const randHex = Array.from(rand, (b) => byteToHex[b]).join("");
150
+ return [
151
+ tsHex.slice(0, 8),
152
+ tsHex.slice(8, 12),
153
+ randHex.slice(0, 4),
154
+ randHex.slice(4, 8),
155
+ randHex.slice(8, 20)
156
+ ].join("-");
157
+ }
158
+ export { getRandomItem, noop, randomInt, randomIntByLength, randomStr, randomUUID };
159
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/generators/random/array/getRandomItem.ts","../../src/generators/random/integer/randomInt.ts","../../src/generators/random/integer/randomIntByLength.ts","../../src/generators/random/string/randomStr.ts","../../src/generators/random/uuid/randomUUID.ts"],"sourcesContent":["import type {\n Extends,\n FixNeverArrayRecursive,\n IfNonEmptyArray,\n NullToUndefined\n} from \"@rzl-zone/ts-types-plus\";\n\nimport { isNonEmptyArray } from \"@/predicates/is/isNonEmptyArray\";\n\n/** ---------------------------------\n * * ***Utility: `getRandomItem`.***\n * ---------------------------------\n * **Function to get a random element from a given array.**\n * @template T - The type of the input array.\n * @param {*} array - The input array, can be `null`, `undefined`, or an empty array.\n * @returns\n * - If `array` is a non-empty tuple, returns one of its elements.\n * - If `array` is empty, `null`, or `undefined`, returns `undefined`.\n * @example\n * getRandomItem([]);\n * // ➔ undefined\n * getRandomItem(null);\n * // ➔ undefined\n * getRandomItem(undefined);\n * // ➔ undefined\n * getRandomItem([1, 2, 3, 4]);\n * // ➔ number\n * getRandomItem([\"apple\", \"banana\", \"cherry\"]);\n * // ➔ string\n * getRandomItem([\"apple\", 123, true]);\n * // ➔ string | number | boolean\n * getRandomItem([\"apple\", 123, true, null]);\n * // ➔ string | number | boolean | undefined\n * getRandomItem([\"apple\", 123, true, undefined]);\n * // ➔ string | number | boolean | undefined\n *\n * // Tuple example:\n * const tuple = [1, \"two\", true] as const;\n * getRandomItem(tuple); // 1 | \"two\" | true\n */\nexport function getRandomItem(array: undefined): undefined;\nexport function getRandomItem(array: []): undefined;\nexport function getRandomItem<T extends readonly unknown[]>(\n array: T\n): T extends never[][]\n ? undefined\n : number extends T[\"length\"]\n ? NullToUndefined<FixNeverArrayRecursive<T[number]>>\n : IfNonEmptyArray<\n T,\n NullToUndefined<FixNeverArrayRecursive<T[number]>>,\n undefined\n >;\nexport function getRandomItem<T extends readonly unknown[] | undefined | null>(\n array: T\n): T extends readonly unknown[]\n ? NullToUndefined<FixNeverArrayRecursive<T[number]>> | undefined\n : undefined;\nexport function getRandomItem<T>(array: T): unknown extends T\n ? unknown\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Extends<any[] | readonly any[], T> extends true\n ? Extract<T, unknown[] | readonly unknown[]>[number] | undefined\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Extends<any[], T> extends true\n ? Extract<T, unknown[] | readonly unknown[]>[number] | undefined\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Extends<readonly any[], T> extends true\n ? Extract<T, unknown[] | readonly unknown[]>[number] | undefined\n : undefined;\nexport function getRandomItem(array: unknown): unknown {\n if (!isNonEmptyArray(array)) return undefined;\n\n const randomIndex = Math.floor(Math.random() * (array.length || 0));\n return array[randomIndex];\n}\n","import { isNumber } from \"@/predicates/is/isNumber\";\nimport { isInteger } from \"@/predicates/is/isInteger\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\n\n/** -----------------------------------------------------------------------\n * * ***Utility: `randomInt`.***\n * ------------------------------------------------------------------------\n * **Generates a random integer within a specified range (inclusive).**\n * - **Generates a random integer between `min` and `max` (inclusive), with safety constraints:**\n * - `min` will be forced to be at least `1`.\n * - `max` will be capped at `Number.MAX_SAFE_INTEGER`.\n * @param {number} min - The minimum value (inclusive), must be an integer.\n * @param {number} max - The maximum value (inclusive), must be an integer.\n * @returns {number} A random integer N where `min ≤ N ≤ max`.\n * @throws **{@link TypeError | `TypeError`}** if:\n * - `min` or `max` is not an integer, or value is `Number.MIN_VALUE`.\n * - `min` is greater than `max`.\n * @example\n * randomInt(1, 10); // ➔ returns 1 up-to 10 (random)\n * randomInt(50, 100); // ➔ returns 50 up-to 100 (random)\n * randomInt(5, 5); // ➔ always returns 5 (exact)\n * randomInt(-5, 3); // ➔ always returns ≥ 1, since min is adjusted (exact)\n * randomInt(1, Number.MAX_SAFE_INTEGER + 10000);\n * // ➔ still safely capped at MAX_SAFE_INTEGER\n * randomInt(Number.MIN_VALUE, 3);\n * // ➔ Error, min or max cant be as `Number.MIN_VALUE` value.\n */\nexport const randomInt = (min: number, max: number): number => {\n if (!isInteger(min) || !isInteger(max)) {\n throw new TypeError(\n `First parameter (\\`min\\`) and second parameter (\\`max\\`) must be of type \\`integer-number\\`${minValueNote(\n min,\n max\n )}value, but received: ['min': \\`${getPreciseType(\n min\n )}\\` - (with value: \\`${safeStableStringify(min, {\n keepUndefined: true\n })})\\`, 'max': \\`${getPreciseType(max)}\\` - (with value: \\`${safeStableStringify(\n max,\n {\n keepUndefined: true\n }\n )}\\`)].`\n );\n }\n if (min > max) {\n throw new RangeError(\n `First parameter (\\`min\\`) must be less than or equal to second parameter (\\`max\\`), but received: ['min': ${formatValue(\n min\n )} - (with value: \\`${safeStableStringify(min, {\n keepUndefined: true\n })})\\`, 'max': ${formatValue(max)} - (with value: \\`${safeStableStringify(\n max,\n {\n keepUndefined: true\n }\n )})\\`].`\n );\n }\n\n // Ensure `min` is at least 1\n min = Math.max(1, min);\n\n // Ensure `max` does not exceed Number.MAX_SAFE_INTEGER\n max = Math.min(Number.MAX_SAFE_INTEGER, max);\n\n return Math.floor(Math.random() * (max - min + 1)) + min;\n};\n\nconst formatValue = (value: unknown): string => {\n return isNumber(value, { includeNaN: true })\n ? value === Number.MIN_VALUE\n ? \"`Number.MIN_VALUE`\"\n : `${value}`\n : `\\`${getPreciseType(value)}\\``;\n};\n\nconst minValueNote = (...values: unknown[]) => {\n return values.some(\n (v) => isNumber(v, { includeNaN: true }) && v === Number.MIN_VALUE\n )\n ? \" and can't be `Number.MIN_VALUE` \"\n : \" \";\n};\n","import { randomInt } from \"./randomInt\";\nimport { isInteger } from \"@/predicates/is/isInteger\";\nimport { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { assertIsBoolean } from \"@/assertions/booleans/assertIsBoolean\";\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\n\ntype OptionsRandomIntByLength = {\n /** * Minimum length of the random number, the `allowed minimal value` `integer` is `1` `and not bigger than value of` `maxLength`, defaultValue: `1`.\n *\n * @default 1\n */\n minLength?: number;\n /** * Maximum length of the random number, the `allowed maximal value` `integer` is `16`, defaultValue: `16`.\n *\n * @default 16\n */\n maxLength?: number;\n /** * If true, prevents the result from being zero, defaultValue: `false`.\n *\n * @default false\n */\n avoidZero?: boolean;\n};\n\n/** ----------------------------------------------------------------------------\n * * ***Utility: `randomIntByLength`.***\n * -----------------------------------------------------------------------------\n * **Generates a random integer within a specified range of digit lengths.**\n * @description\n * This function allows generating random integers that strictly conform to a specified minimum and\n * maximum digit length, it is useful for scenarios such as generating realistic-looking IDs, codes,\n * or random test data.\n * - **The function ensures:**\n * - `minLength` is at least 1 and not greater than `maxLength`.\n * - `maxLength` is no more than 16 (due to JavaScript's `Number.MAX_SAFE_INTEGER`).\n * - If `avoidZero` is `true`, ensures that `0` is never returned.\n * @param {OptionsRandomIntByLength} [options] - Configuration options.\n * @param {OptionsRandomIntByLength[\"minLength\"]} [options.minLength=1] - Minimum number of digits (must be ≥ `1` and ≤ `maxLength`).\n * @param {OptionsRandomIntByLength[\"maxLength\"]} [options.maxLength=16] - Maximum number of digits (must be ≤ `16`).\n * @param {OptionsRandomIntByLength[\"avoidZero\"]} [options.avoidZero=false] - If true, will ensure the result is never zero.\n * @returns {number} A randomly generated integer within the specified constraints.\n * @throws **{@link TypeError | `TypeError`}** if parameters are invalid, such as:\n * - `minLength` < `1`\n * - `maxLength` > `16`\n * - `minLength` > `maxLength`\n * - non-integer values for `minLength` or `maxLength`\n * @example\n * randomIntByLength({ minLength: 3, maxLength: 5 });\n * // ➔ `4829` (random), `192` (random) or `71492` (random).\n * randomIntByLength({ minLength: 4, maxLength: 4 });\n * // ➔ `5930` (exact 4 digits)\n * randomIntByLength({ avoidZero: true });\n * // ➔ never 0\n */\nexport const randomIntByLength = (\n options?: OptionsRandomIntByLength\n): number => {\n // Ensure options is an object and Defensive options check\n if (!isPlainObject(options)) {\n options = {};\n }\n\n const { minLength = 1, maxLength = 16, avoidZero = false } = options;\n\n assertIsBoolean(avoidZero, {\n message({ currentType, validType }) {\n return `Parameters \\`avoidZero\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`;\n }\n });\n\n // Validate `minLength` & `maxLength` type\n if (!isInteger(minLength) || !isInteger(maxLength)) {\n throw new TypeError(\n `Parameters \\`minLength\\` and \\`maxLength\\` must be of type \\`integer-number\\`, but received: ['minLength': \\`${getPreciseType(\n minLength\n )}\\` - (with value: ${safeStableStringify(minLength, {\n keepUndefined: true\n })}), 'maxLength': \\`${getPreciseType(\n maxLength\n )}\\` - (with value: ${safeStableStringify(maxLength, {\n keepUndefined: true\n })})].`\n );\n }\n\n // Validate `minLength` & `maxLength` range.\n if (minLength < 1 || maxLength > 16 || minLength > maxLength) {\n throw new RangeError(\n `Invalid range at parameters \\`minLength\\` must be ≥ 1, \\`maxLength\\` must be ≤ 16, and \\`minLength\\` ≤ \\`maxLength\\`, but received: ['minLength': \\`${minLength}\\`, 'maxLength': \\`${maxLength}\\`].`\n );\n }\n\n // Generate a random length between minLength and maxLength\n const randomLength =\n minLength === maxLength ? minLength : randomInt(minLength, maxLength);\n\n // Define min and max value based on the selected length\n const minValue = 10 ** (randomLength - 1); // Example: minLength=3 ➔ minValue=100\n const maxValue = 10 ** randomLength - 1; // Example: maxLength=4 ➔ maxValue=9999\n\n // Generate a random number within the valid range\n let result = randomInt(minValue, maxValue);\n\n // Ensure the number is not zero if `avoidZero` is true\n if (avoidZero && result === 0) {\n result = minValue; // Assign the smallest valid number instead of looping\n }\n\n return result;\n};\n","import type { OptionsRandomStr } from \"./_private/randomSTR.types\";\n\nimport { randomInt } from \"../integer/randomInt\";\n\nimport { isNaN } from \"@/predicates/is/isNaN\";\nimport { isInteger } from \"@/predicates/is/isInteger\";\nimport { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\n\nimport { assertIsBoolean } from \"@/assertions/booleans/assertIsBoolean\";\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\n\n/** ---------------------------------------------------------------------------------\n * * ***Utility: `randomStr`.***\n * ---------------------------------------------------------------------------------\n * **Generates a random alphanumeric string or number with a specified length range.**\n * @description\n * This function allows you to generate random strings or numbers with fully\n * customizable options, such as length range, character sets, inclusion of\n * additional characters, and whether to avoid whitespace.\n * @param {OptionsRandomStr} [options] - Configuration options for generating the string.\n * @param {OptionsRandomStr[\"minLength\"]} [options.minLength=40] - Minimum length of the generated string (must be `≥` `1`).\n * @param {OptionsRandomStr[\"maxLength\"]} [options.maxLength=40] - Maximum length of the generated string (must be `≤` `5000`).\n * @param {OptionsRandomStr[\"type\"]} [options.type=\"string\"] - Whether to generate a general alphanumeric string or purely numeric string.\n * @param {OptionsRandomStr[\"avoidWhiteSpace\"]} [options.avoidWhiteSpace=true] - If true, removes all whitespace, tabs, and newlines from the character set before generating.\n * @param {OptionsRandomStr[\"replaceGenStr\"]} [options.replaceGenStr] - A custom character set to use when `type` is `\"string\"`.\n * @param {OptionsRandomStr[\"replaceGenInt\"]} [options.replaceGenInt] - A custom character set to use when `type` is `\"number\"`.\n * @param {OptionsRandomStr[\"addChar\"]} [options.addChar] - Additional characters to always include in the character set.\n * @returns {string} The randomly generated string or numeric string of the desired length.\n * @throws **{@link TypeError | `TypeError`}** if provided options are invalid (such as minLength > maxLength, invalid type, or empty character set).\n * @example\n * randomStr();\n * // ➔ Generates a 40-character random alphanumeric string\n * randomStr({ minLength: 10, maxLength: 20 });\n * // ➔ Generates a string between 10 and 20 characters\n * randomStr({ type: \"number\", minLength: 5, maxLength: 5 });\n * // ➔ \"48302\"\n * randomStr({ replaceGenStr: \"ABC \", avoidWhiteSpace: false });\n * // ➔ String using A, B, C and space\n * randomStr({ addChar: \"!@#\", minLength: 15, maxLength: 15 });\n * // ➔ Guaranteed to include !@# in the set\n */\nexport const randomStr = (options?: OptionsRandomStr): string => {\n // Ensure options is an object and Defensive options check\n if (!isPlainObject(options)) {\n options = {};\n }\n\n const {\n minLength = 40,\n maxLength = 40,\n type = \"string\",\n avoidWhiteSpace = true\n } = options;\n\n // Validate `avoidWhiteSpace`\n assertIsBoolean(avoidWhiteSpace, {\n message({ currentType, validType }) {\n return `Parameters \\`avoidWhiteSpace\\` property of the \\`options\\` (first-parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`;\n }\n });\n\n // Validate `minLength` & `maxLength` type\n if (!isInteger(minLength) || !isInteger(maxLength)) {\n throw new TypeError(\n `Parameters \\`minLength\\` and \\`maxLength\\` must be of type \\`integer-number\\`, but received: ['minLength': \\`${getPreciseType(\n minLength\n )}\\` - (with value: ${safeStableStringify(minLength, {\n keepUndefined: true\n })}), 'maxLength': \\`${getPreciseType(\n maxLength\n )}\\` - (with value: ${safeStableStringify(maxLength, {\n keepUndefined: true\n })})].`\n );\n }\n\n // Validate `minLength` & `maxLength` range.\n if (minLength < 1 || maxLength > 5000 || minLength > maxLength) {\n throw new RangeError(\n `Invalid range at parameters \\`minLength\\` must be ≥ 1, \\`maxLength\\` must be ≤ 5000, and \\`minLength\\` ≤ \\`maxLength\\`, but received: ['minLength': \\`${minLength}\\`, 'maxLength': \\`${maxLength}\\`].`\n );\n }\n\n // Validate `type` value props (is not typeof)\n if (type !== \"string\" && type !== \"number\") {\n throw new TypeError(\n `Parameter \\`type\\` must be of type \\`string\\` with value one of \"string\" | \"number\", but received: \\`${getPreciseType(\n type\n )}\\`, with value: ${safeStableStringify(type, {\n keepUndefined: true\n })}.`\n );\n }\n\n // Generate a random length within the range\n const length = randomInt(minLength, maxLength);\n\n // Function to clean characters based on `avoidWhiteSpace`\n const cleanCharacters = (charSet: string) => {\n return avoidWhiteSpace ? charSet.replace(/\\s|\\n|\\t/g, \"\") : charSet;\n };\n\n // Define character sets\n const defaultNumberSet = \"0123456789\";\n const defaultStringSet =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\n const baseCharSet =\n type === \"number\"\n ? ((!isNaN(Number(options.replaceGenInt))\n ? options.replaceGenInt\n : undefined) ?? defaultNumberSet)\n : ((options.replaceGenStr ? options.replaceGenStr : undefined) ??\n defaultStringSet);\n\n // Get the final character set\n const characterSet = cleanCharacters(baseCharSet) + (options.addChar || \"\");\n\n // Ensure characterSet is not empty\n if (!characterSet.length) {\n const errCharSet = () => {\n if (type === \"number\") {\n if (avoidWhiteSpace) {\n return \"If `avoidWhiteSpace` is true, and `replaceGenInt` cant be empty-string value, ensure `replaceGenInt` has valid characters and non-nan string number.\";\n }\n return \"Ensure `replaceGenInt` has valid characters and not a NaN number string while convert to number.\";\n }\n return \"Ensure `replaceGenStr` has valid characters and non empty string.\";\n };\n\n throw new Error(`Character set is empty. ${errCharSet()}`);\n }\n\n // Generate random string\n let result = \"\";\n for (let i = 0; i < length; i++) {\n result += characterSet.charAt(\n Math.floor(Math.random() * characterSet.length)\n );\n }\n\n return result;\n};\n","import { isBoolean } from \"@/predicates/is/isBoolean\";\nimport { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\n\n/**\n * Configuration options for `randomUUID()`.\n */\ntype OptionsRandomUUID = {\n /**\n * Specifies which UUID version to generate.\n *\n * - `\"v4\"` — Fully random UUID (RFC 4122). No timestamp, no ordering guarantees.\n * - `\"v7\"` — Time-ordered UUID (RFC 9562). Uses Unix timestamp + randomness.\n *\n * @default \"v4\"\n *\n * @example\n * // Random v4 UUID\n * randomUUID({ version: \"v4\" }); // ➔ \"3ec0de5a-b8a9-4ffb-a62a-fcc76851e9c2\"\n *\n * @example\n * // Time-ordered v7 UUID\n * randomUUID({ version: \"v7\" }); // ➔ \"0199f3f6-3c5e-744b-affa-46b2cfd496f8\"\n */\n version?: \"v4\" | \"v7\";\n\n /**\n * Enables monotonic sequencing for UUID v7.\n *\n * - Guarantees that multiple UUIDs generated within the same millisecond\n * are strictly non-decreasing (lexicographically and timestamp-wise).\n * - Only valid when `version === \"v7\"`. Using with `v4` will throw a `TypeError`.\n * - Useful for database inserts, logs, or any system where order matters.\n *\n * @default false\n *\n * @example\n * // Monotonic v7 UUIDs\n * const a = randomUUID({ version: \"v7\", monotonic: true });\n * const b = randomUUID({ version: \"v7\", monotonic: true });\n * console.log(a < b); // true, guaranteed\n */\n monotonic?: boolean;\n};\n\n/** -----------------------------------------------------------------------\n * * ***Utility: `randomUUID`.***\n * ------------------------------------------------------------------------\n * **Generates a UUID string according to the specified version and options.**\n *\n * - **Supported versions**:\n * - **`\"v4\"` (default)** ➔ Fully random UUID, RFC 4122 compliant.\n * - Uses `crypto.randomUUID()` if available.\n * - Falls back to `crypto.getRandomValues()` or `Math.random()`\n * if needed.\n * - **`\"v7\"`** ➔ Time-ordered UUID, RFC 9562 compliant.\n * - Timestamp (Unix ms, 48 bits) + 80 bits randomness.\n * - Good for database indexing / sorting.\n * - **`\"v7\"` + `monotonic: true`** ➔ Ensures strictly non-decreasing UUIDs\n * for multiple calls in the same millisecond (per-process).\n *\n * - **Behavior / Safety Notes**:\n * - **v4**: Fully random; probability of duplicates is astronomically low.\n * - **v7**: Time-ordered; collisions extremely unlikely unless same ms + random repeat.\n * - **Monotonic v7**: Guaranteed ordering per-process if multiple UUIDs are generated\n * in the same millisecond.\n * - **All versions**: Fallback safely if `crypto` APIs are unavailable.\n *\n * @param {object} [options] - Optional settings object.\n * @param {\"v4\" | \"v7\"} [options.version=\"v4\"] - UUID version to generate.\n * @param {boolean} [options.monotonic=false] - For v7 only: generate monotonic UUIDs\n * to maintain strict lexicographic order\n * when generating multiple UUIDs within the same ms.\n *\n * @returns {string} A 36-character UUID string compliant with the selected version.\n *\n * @throws **{@link TypeError | `TypeError`}** if:\n * - `options` is not a plain object.\n * - `options.version` is provided but not a string.\n * - `options.monotonic` is provided but not a boolean.\n * - `monotonic: true` is used with `version` other than `\"v7\"`.\n * @throws **{@link RangeError | `RangeError`}** if `options.version` is provided but not `\"v4\"` or `\"v7\"`.\n *\n * @example\n * // Default (v4)\n * const id = randomUUID();\n * // ➔ \"3b12f1df-5232-4804-897e-917bf397618a\"\n *\n * @example\n * // Explicit v4\n * const id4 = randomUUID({ version: \"v4\" });\n *\n * @example\n * // Time-ordered v7\n * const id7 = randomUUID({ version: \"v7\" });\n * // ➔ \"018f48d2-84c1-7ccd-b5a3-2f9463b3a889\"\n *\n * @example\n * // Monotonic v7\n * const a = randomUUID({ version: \"v7\", monotonic: true });\n * const b = randomUUID({ version: \"v7\", monotonic: true });\n * // a < b lexicographically (guaranteed)\n *\n * @example\n * // Throws TypeError\n * randomUUID(\"v4\" as any); // options must be object\n * randomUUID({ version: 123 as any }); // version must be string\n * randomUUID({ version: \"v4\", monotonic: true } as any); // monotonic only for v7\n *\n * @example\n * // Throws RangeError\n * randomUUID({ version: \"v1\" as any }); // unsupported version\n */\nexport function randomUUID(options: OptionsRandomUUID = {}): string {\n // Validate options is a plain object if provided\n if (!isPlainObject(options)) {\n throw new TypeError(\n `First parameter (\\`options\\`) must be a plain object with optional properties \\`version\\` and \\`monotonic\\`, but received: \\`${getPreciseType(\n options\n )}\\` - (with value: \\`${safeStableStringify(options, { keepUndefined: true })}\\`).`\n );\n }\n\n const { version = \"v4\", monotonic = false } = options;\n\n // Validate version type\n if (!isNonEmptyString(version)) {\n throw new TypeError(\n `Parameter \\`version\\` property of the \\`options\\` (first parameter) must be a \\`string\\` of either \"v4\" or \"v7\", but received type: \\`${getPreciseType(\n version\n )}\\` - (with value: \\`${safeStableStringify(version, { keepUndefined: true })}\\`).`\n );\n }\n\n if (version !== \"v4\" && version !== \"v7\") {\n throw new RangeError(\n `Unsupported UUID version. Allowed values are \"v4\" or \"v7\". (received: \\`${safeStableStringify(\n version,\n {\n keepUndefined: true\n }\n )}\\`).`\n );\n }\n\n // Validate monotonic type\n if (!isBoolean(monotonic)) {\n throw new TypeError(\n `Parameter \\`monotonic\\` property of the \\`options\\` (first parameter) must be a \\`boolean\\` when provided, but received type: \\`${getPreciseType(\n monotonic\n )}\\` - (with value: \\`${safeStableStringify(monotonic, {\n keepUndefined: true\n })}\\`).`\n );\n }\n\n // monotonic only allowed with v7\n if (monotonic && version !== \"v7\") {\n throw new TypeError(\n `Parameter \\`monotonic\\` property of the \\`options\\` (first parameter) is only supported for version \"v7\". Received: version=${safeStableStringify(\n version,\n { keepUndefined: true }\n )}.`\n );\n }\n\n if (version === \"v4\") {\n return generateUUIDv4();\n }\n\n // version === \"v7\"\n return generateUUIDv7({ monotonic });\n}\n\n//todo: Helpers & Implementations\n\nfunction hasCryptoGetRandomValues(): boolean {\n return (\n typeof crypto !== \"undefined\" &&\n typeof crypto.getRandomValues === \"function\"\n );\n}\n\nfunction hasCryptoRandomUUID(): boolean {\n return (\n typeof crypto !== \"undefined\" && typeof crypto.randomUUID === \"function\"\n );\n}\n\nfunction getRandomBytes(len: number): Uint8Array {\n if (hasCryptoGetRandomValues()) {\n return crypto.getRandomValues(new Uint8Array(len));\n }\n // Fallback: not cryptographically secure, but avoids crash\n const arr = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n arr[i] = Math.floor(Math.random() * 256);\n }\n return arr;\n}\n\nconst byteToHex: string[] = (() => {\n const arr: string[] = [];\n for (let i = 0; i < 256; ++i) {\n arr.push((i + 0x100).toString(16).substring(1));\n }\n return arr;\n})();\n\nfunction generateUUIDv4(): string {\n // Prefer native if available\n if (hasCryptoRandomUUID()) {\n return crypto.randomUUID();\n }\n\n // If crypto.getRandomValues available, use it for 16 bytes\n if (hasCryptoGetRandomValues()) {\n const rnd = crypto.getRandomValues(new Uint8Array(16));\n\n if (\n !rnd[0] ||\n !rnd[1] ||\n !rnd[2] ||\n !rnd[3] ||\n !rnd[4] ||\n !rnd[5] ||\n !rnd[6] ||\n !rnd[7] ||\n !rnd[8] ||\n !rnd[9] ||\n !rnd[10] ||\n !rnd[11] ||\n !rnd[12] ||\n !rnd[13] ||\n !rnd[14] ||\n !rnd[15]\n ) {\n return \"\";\n }\n\n const byteToHex0 = byteToHex[rnd[0]];\n const byteToHex1 = byteToHex[rnd[1]];\n\n if (!byteToHex0 || !byteToHex1) return \"\";\n\n // Per RFC 4122: set version and variant\n rnd[6] = (rnd[6]! & 0x0f) | 0x40; // version 4\n rnd[8] = (rnd[8]! & 0x3f) | 0x80; // variant 10xx\n\n return (\n byteToHex0 +\n byteToHex1 +\n byteToHex[rnd[2]] +\n byteToHex[rnd[3]] +\n \"-\" +\n byteToHex[rnd[4]] +\n byteToHex[rnd[5]] +\n \"-\" +\n byteToHex[rnd[6]] +\n byteToHex[rnd[7]] +\n \"-\" +\n byteToHex[rnd[8]] +\n byteToHex[rnd[9]] +\n \"-\" +\n byteToHex[rnd[10]] +\n byteToHex[rnd[11]] +\n byteToHex[rnd[12]] +\n byteToHex[rnd[13]] +\n byteToHex[rnd[14]] +\n byteToHex[rnd[15]]\n );\n }\n\n // Last-resort fallback using Math.random (not crypto-secure)\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === \"x\" ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n\n/* ---------------------------\n Monotonic state (singleton per-process)\n --------------------------- */\n\n/**\n * Internal monotonic state:\n * - lastTimestampMs: last generated timestamp (ms)\n * - lastRand: last random 10-byte block used for v7 (used to increment on same ms)\n */\nconst monotonicState: {\n lastTimestampMs: number;\n lastRand: Uint8Array | null;\n} = {\n lastTimestampMs: -1,\n lastRand: null\n};\n\nfunction incrementUint8ArrayBigEndian(arr: Uint8Array): boolean {\n // Increment arr in big-endian order. Return true if overflowed back to zero.\n for (let i = arr.length - 1; i >= 0; i--) {\n if (arr[i] === 0xff) {\n arr[i] = 0x00;\n continue;\n }\n\n arr[i] = (arr[i]! + 1) & 0xff;\n\n return false; // no overflow\n }\n // overflowed (wrapped to zero)\n return true;\n}\n\nfunction generateUUIDv7({\n monotonic = false\n}: { monotonic?: boolean } = {}): string {\n const nowMs = Date.now();\n const tsHex = BigInt(nowMs).toString(16).padStart(12, \"0\"); // 48 bits ➔ 12 hex chars\n\n // We'll use 10 random bytes (80 bits)\n let rand = getRandomBytes(10);\n\n if (monotonic) {\n // ensure monotonicState is consistent per-process\n if (monotonicState.lastTimestampMs === nowMs && monotonicState.lastRand) {\n // We are in the same ms bucket — increment lastRand (big-endian)\n const copy = new Uint8Array(monotonicState.lastRand); // copy for use\n const overflow = incrementUint8ArrayBigEndian(copy);\n if (overflow) {\n // Practically impossible (2^80 increments in 1ms). Throw to be safe.\n throw new RangeError(\n \"Monotonic UUID sequence overflow: too many UUIDs generated within the same millisecond.\"\n );\n }\n // use incremented copy as rand\n rand = copy;\n // update state\n monotonicState.lastRand = copy;\n } else {\n // New ms: generate fresh randomness and store\n const fresh = getRandomBytes(10);\n monotonicState.lastRand = new Uint8Array(fresh);\n monotonicState.lastTimestampMs = nowMs;\n rand = fresh;\n }\n }\n\n // if (!rand[0] || !rand[2]) return \"\";\n // If not monotonic, rand remains randomly generated above.\n\n // Now set version & variant bits into proper positions.\n // For v7 layout we used: timestamp (48 bits) + rand[0..9] (80 bits)\n // We must set version nibble into high nibble of rand[0] (time_hi_and_version)\n // and set variant bits into rand[2]'s high bits (clock_seq_hi_and_reserved)\n rand[0] = rand[0] ? (rand[0] & 0x0f) | 0x70 : 0; // version 7 (0x7 << 4)\n rand[2] = rand[2] ? (rand[2] & 0x3f) | 0x80 : 0; // variant 10xx\n\n const randHex = Array.from(rand, (b) => byteToHex[b]).join(\"\");\n\n // Assemble UUID groups:\n // - 8 hex (timestamp[0..7])\n // - 4 hex (timestamp[8..11])\n // - 4 hex (rand[0..1]) ➔ contains version in high nibble of rand[0]\n // - 4 hex (rand[2..3]) ➔ contains variant in high bits of rand[2]\n // - 12 hex (rand[4..9])\n const part1 = tsHex.slice(0, 8);\n const part2 = tsHex.slice(8, 12);\n const part3 = randHex.slice(0, 4);\n const part4 = randHex.slice(4, 8);\n const part5 = randHex.slice(8, 20);\n\n return [part1, part2, part3, part4, part5].join(\"-\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAsEA,SAAgB,cAAc,OAAyB;CACrD,IAAI,CAAC,gBAAgB,MAAM,EAAE,OAAO;CAGpC,OAAO,MADa,KAAK,MAAM,KAAK,QAAQ,IAAI,MAAM,UAAU,GACxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC9C1B,MAAa,aAAa,KAAa,QAAwB;CAC7D,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,IAAI,EACpC,MAAM,IAAI,UACR,8FAA8F,aAC5F,KACA,IACD,CAAC,iCAAiC,eACjC,IACD,CAAC,sBAAsB,oBAAoB,KAAK,EAC/C,eAAe,MAChB,CAAC,CAAC,gBAAgB,eAAe,IAAI,CAAC,sBAAsB,oBAC3D,KACA,EACE,eAAe,MAChB,CACF,CAAC,OACH;CAEH,IAAI,MAAM,KACR,MAAM,IAAI,WACR,6GAA6G,YAC3G,IACD,CAAC,oBAAoB,oBAAoB,KAAK,EAC7C,eAAe,MAChB,CAAC,CAAC,cAAc,YAAY,IAAI,CAAC,oBAAoB,oBACpD,KACA,EACE,eAAe,MAChB,CACF,CAAC,OACH;CAIH,MAAM,KAAK,IAAI,GAAG,IAAI;CAGtB,MAAM,KAAK,IAAI,OAAO,kBAAkB,IAAI;CAE5C,OAAO,KAAK,MAAM,KAAK,QAAQ,IAAI,MAAM,MAAM,GAAG,GAAG;;AAGvD,MAAM,eAAe,UAA2B;CAC9C,OAAO,SAAS,OAAO,EAAE,YAAY,MAAM,CAAC,GACxC,UAAU,OAAO,YACf,uBACA,GAAG,UACL,KAAK,eAAe,MAAM,CAAC;;AAGjC,MAAM,gBAAgB,GAAG,WAAsB;CAC7C,OAAO,OAAO,MACX,MAAM,SAAS,GAAG,EAAE,YAAY,MA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