@rzl-zone/utils-js 3.7.1 → 3.9.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 (124) hide show
  1. package/README.md +28 -1
  2. package/dist/assertions/index.cjs +11 -11
  3. package/dist/assertions/index.d.ts +169 -58
  4. package/dist/assertions/index.js +5 -5
  5. package/dist/{chunk-EK7FSI7F.cjs → chunk-2XGQQZ6A.cjs} +3 -3
  6. package/dist/{chunk-YS27V6LS.js → chunk-3LE6NX57.js} +5 -176
  7. package/dist/{chunk-PZQC3FZY.js → chunk-44X74C26.js} +4 -4
  8. package/dist/{chunk-4ACKNPL5.js → chunk-5KDVIEVO.js} +2 -2
  9. package/dist/{chunk-JY4HLZ4W.js → chunk-5O66AUEC.js} +2 -2
  10. package/dist/chunk-5Y6JL47L.js +302 -0
  11. package/dist/{chunk-KIYALQQF.cjs → chunk-62FS7WMB.cjs} +35 -35
  12. package/dist/{chunk-VJVCXEH7.cjs → chunk-6AMDHVS2.cjs} +9 -181
  13. package/dist/{chunk-6PKW4WCT.js → chunk-6WVOUVWD.js} +27 -15
  14. package/dist/{chunk-BYUT376O.cjs → chunk-76ATVDCR.cjs} +3 -3
  15. package/dist/{chunk-F3WBQKRI.cjs → chunk-7C7TQC5J.cjs} +29 -7
  16. package/dist/{chunk-QUITZ3GP.js → chunk-7EIFPHV3.js} +32 -16
  17. package/dist/{chunk-6RFNZ2ZZ.cjs → chunk-7NXFGJJE.cjs} +14 -14
  18. package/dist/{chunk-TFDXRT6D.cjs → chunk-ALRISPTL.cjs} +3 -3
  19. package/dist/chunk-BAV5T2E3.cjs +1 -1
  20. package/dist/{chunk-4ZOXSUXB.js → chunk-C7GC2PFX.js} +3 -3
  21. package/dist/chunk-DVMHRLKP.cjs +1 -1
  22. package/dist/{chunk-XFTUHS4Y.js → chunk-DXPM4NOU.js} +10 -8
  23. package/dist/{chunk-DPLL67OT.js → chunk-EJV5AF4L.js} +2 -2
  24. package/dist/{chunk-NREACG6M.cjs → chunk-FWWPEL7J.cjs} +3 -3
  25. package/dist/{chunk-LEX4TQW2.js → chunk-GHU356XQ.js} +4 -6
  26. package/dist/chunk-GKDSBOYE.js +209 -0
  27. package/dist/{chunk-YC7AK3KX.cjs → chunk-H44QVAZL.cjs} +31 -31
  28. package/dist/{chunk-AKKM6MOX.cjs → chunk-I33PB44Q.cjs} +15 -15
  29. package/dist/{chunk-LIU4S3JA.cjs → chunk-IX6PF5ZP.cjs} +4 -4
  30. package/dist/{chunk-3KTD3QDI.js → chunk-J4TT33ZX.js} +29 -7
  31. package/dist/{chunk-SZJ7OI4S.js → chunk-J6VLFVIL.js} +3 -3
  32. package/dist/{chunk-KTQLDIIT.cjs → chunk-JI57K7D4.cjs} +173 -163
  33. package/dist/{chunk-OFBFGFVH.js → chunk-JYOCB6OV.js} +2 -2
  34. package/dist/chunk-KHO2SBNA.cjs +1 -1
  35. package/dist/{chunk-66WLOZOD.cjs → chunk-KUVRZ2JW.cjs} +53 -51
  36. package/dist/chunk-L5RDAVVH.js +1 -1
  37. package/dist/{chunk-VCVND6CH.js → chunk-M5QB2GM5.js} +2 -2
  38. package/dist/{chunk-3LEWQV3R.js → chunk-MBFVTGYS.js} +8 -8
  39. package/dist/{chunk-UKAUXY2U.cjs → chunk-MMRHKYT6.cjs} +12 -12
  40. package/dist/{chunk-U5VR4TJN.js → chunk-MS2KSKD7.js} +9 -9
  41. package/dist/{chunk-7ZNEUWYP.js → chunk-MZ3T6L7Z.js} +2 -2
  42. package/dist/{chunk-ATLFMKAF.cjs → chunk-NAOVH4OH.cjs} +7 -7
  43. package/dist/chunk-NJ24M6ZH.cjs +308 -0
  44. package/dist/chunk-OCTHWEZK.cjs +249 -0
  45. package/dist/chunk-ONZFBJVW.js +1 -1
  46. package/dist/{chunk-FI76UZRF.js → chunk-OSSFLQDD.js} +3 -4
  47. package/dist/{chunk-7WBMA2VE.cjs → chunk-OYFUBKEG.cjs} +4 -5
  48. package/dist/{chunk-B4SDEBN7.cjs → chunk-PWKOFPAH.cjs} +3 -3
  49. package/dist/{chunk-2CQI36UD.cjs → chunk-QGTFQ7RO.cjs} +8 -6
  50. package/dist/chunk-QNKGP5DY.js +1 -1
  51. package/dist/chunk-QXTJVDWE.js +676 -0
  52. package/dist/{chunk-B6UIKBHR.cjs → chunk-QZI5PVCI.cjs} +4 -4
  53. package/dist/{chunk-WNO3EPYT.js → chunk-R2DR7SPJ.js} +102 -26
  54. package/dist/{chunk-TDYGYHSH.js → chunk-SN5HAK3Y.js} +4 -4
  55. package/dist/{chunk-D53CE4BT.js → chunk-SRWL4YCP.js} +11 -8
  56. package/dist/{chunk-7QQV66RX.cjs → chunk-TJ5OY6MC.cjs} +10 -10
  57. package/dist/{chunk-6WMB5AJR.js → chunk-TXOVQZPU.js} +3 -4
  58. package/dist/chunk-UDA26MCU.cjs +1 -1
  59. package/dist/{chunk-R3PBF6F7.cjs → chunk-UFYMRRJH.cjs} +73 -61
  60. package/dist/{chunk-5NN4ZDE2.cjs → chunk-UV5BKAYW.cjs} +6 -8
  61. package/dist/{chunk-GAJBF6DR.js → chunk-UXT4XSUK.js} +2 -2
  62. package/dist/{chunk-TDPYR5JY.js → chunk-VBSLIIDB.js} +24 -14
  63. package/dist/chunk-VCYXNIZ2.cjs +678 -0
  64. package/dist/chunk-VJDDGRIK.cjs +1 -1
  65. package/dist/{chunk-VNADVWSJ.js → chunk-WB3FT62A.js} +6 -4
  66. package/dist/{chunk-K63WO3XA.cjs → chunk-WKM6UVMG.cjs} +4 -5
  67. package/dist/{chunk-OS5OT5JA.cjs → chunk-WLEZ2KSG.cjs} +142 -126
  68. package/dist/{chunk-ZN53RM3R.js → chunk-WRGN6UBK.js} +2 -2
  69. package/dist/chunk-WVSPXFTY.js +1 -1
  70. package/dist/{chunk-2VO2CBTU.js → chunk-X6ULJZ3X.js} +2 -2
  71. package/dist/{chunk-CKUEZF4R.cjs → chunk-XYWC4EQ3.cjs} +71 -71
  72. package/dist/{chunk-A3YI6Y2P.js → chunk-YHFRCVTN.js} +3 -3
  73. package/dist/{chunk-RMJC3B5P.cjs → chunk-YQHJB7KR.cjs} +30 -27
  74. package/dist/{chunk-YGB2BQPB.cjs → chunk-YVRUY4EW.cjs} +8 -8
  75. package/dist/chunk-YWHHVDT4.js +1 -1
  76. package/dist/chunk-ZTHJQJ5F.cjs +211 -0
  77. package/dist/conversions/index.cjs +34 -34
  78. package/dist/conversions/index.d.ts +10 -12
  79. package/dist/conversions/index.js +15 -15
  80. package/dist/events/index.cjs +8 -8
  81. package/dist/events/index.d.ts +9 -9
  82. package/dist/events/index.js +4 -4
  83. package/dist/formatters/index.cjs +19 -19
  84. package/dist/formatters/index.d.ts +19 -24
  85. package/dist/formatters/index.js +9 -9
  86. package/dist/generators/index.cjs +12 -8
  87. package/dist/generators/index.d.ts +155 -26
  88. package/dist/generators/index.js +4 -4
  89. package/dist/index.d.ts +1 -1
  90. package/dist/{isPlainObject-FWmcJF6k.d.ts → isPlainObject-BTPjv6zB.d.ts} +2 -2
  91. package/dist/next/index.cjs +39 -36
  92. package/dist/next/index.d.ts +11 -11
  93. package/dist/next/index.js +12 -9
  94. package/dist/next/server/index.cjs +4 -4
  95. package/dist/next/server/index.d.ts +4 -4
  96. package/dist/next/server/index.js +2 -2
  97. package/dist/operations/index.cjs +11 -11
  98. package/dist/operations/index.d.ts +8 -9
  99. package/dist/operations/index.js +8 -8
  100. package/dist/parsers/index.cjs +6 -4
  101. package/dist/parsers/index.d.ts +224 -32
  102. package/dist/parsers/index.js +5 -3
  103. package/dist/predicates/index.cjs +77 -76
  104. package/dist/predicates/index.d.ts +15 -28
  105. package/dist/predicates/index.js +14 -13
  106. package/dist/promises/index.cjs +6 -6
  107. package/dist/promises/index.d.ts +5 -7
  108. package/dist/promises/index.js +4 -4
  109. package/dist/rzl-utils.global.js +2 -2
  110. package/dist/strings/index.cjs +23 -23
  111. package/dist/strings/index.d.ts +1 -1
  112. package/dist/strings/index.js +7 -7
  113. package/dist/tailwind/index.cjs +13 -13
  114. package/dist/tailwind/index.d.ts +18 -18
  115. package/dist/tailwind/index.js +5 -5
  116. package/dist/urls/index.cjs +23 -21
  117. package/dist/urls/index.d.ts +188 -121
  118. package/dist/urls/index.js +16 -14
  119. package/package.json +1 -1
  120. package/dist/chunk-ABA2ZSBQ.js +0 -152
  121. package/dist/chunk-BG3AS5BU.cjs +0 -173
  122. package/dist/chunk-K3SONK25.cjs +0 -157
  123. package/dist/chunk-KPCDDYTZ.js +0 -417
  124. package/dist/chunk-QAPYHLHC.cjs +0 -419
@@ -0,0 +1,308 @@
1
+ /*!
2
+ * ====================================================
3
+ * Rzl Utils-JS.
4
+ * ----------------------------------------------------
5
+ * Version: 3.9.0.
6
+ * Author: Rizalvin Dwiky.
7
+ * Repository: https://github.com/rzl-zone/utils-js.
8
+ * ====================================================
9
+ */
10
+ 'use strict';
11
+
12
+ var chunkDVMHRLKP_cjs = require('./chunk-DVMHRLKP.cjs');
13
+ var chunkH44QVAZL_cjs = require('./chunk-H44QVAZL.cjs');
14
+ var chunk7C7TQC5J_cjs = require('./chunk-7C7TQC5J.cjs');
15
+
16
+ function getRandomItem(array) {
17
+ if (!chunk7C7TQC5J_cjs.isNonEmptyArray(array)) return void 0;
18
+ const randomIndex = Math.floor(Math.random() * (array.length || 0));
19
+ return array[randomIndex];
20
+ }
21
+
22
+ var randomInt = (min, max) => {
23
+ if (!chunkDVMHRLKP_cjs.isInteger(min) || !chunkDVMHRLKP_cjs.isInteger(max)) {
24
+ throw new TypeError(
25
+ `First parameter (\`min\`) and second parameter (\`max\`) must be of type \`integer-number\`${minValueNote(
26
+ min,
27
+ max
28
+ )}value, but received: ['min': \`${chunk7C7TQC5J_cjs.getPreciseType(
29
+ min
30
+ )}\` - (with value: \`${chunkH44QVAZL_cjs.safeStableStringify(min, {
31
+ keepUndefined: true
32
+ })})\`, 'max': \`${chunk7C7TQC5J_cjs.getPreciseType(max)}\` - (with value: \`${chunkH44QVAZL_cjs.safeStableStringify(
33
+ max,
34
+ {
35
+ keepUndefined: true
36
+ }
37
+ )}\`)].`
38
+ );
39
+ }
40
+ if (min > max) {
41
+ throw new RangeError(
42
+ `First parameter (\`min\`) must be less than or equal to second parameter (\`max\`), but received: ['min': ${formatValue(
43
+ min
44
+ )} - (with value: \`${chunkH44QVAZL_cjs.safeStableStringify(min, {
45
+ keepUndefined: true
46
+ })})\`, 'max': ${formatValue(max)} - (with value: \`${chunkH44QVAZL_cjs.safeStableStringify(max, {
47
+ keepUndefined: true
48
+ })})\`].`
49
+ );
50
+ }
51
+ min = Math.max(1, min);
52
+ max = Math.min(Number.MAX_SAFE_INTEGER, max);
53
+ return Math.floor(Math.random() * (max - min + 1)) + min;
54
+ };
55
+ var formatValue = (value) => {
56
+ return chunk7C7TQC5J_cjs.isNumber(value, { includeNaN: true }) ? value === Number.MIN_VALUE ? "`Number.MIN_VALUE`" : `${value}` : `\`${chunk7C7TQC5J_cjs.getPreciseType(value)}\``;
57
+ };
58
+ var minValueNote = (...values) => {
59
+ return values.some((v) => chunk7C7TQC5J_cjs.isNumber(v, { includeNaN: true }) && v === Number.MIN_VALUE) ? " and can't be `Number.MIN_VALUE` " : " ";
60
+ };
61
+
62
+ var randomIntByLength = (options) => {
63
+ if (!chunk7C7TQC5J_cjs.isPlainObject(options)) {
64
+ options = {};
65
+ }
66
+ const { minLength = 1, maxLength = 16, avoidZero = false } = options;
67
+ chunk7C7TQC5J_cjs.assertIsBoolean(avoidZero, {
68
+ message({ currentType, validType }) {
69
+ return `Parameters \`avoidZero\` must be of type \`${validType}\`, but received: \`${currentType}\`.`;
70
+ }
71
+ });
72
+ if (!chunkDVMHRLKP_cjs.isInteger(minLength) || !chunkDVMHRLKP_cjs.isInteger(maxLength)) {
73
+ throw new TypeError(
74
+ `Parameters \`minLength\` and \`maxLength\` must be of type \`integer-number\`, but received: ['minLength': \`${chunk7C7TQC5J_cjs.getPreciseType(
75
+ minLength
76
+ )}\` - (with value: ${chunkH44QVAZL_cjs.safeStableStringify(minLength, {
77
+ keepUndefined: true
78
+ })}), 'maxLength': \`${chunk7C7TQC5J_cjs.getPreciseType(
79
+ maxLength
80
+ )}\` - (with value: ${chunkH44QVAZL_cjs.safeStableStringify(maxLength, {
81
+ keepUndefined: true
82
+ })})].`
83
+ );
84
+ }
85
+ if (minLength < 1 || maxLength > 16 || minLength > maxLength) {
86
+ throw new RangeError(
87
+ `Invalid range at parameters \`minLength\` must be \u2265 1, \`maxLength\` must be \u2264 16, and \`minLength\` \u2264 \`maxLength\`, but received: ['minLength': \`${minLength}\`, 'maxLength': \`${maxLength}\`].`
88
+ );
89
+ }
90
+ const randomLength = minLength === maxLength ? minLength : randomInt(minLength, maxLength);
91
+ const minValue = 10 ** (randomLength - 1);
92
+ const maxValue = 10 ** randomLength - 1;
93
+ let result = randomInt(minValue, maxValue);
94
+ if (avoidZero && result === 0) {
95
+ result = minValue;
96
+ }
97
+ return result;
98
+ };
99
+
100
+ var randomStr = (options) => {
101
+ if (!chunk7C7TQC5J_cjs.isPlainObject(options)) {
102
+ options = {};
103
+ }
104
+ const {
105
+ minLength = 40,
106
+ maxLength = 40,
107
+ type = "string",
108
+ avoidWhiteSpace = true
109
+ } = options;
110
+ chunk7C7TQC5J_cjs.assertIsBoolean(avoidWhiteSpace, {
111
+ message({ currentType, validType }) {
112
+ return `Parameters \`avoidWhiteSpace\` property of the \`options\` (first-parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`;
113
+ }
114
+ });
115
+ if (!chunkDVMHRLKP_cjs.isInteger(minLength) || !chunkDVMHRLKP_cjs.isInteger(maxLength)) {
116
+ throw new TypeError(
117
+ `Parameters \`minLength\` and \`maxLength\` must be of type \`integer-number\`, but received: ['minLength': \`${chunk7C7TQC5J_cjs.getPreciseType(
118
+ minLength
119
+ )}\` - (with value: ${chunkH44QVAZL_cjs.safeStableStringify(minLength, {
120
+ keepUndefined: true
121
+ })}), 'maxLength': \`${chunk7C7TQC5J_cjs.getPreciseType(
122
+ maxLength
123
+ )}\` - (with value: ${chunkH44QVAZL_cjs.safeStableStringify(maxLength, {
124
+ keepUndefined: true
125
+ })})].`
126
+ );
127
+ }
128
+ if (minLength < 1 || maxLength > 5e3 || minLength > maxLength) {
129
+ throw new RangeError(
130
+ `Invalid range at parameters \`minLength\` must be \u2265 1, \`maxLength\` must be \u2264 5000, and \`minLength\` \u2264 \`maxLength\`, but received: ['minLength': \`${minLength}\`, 'maxLength': \`${maxLength}\`].`
131
+ );
132
+ }
133
+ if (type !== "string" && type !== "number") {
134
+ throw new TypeError(
135
+ `Parameter \`type\` must be of type \`string\` with value one of "string" | "number", but received: \`${chunk7C7TQC5J_cjs.getPreciseType(
136
+ type
137
+ )}\`, with value: ${chunkH44QVAZL_cjs.safeStableStringify(type, {
138
+ keepUndefined: true
139
+ })}.`
140
+ );
141
+ }
142
+ const length = randomInt(minLength, maxLength);
143
+ const cleanCharacters = (charSet) => {
144
+ return avoidWhiteSpace ? charSet.replace(/\s|\n|\t/g, "") : charSet;
145
+ };
146
+ const defaultNumberSet = "0123456789";
147
+ const defaultStringSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
148
+ const baseCharSet = type === "number" ? (!chunk7C7TQC5J_cjs.isNaN(Number(options.replaceGenInt)) ? options.replaceGenInt : void 0) ?? defaultNumberSet : (options.replaceGenStr ? options.replaceGenStr : void 0) ?? defaultStringSet;
149
+ const characterSet = cleanCharacters(baseCharSet) + (options.addChar || "");
150
+ if (!characterSet.length) {
151
+ const errCharSet = () => {
152
+ if (type === "number") {
153
+ if (avoidWhiteSpace) {
154
+ return `If \`avoidWhiteSpace\` is true, and \`replaceGenInt\` cant be empty-string value, ensure \`replaceGenInt\` has valid characters and non-nan string number.`;
155
+ }
156
+ return `Ensure \`replaceGenInt\` has valid characters and not a NaN number string while convert to number.`;
157
+ }
158
+ return `Ensure \`replaceGenStr\` has valid characters and non empty string.`;
159
+ };
160
+ throw new Error(`Character set is empty. ${errCharSet()}`);
161
+ }
162
+ let result = "";
163
+ for (let i = 0; i < length; i++) {
164
+ result += characterSet.charAt(Math.floor(Math.random() * characterSet.length));
165
+ }
166
+ return result;
167
+ };
168
+
169
+ function randomUUID(options = {}) {
170
+ if (!chunk7C7TQC5J_cjs.isPlainObject(options)) {
171
+ throw new TypeError(
172
+ `First parameter (\`options\`) must be a plain object with optional properties \`version\` and \`monotonic\`, but received: \`${chunk7C7TQC5J_cjs.getPreciseType(
173
+ options
174
+ )}\` - (with value: \`${chunkH44QVAZL_cjs.safeStableStringify(options, { keepUndefined: true })}\`).`
175
+ );
176
+ }
177
+ const { version = "v4", monotonic = false } = options;
178
+ if (!chunk7C7TQC5J_cjs.isNonEmptyString(version)) {
179
+ throw new TypeError(
180
+ `Parameter \`version\` property of the \`options\` (first parameter) must be a \`string\` of either "v4" or "v7", but received type: \`${chunk7C7TQC5J_cjs.getPreciseType(
181
+ version
182
+ )}\` - (with value: \`${chunkH44QVAZL_cjs.safeStableStringify(version, { keepUndefined: true })}\`).`
183
+ );
184
+ }
185
+ if (version !== "v4" && version !== "v7") {
186
+ throw new RangeError(
187
+ `Unsupported UUID version. Allowed values are "v4" or "v7". (received: \`${chunkH44QVAZL_cjs.safeStableStringify(
188
+ version,
189
+ {
190
+ keepUndefined: true
191
+ }
192
+ )}\`).`
193
+ );
194
+ }
195
+ if (!chunk7C7TQC5J_cjs.isBoolean(monotonic)) {
196
+ throw new TypeError(
197
+ `Parameter \`monotonic\` property of the \`options\` (first parameter) must be a \`boolean\` when provided, but received type: \`${chunk7C7TQC5J_cjs.getPreciseType(
198
+ monotonic
199
+ )}\` - (with value: \`${chunkH44QVAZL_cjs.safeStableStringify(monotonic, {
200
+ keepUndefined: true
201
+ })}\`).`
202
+ );
203
+ }
204
+ if (monotonic && version !== "v7") {
205
+ throw new TypeError(
206
+ `Parameter \`monotonic\` property of the \`options\` (first parameter) is only supported for version "v7". Received: version=${chunkH44QVAZL_cjs.safeStableStringify(
207
+ version,
208
+ { keepUndefined: true }
209
+ )}.`
210
+ );
211
+ }
212
+ if (version === "v4") {
213
+ return generateUUIDv4();
214
+ }
215
+ return generateUUIDv7({ monotonic });
216
+ }
217
+ function hasCryptoGetRandomValues() {
218
+ return typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function";
219
+ }
220
+ function hasCryptoRandomUUID() {
221
+ return typeof crypto !== "undefined" && typeof crypto.randomUUID === "function";
222
+ }
223
+ function getRandomBytes(len) {
224
+ if (hasCryptoGetRandomValues()) {
225
+ return crypto.getRandomValues(new Uint8Array(len));
226
+ }
227
+ const arr = new Uint8Array(len);
228
+ for (let i = 0; i < len; i++) {
229
+ arr[i] = Math.floor(Math.random() * 256);
230
+ }
231
+ return arr;
232
+ }
233
+ var byteToHex = (() => {
234
+ const arr = [];
235
+ for (let i = 0; i < 256; ++i) {
236
+ arr.push((i + 256).toString(16).substring(1));
237
+ }
238
+ return arr;
239
+ })();
240
+ function generateUUIDv4() {
241
+ if (hasCryptoRandomUUID()) {
242
+ return crypto.randomUUID();
243
+ }
244
+ if (hasCryptoGetRandomValues()) {
245
+ const rnd = crypto.getRandomValues(new Uint8Array(16));
246
+ rnd[6] = rnd[6] & 15 | 64;
247
+ rnd[8] = rnd[8] & 63 | 128;
248
+ return byteToHex[rnd[0]] + byteToHex[rnd[1]] + 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]];
249
+ }
250
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
251
+ const r = Math.random() * 16 | 0;
252
+ const v = c === "x" ? r : r & 3 | 8;
253
+ return v.toString(16);
254
+ });
255
+ }
256
+ var monotonicState = {
257
+ lastTimestampMs: -1,
258
+ lastRand: null
259
+ };
260
+ function incrementUint8ArrayBigEndian(arr) {
261
+ for (let i = arr.length - 1; i >= 0; i--) {
262
+ if (arr[i] === 255) {
263
+ arr[i] = 0;
264
+ continue;
265
+ }
266
+ arr[i] = arr[i] + 1 & 255;
267
+ return false;
268
+ }
269
+ return true;
270
+ }
271
+ function generateUUIDv7({ monotonic = false } = {}) {
272
+ const nowMs = Date.now();
273
+ const tsHex = BigInt(nowMs).toString(16).padStart(12, "0");
274
+ let rand = getRandomBytes(10);
275
+ if (monotonic) {
276
+ if (monotonicState.lastTimestampMs === nowMs && monotonicState.lastRand) {
277
+ const copy = new Uint8Array(monotonicState.lastRand);
278
+ const overflow = incrementUint8ArrayBigEndian(copy);
279
+ if (overflow) {
280
+ throw new RangeError(
281
+ "Monotonic UUID sequence overflow: too many UUIDs generated within the same millisecond."
282
+ );
283
+ }
284
+ rand = copy;
285
+ monotonicState.lastRand = copy;
286
+ } else {
287
+ const fresh = getRandomBytes(10);
288
+ monotonicState.lastRand = new Uint8Array(fresh);
289
+ monotonicState.lastTimestampMs = nowMs;
290
+ rand = fresh;
291
+ }
292
+ }
293
+ rand[0] = rand[0] & 15 | 112;
294
+ rand[2] = rand[2] & 63 | 128;
295
+ const randHex = Array.from(rand, (b) => byteToHex[b]).join("");
296
+ const part1 = tsHex.slice(0, 8);
297
+ const part2 = tsHex.slice(8, 12);
298
+ const part3 = randHex.slice(0, 4);
299
+ const part4 = randHex.slice(4, 8);
300
+ const part5 = randHex.slice(8, 20);
301
+ return [part1, part2, part3, part4, part5].join("-");
302
+ }
303
+
304
+ exports.getRandomItem = getRandomItem;
305
+ exports.randomInt = randomInt;
306
+ exports.randomIntByLength = randomIntByLength;
307
+ exports.randomStr = randomStr;
308
+ exports.randomUUID = randomUUID;
@@ -0,0 +1,249 @@
1
+ /*!
2
+ * ====================================================
3
+ * Rzl Utils-JS.
4
+ * ----------------------------------------------------
5
+ * Version: 3.9.0.
6
+ * Author: Rizalvin Dwiky.
7
+ * Repository: https://github.com/rzl-zone/utils-js.
8
+ * ====================================================
9
+ */
10
+ 'use strict';
11
+
12
+ var chunk6AMDHVS2_cjs = require('./chunk-6AMDHVS2.cjs');
13
+ var chunkIX6PF5ZP_cjs = require('./chunk-IX6PF5ZP.cjs');
14
+ var chunkFWWPEL7J_cjs = require('./chunk-FWWPEL7J.cjs');
15
+ var chunkH44QVAZL_cjs = require('./chunk-H44QVAZL.cjs');
16
+ var chunk7C7TQC5J_cjs = require('./chunk-7C7TQC5J.cjs');
17
+
18
+ var NormalizePathnameError = class _NormalizePathnameError extends Error {
19
+ /** * ***The original error that triggered this normalization failure.***
20
+ *
21
+ * **Always available for backward compatibility.**
22
+ */
23
+ originalError;
24
+ constructor(message, originalError) {
25
+ super(message, chunk7C7TQC5J_cjs.isFunction(Error) ? { cause: originalError } : void 0);
26
+ this.name = "NormalizePathnameError";
27
+ this.originalError = originalError;
28
+ if (chunk7C7TQC5J_cjs.isFunction(Error.captureStackTrace)) {
29
+ Error.captureStackTrace(this, _NormalizePathnameError);
30
+ } else {
31
+ this.stack = new Error(message).stack;
32
+ }
33
+ }
34
+ /** * ***Safe JSON representation for logging or IPC.*** */
35
+ toJSON() {
36
+ return {
37
+ name: this.name,
38
+ message: this.message,
39
+ stack: this.stack,
40
+ originalError: {
41
+ name: this.originalError.name,
42
+ message: this.originalError.message,
43
+ stack: this.originalError.stack
44
+ }
45
+ };
46
+ }
47
+ };
48
+
49
+ function normalizePathname(pathname, options = {
50
+ defaultPath: "/",
51
+ keepNullable: false
52
+ }) {
53
+ chunk7C7TQC5J_cjs.assertIsPlainObject(options, {
54
+ message({ currentType, validType }) {
55
+ return `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`;
56
+ }
57
+ });
58
+ const {
59
+ defaultPath = "/",
60
+ keepNullable = false,
61
+ keepTrailingSlash = false,
62
+ localhostDomain = false,
63
+ ignoreDomainExtensions = void 0
64
+ } = options;
65
+ if (!chunk7C7TQC5J_cjs.isNonEmptyString(defaultPath)) {
66
+ throw new TypeError(
67
+ `Parameter \`defaultPath\` property of the \`options\` (second parameter) must be of type \`string\` and not empty-string, but received: \`${chunk7C7TQC5J_cjs.getPreciseType(
68
+ defaultPath
69
+ )}\`, with value: \`${chunkH44QVAZL_cjs.safeStableStringify(defaultPath, {
70
+ keepUndefined: true
71
+ })}\`.`
72
+ );
73
+ }
74
+ chunk7C7TQC5J_cjs.assertIsBoolean(keepNullable, {
75
+ message({ currentType, validType }) {
76
+ return `Parameter \`keepNullable\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`;
77
+ }
78
+ });
79
+ chunk7C7TQC5J_cjs.assertIsBoolean(keepTrailingSlash, {
80
+ message({ currentType, validType }) {
81
+ return `Parameter \`keepTrailingSlash\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`;
82
+ }
83
+ });
84
+ chunk7C7TQC5J_cjs.assertIsBoolean(localhostDomain, {
85
+ message({ currentType, validType }) {
86
+ return `Parameter \`localhostDomain\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`;
87
+ }
88
+ });
89
+ let ignoreDomainExtsSet;
90
+ if (!chunk7C7TQC5J_cjs.isUndefined(ignoreDomainExtensions)) {
91
+ if (!chunk7C7TQC5J_cjs.isSet(ignoreDomainExtensions) && !chunk7C7TQC5J_cjs.isArray(ignoreDomainExtensions)) {
92
+ throw new TypeError(
93
+ `Parameter \`ignoreDomainExtensions\` must be of type a \`Set<string>\` or \`string[]\`, but received: \`${chunk7C7TQC5J_cjs.getPreciseType(
94
+ ignoreDomainExtensions
95
+ )}\`.`
96
+ );
97
+ }
98
+ ignoreDomainExtsSet = chunk7C7TQC5J_cjs.isSet(ignoreDomainExtensions) ? ignoreDomainExtensions : new Set(ignoreDomainExtensions);
99
+ let idx = 0;
100
+ for (const ext of ignoreDomainExtsSet) {
101
+ if (!chunk7C7TQC5J_cjs.isNonEmptyString(ext)) {
102
+ throw new TypeError(
103
+ `Parameter \`ignoreDomainExtensions[${idx}]\` must be a \`string\` and \`non-empty string\`, but received: \`${chunkH44QVAZL_cjs.safeStableStringify(
104
+ ext,
105
+ { keepUndefined: true }
106
+ )}\`.`
107
+ );
108
+ }
109
+ if (!ext.startsWith(".")) {
110
+ throw new TypeError(
111
+ `Parameter \`ignoreDomainExtensions[${idx}]\` must start with a dot (.), but received: ${chunkH44QVAZL_cjs.safeStableStringify(
112
+ ext,
113
+ { keepUndefined: true }
114
+ )}`
115
+ );
116
+ }
117
+ idx++;
118
+ }
119
+ }
120
+ try {
121
+ if (keepNullable && (chunk7C7TQC5J_cjs.isNil(pathname) || !chunk7C7TQC5J_cjs.isString(pathname))) {
122
+ if (chunk7C7TQC5J_cjs.isNull(pathname)) return null;
123
+ return void 0;
124
+ }
125
+ let currentPathName = chunk7C7TQC5J_cjs.isNonEmptyString(pathname) ? pathname : defaultPath;
126
+ currentPathName = chunkIX6PF5ZP_cjs.removeSpaces(currentPathName, { trimOnly: true }).replace(
127
+ /\s+/g,
128
+ ""
129
+ );
130
+ currentPathName = stripLeadingDomain(currentPathName, {
131
+ keepTrailingSlash,
132
+ localhostDomain,
133
+ ignoreDomainExtensions: ignoreDomainExtsSet
134
+ });
135
+ let _pathName = currentPathName;
136
+ let search = "";
137
+ let hash = "";
138
+ const searchIndex = currentPathName.indexOf("?");
139
+ const hashIndex = currentPathName.indexOf("#");
140
+ if (searchIndex !== -1) {
141
+ search = currentPathName.slice(
142
+ searchIndex,
143
+ hashIndex !== -1 ? hashIndex : void 0
144
+ );
145
+ }
146
+ if (hashIndex !== -1) {
147
+ hash = currentPathName.slice(hashIndex);
148
+ }
149
+ const endIndex = Math.min(
150
+ searchIndex !== -1 ? searchIndex : currentPathName.length,
151
+ hashIndex !== -1 ? hashIndex : currentPathName.length
152
+ );
153
+ _pathName = currentPathName.slice(0, endIndex);
154
+ _pathName = "/" + _pathName.replace(/^\/+/, "").replace(/\/{2,}/g, "/");
155
+ if (!keepTrailingSlash && _pathName !== "/") {
156
+ _pathName = _pathName.replace(/\/+$/, "");
157
+ }
158
+ _pathName = decodeUnicodeSequences(_pathName);
159
+ search = decodeUnicodeSequences(search);
160
+ hash = decodeUnicodeSequences(hash);
161
+ return _pathName + search + hash;
162
+ } catch (error) {
163
+ throwError(error);
164
+ }
165
+ }
166
+ var decodeUnicodeSequences = (str) => {
167
+ return str.replace(/(?:%(?:[0-9A-F]{2})){2,}/gi, (match) => {
168
+ try {
169
+ const decoded = decodeURIComponent(match);
170
+ if (/^[\u0000-\u007F]+$/.test(decoded)) return match;
171
+ return decoded;
172
+ } catch {
173
+ return match;
174
+ }
175
+ });
176
+ };
177
+ var stripLeadingDomain = (path, options) => {
178
+ let currentPath = path;
179
+ const { ignoreDomainExtensions, localhostDomain } = options;
180
+ if (/^https?:\/\//i.test(currentPath)) {
181
+ try {
182
+ const url = new URL(currentPath);
183
+ currentPath = url.pathname.replace(/^\/+/, "").replace(/\/{2,}/g, "/") + url.search + url.hash;
184
+ return ensureLeadingSlash(currentPath);
185
+ } catch (error) {
186
+ throwError(error);
187
+ }
188
+ }
189
+ if (currentPath.startsWith("/")) {
190
+ currentPath = currentPath.replace(/\/{2,}/g, "/").slice(1);
191
+ }
192
+ const segments = currentPath.split("/");
193
+ const firstPart = segments[0];
194
+ const domainPart = firstPart.split(":")[0];
195
+ const isDomain = chunk6AMDHVS2_cjs.isValidDomain(domainPart, {
196
+ subdomain: true,
197
+ allowUnicode: true,
198
+ wildcard: true,
199
+ allowLocalhost: localhostDomain,
200
+ allowPort: true,
201
+ allowProtocol: true,
202
+ topLevel: false
203
+ });
204
+ let hasIgnoredExtension = false;
205
+ if (ignoreDomainExtensions) {
206
+ for (const ext of ignoreDomainExtensions) {
207
+ if (firstPart.endsWith(ext)) {
208
+ hasIgnoredExtension = true;
209
+ break;
210
+ }
211
+ }
212
+ }
213
+ if (isDomain && !hasIgnoredExtension) {
214
+ segments.shift();
215
+ }
216
+ return ensureLeadingSlash(segments.join("/"));
217
+ };
218
+ var ensureLeadingSlash = (path) => {
219
+ if (!path.startsWith("/")) path = "/" + path;
220
+ return path;
221
+ };
222
+ var throwError = (error) => {
223
+ const err = chunk7C7TQC5J_cjs.isError(error) ? error : new Error("Unknown error from function `normalizePathname()`.");
224
+ throw new NormalizePathnameError(
225
+ `Failed to normalize pathname in function \`normalizePathname()\`: ${err.message}`,
226
+ err
227
+ );
228
+ };
229
+
230
+ var formatEnvPort = (envVar, options = {}) => {
231
+ if (!chunk7C7TQC5J_cjs.isNonEmptyString(envVar)) return "";
232
+ chunk7C7TQC5J_cjs.assertIsPlainObject(options, {
233
+ message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
234
+ });
235
+ const prefixColon = chunk7C7TQC5J_cjs.hasOwnProp(options, "prefixColon") ? options.prefixColon : false;
236
+ if (!chunk7C7TQC5J_cjs.isBoolean(prefixColon)) {
237
+ throw new TypeError(
238
+ `Parameter \`prefixColon\` property of the \`options\` (second parameter) must be of type \`boolean\`, but received: \`${chunk7C7TQC5J_cjs.getPreciseType(
239
+ prefixColon
240
+ )}\`.`
241
+ );
242
+ }
243
+ const digitsOnly = envVar.replace(/\D+/g, "");
244
+ if (chunkFWWPEL7J_cjs.isEmptyString(digitsOnly)) return "";
245
+ return prefixColon ? `:${digitsOnly}` : digitsOnly;
246
+ };
247
+
248
+ exports.formatEnvPort = formatEnvPort;
249
+ exports.normalizePathname = normalizePathname;
@@ -2,7 +2,7 @@
2
2
  * ====================================================
3
3
  * Rzl Utils-JS.
4
4
  * ----------------------------------------------------
5
- * Version: 3.7.1.
5
+ * Version: 3.9.0.
6
6
  * Author: Rizalvin Dwiky.
7
7
  * Repository: https://github.com/rzl-zone/utils-js.
8
8
  * ====================================================
@@ -2,21 +2,20 @@
2
2
  * ====================================================
3
3
  * Rzl Utils-JS.
4
4
  * ----------------------------------------------------
5
- * Version: 3.7.1.
5
+ * Version: 3.9.0.
6
6
  * Author: Rizalvin Dwiky.
7
7
  * Repository: https://github.com/rzl-zone/utils-js.
8
8
  * ====================================================
9
9
  */
10
- import { isString, resolveErrorMessageAssertions } from './chunk-3KTD3QDI.js';
10
+ import { isString, resolveErrorMessageAssertions } from './chunk-J4TT33ZX.js';
11
11
 
12
12
  var assertIsString = (value, options = {}) => {
13
13
  if (isString(value)) return;
14
- const errorMessage = resolveErrorMessageAssertions({
14
+ resolveErrorMessageAssertions({
15
15
  value,
16
16
  options,
17
17
  requiredValidType: "string"
18
18
  });
19
- throw new TypeError(errorMessage);
20
19
  };
21
20
 
22
21
  export { assertIsString };
@@ -2,23 +2,22 @@
2
2
  * ====================================================
3
3
  * Rzl Utils-JS.
4
4
  * ----------------------------------------------------
5
- * Version: 3.7.1.
5
+ * Version: 3.9.0.
6
6
  * Author: Rizalvin Dwiky.
7
7
  * Repository: https://github.com/rzl-zone/utils-js.
8
8
  * ====================================================
9
9
  */
10
10
  'use strict';
11
11
 
12
- var chunkF3WBQKRI_cjs = require('./chunk-F3WBQKRI.cjs');
12
+ var chunk7C7TQC5J_cjs = require('./chunk-7C7TQC5J.cjs');
13
13
 
14
14
  function assertIsArray(value, options) {
15
- if (chunkF3WBQKRI_cjs.isArray(value)) return;
16
- const errorMessage = chunkF3WBQKRI_cjs.resolveErrorMessageAssertions({
15
+ if (chunk7C7TQC5J_cjs.isArray(value)) return;
16
+ chunk7C7TQC5J_cjs.resolveErrorMessageAssertions({
17
17
  value,
18
18
  options,
19
19
  requiredValidType: "array"
20
20
  });
21
- throw new TypeError(errorMessage);
22
21
  }
23
22
 
24
23
  exports.assertIsArray = assertIsArray;
@@ -2,17 +2,17 @@
2
2
  * ====================================================
3
3
  * Rzl Utils-JS.
4
4
  * ----------------------------------------------------
5
- * Version: 3.7.1.
5
+ * Version: 3.9.0.
6
6
  * Author: Rizalvin Dwiky.
7
7
  * Repository: https://github.com/rzl-zone/utils-js.
8
8
  * ====================================================
9
9
  */
10
10
  'use strict';
11
11
 
12
- var chunkF3WBQKRI_cjs = require('./chunk-F3WBQKRI.cjs');
12
+ var chunk7C7TQC5J_cjs = require('./chunk-7C7TQC5J.cjs');
13
13
 
14
14
  function isFinite(value) {
15
- return chunkF3WBQKRI_cjs.isNumber(value) && Number.isFinite(value);
15
+ return chunk7C7TQC5J_cjs.isNumber(value) && Number.isFinite(value);
16
16
  }
17
17
 
18
18
  exports.isFinite = isFinite;
@@ -2,7 +2,7 @@
2
2
  * ====================================================
3
3
  * Rzl Utils-JS.
4
4
  * ----------------------------------------------------
5
- * Version: 3.7.1.
5
+ * Version: 3.9.0.
6
6
  * Author: Rizalvin Dwiky.
7
7
  * Repository: https://github.com/rzl-zone/utils-js.
8
8
  * ====================================================
@@ -10,8 +10,8 @@
10
10
  'use strict';
11
11
 
12
12
  var chunkDVMHRLKP_cjs = require('./chunk-DVMHRLKP.cjs');
13
- var chunkYC7AK3KX_cjs = require('./chunk-YC7AK3KX.cjs');
14
- var chunkF3WBQKRI_cjs = require('./chunk-F3WBQKRI.cjs');
13
+ var chunkH44QVAZL_cjs = require('./chunk-H44QVAZL.cjs');
14
+ var chunk7C7TQC5J_cjs = require('./chunk-7C7TQC5J.cjs');
15
15
 
16
16
  var CustomPromise = class extends Promise {
17
17
  _value;
@@ -74,12 +74,14 @@ var AbortError = class extends Error {
74
74
  var delay = (milliSeconds = 1e3, signal) => {
75
75
  if (!chunkDVMHRLKP_cjs.isInteger(milliSeconds) || milliSeconds <= 0) {
76
76
  throw new TypeError(
77
- `First parameter (\`milliSeconds\`) must be of type \`number\` and value must be a \`non-zero\`, \`non-NaN\`, \`non-negative\`, and \`integer-number\`, but received: \`${chunkF3WBQKRI_cjs.getPreciseType(
77
+ `First parameter (\`milliSeconds\`) must be of type \`number\` and value must be a \`non-zero\`, \`non-NaN\`, \`non-negative\`, and \`integer-number\`, but received: \`${chunk7C7TQC5J_cjs.getPreciseType(
78
78
  milliSeconds
79
- )}\`, with value: \`${chunkYC7AK3KX_cjs.safeStableStringify(milliSeconds)}\`.`
79
+ )}\`, with value: \`${chunkH44QVAZL_cjs.safeStableStringify(milliSeconds, {
80
+ keepUndefined: true
81
+ })}\`.`
80
82
  );
81
83
  }
82
- if (chunkF3WBQKRI_cjs.isNull(signal) || signal && !(signal instanceof AbortSignal)) {
84
+ if (chunk7C7TQC5J_cjs.isNull(signal) || signal && !(signal instanceof AbortSignal)) {
83
85
  throw new TypeError(
84
86
  "Second parameter (`signal`) must be an `instance of AbortSignal` if provided."
85
87
  );
@@ -2,7 +2,7 @@
2
2
  * ====================================================
3
3
  * Rzl Utils-JS.
4
4
  * ----------------------------------------------------
5
- * Version: 3.7.1.
5
+ * Version: 3.9.0.
6
6
  * Author: Rizalvin Dwiky.
7
7
  * Repository: https://github.com/rzl-zone/utils-js.
8
8
  * ====================================================