@rzl-zone/utils-js 3.7.1 → 3.8.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.
- package/README.md +23 -0
- package/dist/assertions/index.cjs +1 -1
- package/dist/assertions/index.d.ts +8 -8
- package/dist/assertions/index.js +1 -1
- package/dist/chunk-2VO2CBTU.js +1 -1
- package/dist/{chunk-KTQLDIIT.cjs → chunk-3JD53UUH.cjs} +15 -5
- package/dist/chunk-3KTD3QDI.js +1 -1
- package/dist/chunk-4ACKNPL5.js +1 -1
- package/dist/chunk-4ZOXSUXB.js +1 -1
- package/dist/{chunk-6PKW4WCT.js → chunk-5IKZ3JDV.js} +20 -8
- package/dist/chunk-5NN4ZDE2.cjs +1 -1
- package/dist/{chunk-OS5OT5JA.cjs → chunk-5PF7KRCP.cjs} +25 -9
- package/dist/{chunk-66WLOZOD.cjs → chunk-6NORJBI6.cjs} +7 -5
- package/dist/chunk-6RFNZ2ZZ.cjs +1 -1
- package/dist/{chunk-TDPYR5JY.js → chunk-6VA4F6VR.js} +15 -5
- package/dist/chunk-6WMB5AJR.js +1 -1
- package/dist/chunk-7QQV66RX.cjs +1 -1
- package/dist/chunk-7WBMA2VE.cjs +1 -1
- package/dist/chunk-7ZNEUWYP.js +1 -1
- package/dist/chunk-A3YI6Y2P.js +1 -1
- package/dist/{chunk-RMJC3B5P.cjs → chunk-A4H7474O.cjs} +7 -4
- package/dist/chunk-AKKM6MOX.cjs +1 -1
- package/dist/chunk-ATLFMKAF.cjs +1 -1
- package/dist/chunk-B4SDEBN7.cjs +1 -1
- package/dist/chunk-B6UIKBHR.cjs +1 -1
- package/dist/chunk-BAV5T2E3.cjs +1 -1
- package/dist/chunk-BYUT376O.cjs +1 -1
- package/dist/chunk-CKUEZF4R.cjs +1 -1
- package/dist/chunk-DPLL67OT.js +1 -1
- package/dist/chunk-DVMHRLKP.cjs +1 -1
- package/dist/chunk-EK7FSI7F.cjs +1 -1
- package/dist/chunk-F3WBQKRI.cjs +1 -1
- package/dist/chunk-FI76UZRF.js +1 -1
- package/dist/chunk-GAJBF6DR.js +1 -1
- package/dist/{chunk-K3SONK25.cjs → chunk-HKJZ7K2K.cjs} +165 -14
- package/dist/{chunk-QUITZ3GP.js → chunk-I3IXLEEG.js} +25 -9
- package/dist/{chunk-VNADVWSJ.js → chunk-JIROTDOU.js} +4 -2
- package/dist/chunk-JY4HLZ4W.js +1 -1
- package/dist/chunk-K63WO3XA.cjs +1 -1
- package/dist/chunk-KHO2SBNA.cjs +1 -1
- package/dist/chunk-KPCDDYTZ.js +1 -1
- package/dist/{chunk-XFTUHS4Y.js → chunk-KVZ3HL2B.js} +7 -5
- package/dist/chunk-L5RDAVVH.js +1 -1
- package/dist/chunk-LEX4TQW2.js +1 -1
- package/dist/chunk-LIU4S3JA.cjs +1 -1
- package/dist/{chunk-R3PBF6F7.cjs → chunk-LVFTN6DK.cjs} +29 -17
- package/dist/chunk-NREACG6M.cjs +1 -1
- package/dist/chunk-OFBFGFVH.js +1 -1
- package/dist/chunk-ONZFBJVW.js +1 -1
- package/dist/{chunk-D53CE4BT.js → chunk-P3ST4UZA.js} +6 -3
- package/dist/{chunk-WNO3EPYT.js → chunk-PW2VMJLT.js} +4 -2
- package/dist/chunk-PZQC3FZY.js +1 -1
- package/dist/chunk-QAPYHLHC.cjs +1 -1
- package/dist/chunk-QNKGP5DY.js +1 -1
- package/dist/{chunk-2CQI36UD.cjs → chunk-RJYWBVGD.cjs} +4 -2
- package/dist/{chunk-3LEWQV3R.js → chunk-RRJIRXHS.js} +5 -5
- package/dist/{chunk-BG3AS5BU.cjs → chunk-SGCN4ED4.cjs} +4 -2
- package/dist/chunk-SLP24LUV.js +302 -0
- package/dist/chunk-SZJ7OI4S.js +1 -1
- package/dist/chunk-TDYGYHSH.js +1 -1
- package/dist/chunk-TFDXRT6D.cjs +1 -1
- package/dist/chunk-U5VR4TJN.js +1 -1
- package/dist/chunk-UDA26MCU.cjs +1 -1
- package/dist/chunk-UKAUXY2U.cjs +1 -1
- package/dist/chunk-VCVND6CH.js +1 -1
- package/dist/chunk-VJDDGRIK.cjs +1 -1
- package/dist/chunk-VJVCXEH7.cjs +1 -1
- package/dist/chunk-WVSPXFTY.js +1 -1
- package/dist/chunk-YC7AK3KX.cjs +1 -1
- package/dist/chunk-YGB2BQPB.cjs +1 -1
- package/dist/chunk-YS27V6LS.js +1 -1
- package/dist/chunk-YWHHVDT4.js +1 -1
- package/dist/chunk-ZN53RM3R.js +1 -1
- package/dist/{chunk-KIYALQQF.cjs → chunk-ZW3VYES4.cjs} +5 -5
- package/dist/conversions/index.cjs +18 -18
- package/dist/conversions/index.d.ts +10 -12
- package/dist/conversions/index.js +3 -3
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.d.ts +9 -9
- package/dist/events/index.js +1 -1
- package/dist/formatters/index.cjs +12 -12
- package/dist/formatters/index.d.ts +19 -24
- package/dist/formatters/index.js +2 -2
- package/dist/generators/index.cjs +10 -6
- package/dist/generators/index.d.ts +155 -26
- package/dist/generators/index.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/{isPlainObject-FWmcJF6k.d.ts → isPlainObject-BTPjv6zB.d.ts} +2 -2
- package/dist/next/index.cjs +11 -9
- package/dist/next/index.d.ts +11 -11
- package/dist/next/index.js +5 -3
- package/dist/next/server/index.cjs +1 -1
- package/dist/next/server/index.d.ts +4 -4
- package/dist/next/server/index.js +1 -1
- package/dist/operations/index.cjs +6 -6
- package/dist/operations/index.d.ts +8 -9
- package/dist/operations/index.js +3 -3
- package/dist/parsers/index.cjs +1 -1
- package/dist/parsers/index.d.ts +1 -1
- package/dist/parsers/index.js +1 -1
- package/dist/predicates/index.cjs +1 -1
- package/dist/predicates/index.d.ts +15 -28
- package/dist/predicates/index.js +1 -1
- package/dist/promises/index.cjs +4 -4
- package/dist/promises/index.d.ts +6 -7
- package/dist/promises/index.js +2 -2
- package/dist/rzl-utils.global.js +2 -2
- package/dist/strings/index.cjs +1 -1
- package/dist/strings/index.d.ts +1 -1
- package/dist/strings/index.js +1 -1
- package/dist/tailwind/index.cjs +10 -10
- package/dist/tailwind/index.d.ts +18 -18
- package/dist/tailwind/index.js +2 -2
- package/dist/urls/index.cjs +9 -9
- package/dist/urls/index.d.ts +9 -10
- package/dist/urls/index.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-ABA2ZSBQ.js +0 -152
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
|
-
import { safeJsonParse } from './chunk-
|
|
10
|
+
import { safeJsonParse } from './chunk-KVZ3HL2B.js';
|
|
11
11
|
import { isEqual } from './chunk-SZJ7OI4S.js';
|
|
12
12
|
import { isEmptyArray } from './chunk-VCVND6CH.js';
|
|
13
13
|
import { assertIsArray } from './chunk-6WMB5AJR.js';
|
|
@@ -57,7 +57,10 @@ var omitKeysDeep = (object, keysToOmit) => {
|
|
|
57
57
|
if (isNonEmptyArray(duplicates)) {
|
|
58
58
|
throw new Error(
|
|
59
59
|
`Function "omitKeysDeep" Error: Duplicate keys detected - \`${safeStableStringify(
|
|
60
|
-
duplicates
|
|
60
|
+
duplicates,
|
|
61
|
+
{
|
|
62
|
+
keepUndefined: true
|
|
63
|
+
}
|
|
61
64
|
)}\`.`
|
|
62
65
|
);
|
|
63
66
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -58,7 +58,9 @@ function normalizePathname(pathname, options = {
|
|
|
58
58
|
throw new TypeError(
|
|
59
59
|
`Parameter \`defaultPath\` property of the \`options\` (second parameter) must be of type \`string\` and not empty-string, but received: \`${getPreciseType(
|
|
60
60
|
defaultPath
|
|
61
|
-
)}\`, with value: \`${safeStableStringify(defaultPath
|
|
61
|
+
)}\`, with value: \`${safeStableStringify(defaultPath, {
|
|
62
|
+
keepUndefined: true
|
|
63
|
+
})}\`.`
|
|
62
64
|
);
|
|
63
65
|
}
|
|
64
66
|
assertIsBoolean(keepTrailingSlash, {
|
package/dist/chunk-PZQC3FZY.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-QAPYHLHC.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-QNKGP5DY.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -76,7 +76,9 @@ var delay = (milliSeconds = 1e3, signal) => {
|
|
|
76
76
|
throw new TypeError(
|
|
77
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(
|
|
78
78
|
milliSeconds
|
|
79
|
-
)}\`, with value: \`${chunkYC7AK3KX_cjs.safeStableStringify(milliSeconds
|
|
79
|
+
)}\`, with value: \`${chunkYC7AK3KX_cjs.safeStableStringify(milliSeconds, {
|
|
80
|
+
keepUndefined: true
|
|
81
|
+
})}\`.`
|
|
80
82
|
);
|
|
81
83
|
}
|
|
82
84
|
if (chunkF3WBQKRI_cjs.isNull(signal) || signal && !(signal instanceof AbortSignal)) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -39,11 +39,11 @@ function toStringValue(value) {
|
|
|
39
39
|
}
|
|
40
40
|
return str;
|
|
41
41
|
}
|
|
42
|
-
function cx(...
|
|
42
|
+
function cx(...values) {
|
|
43
43
|
let str = "";
|
|
44
|
-
for (const
|
|
45
|
-
if (!
|
|
46
|
-
const x = toStringValue(
|
|
44
|
+
for (const value of values) {
|
|
45
|
+
if (!value) continue;
|
|
46
|
+
const x = toStringValue(value);
|
|
47
47
|
if (!x) continue;
|
|
48
48
|
if (str) str += " ";
|
|
49
49
|
str += x;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -60,7 +60,9 @@ function normalizePathname(pathname, options = {
|
|
|
60
60
|
throw new TypeError(
|
|
61
61
|
`Parameter \`defaultPath\` property of the \`options\` (second parameter) must be of type \`string\` and not empty-string, but received: \`${chunkF3WBQKRI_cjs.getPreciseType(
|
|
62
62
|
defaultPath
|
|
63
|
-
)}\`, with value: \`${chunkYC7AK3KX_cjs.safeStableStringify(defaultPath
|
|
63
|
+
)}\`, with value: \`${chunkYC7AK3KX_cjs.safeStableStringify(defaultPath, {
|
|
64
|
+
keepUndefined: true
|
|
65
|
+
})}\`.`
|
|
64
66
|
);
|
|
65
67
|
}
|
|
66
68
|
chunkF3WBQKRI_cjs.assertIsBoolean(keepTrailingSlash, {
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ====================================================
|
|
3
|
+
* Rzl Utils-JS.
|
|
4
|
+
* ----------------------------------------------------
|
|
5
|
+
* Version: 3.8.0.
|
|
6
|
+
* Author: Rizalvin Dwiky.
|
|
7
|
+
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
|
+
* ====================================================
|
|
9
|
+
*/
|
|
10
|
+
import { isInteger } from './chunk-WVSPXFTY.js';
|
|
11
|
+
import { safeStableStringify } from './chunk-2VO2CBTU.js';
|
|
12
|
+
import { isNonEmptyArray, getPreciseType, isNumber, isPlainObject, assertIsBoolean, isNaN, isNonEmptyString, isBoolean } from './chunk-3KTD3QDI.js';
|
|
13
|
+
|
|
14
|
+
function getRandomItem(array) {
|
|
15
|
+
if (!isNonEmptyArray(array)) return void 0;
|
|
16
|
+
const randomIndex = Math.floor(Math.random() * (array.length || 0));
|
|
17
|
+
return array[randomIndex];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var randomInt = (min, max) => {
|
|
21
|
+
if (!isInteger(min) || !isInteger(max)) {
|
|
22
|
+
throw new TypeError(
|
|
23
|
+
`First parameter (\`min\`) and second parameter (\`max\`) must be of type \`integer-number\`${minValueNote(
|
|
24
|
+
min,
|
|
25
|
+
max
|
|
26
|
+
)}value, but received: ['min': \`${getPreciseType(
|
|
27
|
+
min
|
|
28
|
+
)}\` - (with value: \`${safeStableStringify(min, {
|
|
29
|
+
keepUndefined: true
|
|
30
|
+
})})\`, 'max': \`${getPreciseType(max)}\` - (with value: \`${safeStableStringify(
|
|
31
|
+
max,
|
|
32
|
+
{
|
|
33
|
+
keepUndefined: true
|
|
34
|
+
}
|
|
35
|
+
)}\`)].`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (min > max) {
|
|
39
|
+
throw new RangeError(
|
|
40
|
+
`First parameter (\`min\`) must be less than or equal to second parameter (\`max\`), but received: ['min': ${formatValue(
|
|
41
|
+
min
|
|
42
|
+
)} - (with value: \`${safeStableStringify(min, {
|
|
43
|
+
keepUndefined: true
|
|
44
|
+
})})\`, 'max': ${formatValue(max)} - (with value: \`${safeStableStringify(max, {
|
|
45
|
+
keepUndefined: true
|
|
46
|
+
})})\`].`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
min = Math.max(1, min);
|
|
50
|
+
max = Math.min(Number.MAX_SAFE_INTEGER, max);
|
|
51
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
52
|
+
};
|
|
53
|
+
var formatValue = (value) => {
|
|
54
|
+
return isNumber(value, { includeNaN: true }) ? value === Number.MIN_VALUE ? "`Number.MIN_VALUE`" : `${value}` : `\`${getPreciseType(value)}\``;
|
|
55
|
+
};
|
|
56
|
+
var minValueNote = (...values) => {
|
|
57
|
+
return values.some((v) => isNumber(v, { includeNaN: true }) && v === Number.MIN_VALUE) ? " and can't be `Number.MIN_VALUE` " : " ";
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
var randomIntByLength = (options) => {
|
|
61
|
+
if (!isPlainObject(options)) {
|
|
62
|
+
options = {};
|
|
63
|
+
}
|
|
64
|
+
const { minLength = 1, maxLength = 16, avoidZero = false } = options;
|
|
65
|
+
assertIsBoolean(avoidZero, {
|
|
66
|
+
message({ currentType, validType }) {
|
|
67
|
+
return `Parameters \`avoidZero\` must be of type \`${validType}\`, but received: \`${currentType}\`.`;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (!isInteger(minLength) || !isInteger(maxLength)) {
|
|
71
|
+
throw new TypeError(
|
|
72
|
+
`Parameters \`minLength\` and \`maxLength\` must be of type \`integer-number\`, but received: ['minLength': \`${getPreciseType(
|
|
73
|
+
minLength
|
|
74
|
+
)}\` - (with value: ${safeStableStringify(minLength, {
|
|
75
|
+
keepUndefined: true
|
|
76
|
+
})}), 'maxLength': \`${getPreciseType(
|
|
77
|
+
maxLength
|
|
78
|
+
)}\` - (with value: ${safeStableStringify(maxLength, {
|
|
79
|
+
keepUndefined: true
|
|
80
|
+
})})].`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (minLength < 1 || maxLength > 16 || minLength > maxLength) {
|
|
84
|
+
throw new RangeError(
|
|
85
|
+
`Invalid range at parameters \`minLength\` must be \u2265 1, \`maxLength\` must be \u2264 16, and \`minLength\` \u2264 \`maxLength\`, but received: ['minLength': \`${minLength}\`, 'maxLength': \`${maxLength}\`].`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const randomLength = minLength === maxLength ? minLength : randomInt(minLength, maxLength);
|
|
89
|
+
const minValue = 10 ** (randomLength - 1);
|
|
90
|
+
const maxValue = 10 ** randomLength - 1;
|
|
91
|
+
let result = randomInt(minValue, maxValue);
|
|
92
|
+
if (avoidZero && result === 0) {
|
|
93
|
+
result = minValue;
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
var randomStr = (options) => {
|
|
99
|
+
if (!isPlainObject(options)) {
|
|
100
|
+
options = {};
|
|
101
|
+
}
|
|
102
|
+
const {
|
|
103
|
+
minLength = 40,
|
|
104
|
+
maxLength = 40,
|
|
105
|
+
type = "string",
|
|
106
|
+
avoidWhiteSpace = true
|
|
107
|
+
} = options;
|
|
108
|
+
assertIsBoolean(avoidWhiteSpace, {
|
|
109
|
+
message({ currentType, validType }) {
|
|
110
|
+
return `Parameters \`avoidWhiteSpace\` property of the \`options\` (first-parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
if (!isInteger(minLength) || !isInteger(maxLength)) {
|
|
114
|
+
throw new TypeError(
|
|
115
|
+
`Parameters \`minLength\` and \`maxLength\` must be of type \`integer-number\`, but received: ['minLength': \`${getPreciseType(
|
|
116
|
+
minLength
|
|
117
|
+
)}\` - (with value: ${safeStableStringify(minLength, {
|
|
118
|
+
keepUndefined: true
|
|
119
|
+
})}), 'maxLength': \`${getPreciseType(
|
|
120
|
+
maxLength
|
|
121
|
+
)}\` - (with value: ${safeStableStringify(maxLength, {
|
|
122
|
+
keepUndefined: true
|
|
123
|
+
})})].`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (minLength < 1 || maxLength > 5e3 || minLength > maxLength) {
|
|
127
|
+
throw new RangeError(
|
|
128
|
+
`Invalid range at parameters \`minLength\` must be \u2265 1, \`maxLength\` must be \u2264 5000, and \`minLength\` \u2264 \`maxLength\`, but received: ['minLength': \`${minLength}\`, 'maxLength': \`${maxLength}\`].`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
if (type !== "string" && type !== "number") {
|
|
132
|
+
throw new TypeError(
|
|
133
|
+
`Parameter \`type\` must be of type \`string\` with value one of "string" | "number", but received: \`${getPreciseType(
|
|
134
|
+
type
|
|
135
|
+
)}\`, with value: ${safeStableStringify(type, {
|
|
136
|
+
keepUndefined: true
|
|
137
|
+
})}.`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
const length = randomInt(minLength, maxLength);
|
|
141
|
+
const cleanCharacters = (charSet) => {
|
|
142
|
+
return avoidWhiteSpace ? charSet.replace(/\s|\n|\t/g, "") : charSet;
|
|
143
|
+
};
|
|
144
|
+
const defaultNumberSet = "0123456789";
|
|
145
|
+
const defaultStringSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
146
|
+
const baseCharSet = type === "number" ? (!isNaN(Number(options.replaceGenInt)) ? options.replaceGenInt : void 0) ?? defaultNumberSet : (options.replaceGenStr ? options.replaceGenStr : void 0) ?? defaultStringSet;
|
|
147
|
+
const characterSet = cleanCharacters(baseCharSet) + (options.addChar || "");
|
|
148
|
+
if (!characterSet.length) {
|
|
149
|
+
const errCharSet = () => {
|
|
150
|
+
if (type === "number") {
|
|
151
|
+
if (avoidWhiteSpace) {
|
|
152
|
+
return `If \`avoidWhiteSpace\` is true, and \`replaceGenInt\` cant be empty-string value, ensure \`replaceGenInt\` has valid characters and non-nan string number.`;
|
|
153
|
+
}
|
|
154
|
+
return `Ensure \`replaceGenInt\` has valid characters and not a NaN number string while convert to number.`;
|
|
155
|
+
}
|
|
156
|
+
return `Ensure \`replaceGenStr\` has valid characters and non empty string.`;
|
|
157
|
+
};
|
|
158
|
+
throw new Error(`Character set is empty. ${errCharSet()}`);
|
|
159
|
+
}
|
|
160
|
+
let result = "";
|
|
161
|
+
for (let i = 0; i < length; i++) {
|
|
162
|
+
result += characterSet.charAt(Math.floor(Math.random() * characterSet.length));
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
function randomUUID(options = {}) {
|
|
168
|
+
if (!isPlainObject(options)) {
|
|
169
|
+
throw new TypeError(
|
|
170
|
+
`First parameter (\`options\`) must be a plain object with optional properties \`version\` and \`monotonic\`, but received: \`${getPreciseType(
|
|
171
|
+
options
|
|
172
|
+
)}\` - (with value: \`${safeStableStringify(options, { keepUndefined: true })}\`).`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
const { version = "v4", monotonic = false } = options;
|
|
176
|
+
if (!isNonEmptyString(version)) {
|
|
177
|
+
throw new TypeError(
|
|
178
|
+
`Parameter \`version\` property of the \`options\` (first parameter) must be a \`string\` of either "v4" or "v7", but received type: \`${getPreciseType(
|
|
179
|
+
version
|
|
180
|
+
)}\` - (with value: \`${safeStableStringify(version, { keepUndefined: true })}\`).`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
if (version !== "v4" && version !== "v7") {
|
|
184
|
+
throw new RangeError(
|
|
185
|
+
`Unsupported UUID version. Allowed values are "v4" or "v7". (received: \`${safeStableStringify(
|
|
186
|
+
version,
|
|
187
|
+
{
|
|
188
|
+
keepUndefined: true
|
|
189
|
+
}
|
|
190
|
+
)}\`).`
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
if (!isBoolean(monotonic)) {
|
|
194
|
+
throw new TypeError(
|
|
195
|
+
`Parameter \`monotonic\` property of the \`options\` (first parameter) must be a \`boolean\` when provided, but received type: \`${getPreciseType(
|
|
196
|
+
monotonic
|
|
197
|
+
)}\` - (with value: \`${safeStableStringify(monotonic, {
|
|
198
|
+
keepUndefined: true
|
|
199
|
+
})}\`).`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
if (monotonic && version !== "v7") {
|
|
203
|
+
throw new TypeError(
|
|
204
|
+
`Parameter \`monotonic\` property of the \`options\` (first parameter) is only supported for version "v7". Received: version=${safeStableStringify(
|
|
205
|
+
version,
|
|
206
|
+
{ keepUndefined: true }
|
|
207
|
+
)}.`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
if (version === "v4") {
|
|
211
|
+
return generateUUIDv4();
|
|
212
|
+
}
|
|
213
|
+
return generateUUIDv7({ monotonic });
|
|
214
|
+
}
|
|
215
|
+
function hasCryptoGetRandomValues() {
|
|
216
|
+
return typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function";
|
|
217
|
+
}
|
|
218
|
+
function hasCryptoRandomUUID() {
|
|
219
|
+
return typeof crypto !== "undefined" && typeof crypto.randomUUID === "function";
|
|
220
|
+
}
|
|
221
|
+
function getRandomBytes(len) {
|
|
222
|
+
if (hasCryptoGetRandomValues()) {
|
|
223
|
+
return crypto.getRandomValues(new Uint8Array(len));
|
|
224
|
+
}
|
|
225
|
+
const arr = new Uint8Array(len);
|
|
226
|
+
for (let i = 0; i < len; i++) {
|
|
227
|
+
arr[i] = Math.floor(Math.random() * 256);
|
|
228
|
+
}
|
|
229
|
+
return arr;
|
|
230
|
+
}
|
|
231
|
+
var byteToHex = (() => {
|
|
232
|
+
const arr = [];
|
|
233
|
+
for (let i = 0; i < 256; ++i) {
|
|
234
|
+
arr.push((i + 256).toString(16).substring(1));
|
|
235
|
+
}
|
|
236
|
+
return arr;
|
|
237
|
+
})();
|
|
238
|
+
function generateUUIDv4() {
|
|
239
|
+
if (hasCryptoRandomUUID()) {
|
|
240
|
+
return crypto.randomUUID();
|
|
241
|
+
}
|
|
242
|
+
if (hasCryptoGetRandomValues()) {
|
|
243
|
+
const rnd = crypto.getRandomValues(new Uint8Array(16));
|
|
244
|
+
rnd[6] = rnd[6] & 15 | 64;
|
|
245
|
+
rnd[8] = rnd[8] & 63 | 128;
|
|
246
|
+
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]];
|
|
247
|
+
}
|
|
248
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
249
|
+
const r = Math.random() * 16 | 0;
|
|
250
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
251
|
+
return v.toString(16);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
var monotonicState = {
|
|
255
|
+
lastTimestampMs: -1,
|
|
256
|
+
lastRand: null
|
|
257
|
+
};
|
|
258
|
+
function incrementUint8ArrayBigEndian(arr) {
|
|
259
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
260
|
+
if (arr[i] === 255) {
|
|
261
|
+
arr[i] = 0;
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
arr[i] = arr[i] + 1 & 255;
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
function generateUUIDv7({ monotonic = false } = {}) {
|
|
270
|
+
const nowMs = Date.now();
|
|
271
|
+
const tsHex = BigInt(nowMs).toString(16).padStart(12, "0");
|
|
272
|
+
let rand = getRandomBytes(10);
|
|
273
|
+
if (monotonic) {
|
|
274
|
+
if (monotonicState.lastTimestampMs === nowMs && monotonicState.lastRand) {
|
|
275
|
+
const copy = new Uint8Array(monotonicState.lastRand);
|
|
276
|
+
const overflow = incrementUint8ArrayBigEndian(copy);
|
|
277
|
+
if (overflow) {
|
|
278
|
+
throw new RangeError(
|
|
279
|
+
"Monotonic UUID sequence overflow: too many UUIDs generated within the same millisecond."
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
rand = copy;
|
|
283
|
+
monotonicState.lastRand = copy;
|
|
284
|
+
} else {
|
|
285
|
+
const fresh = getRandomBytes(10);
|
|
286
|
+
monotonicState.lastRand = new Uint8Array(fresh);
|
|
287
|
+
monotonicState.lastTimestampMs = nowMs;
|
|
288
|
+
rand = fresh;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
rand[0] = rand[0] & 15 | 112;
|
|
292
|
+
rand[2] = rand[2] & 63 | 128;
|
|
293
|
+
const randHex = Array.from(rand, (b) => byteToHex[b]).join("");
|
|
294
|
+
const part1 = tsHex.slice(0, 8);
|
|
295
|
+
const part2 = tsHex.slice(8, 12);
|
|
296
|
+
const part3 = randHex.slice(0, 4);
|
|
297
|
+
const part4 = randHex.slice(4, 8);
|
|
298
|
+
const part5 = randHex.slice(8, 20);
|
|
299
|
+
return [part1, part2, part3, part4, part5].join("-");
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export { getRandomItem, randomInt, randomIntByLength, randomStr, randomUUID };
|
package/dist/chunk-SZJ7OI4S.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-TDYGYHSH.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-TFDXRT6D.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-U5VR4TJN.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-UDA26MCU.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-UKAUXY2U.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-VCVND6CH.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-VJDDGRIK.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-VJVCXEH7.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-WVSPXFTY.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-YC7AK3KX.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-YGB2BQPB.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-YS27V6LS.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-YWHHVDT4.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
package/dist/chunk-ZN53RM3R.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.8.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -41,11 +41,11 @@ function toStringValue(value) {
|
|
|
41
41
|
}
|
|
42
42
|
return str;
|
|
43
43
|
}
|
|
44
|
-
function cx(...
|
|
44
|
+
function cx(...values) {
|
|
45
45
|
let str = "";
|
|
46
|
-
for (const
|
|
47
|
-
if (!
|
|
48
|
-
const x = toStringValue(
|
|
46
|
+
for (const value of values) {
|
|
47
|
+
if (!value) continue;
|
|
48
|
+
const x = toStringValue(value);
|
|
49
49
|
if (!x) continue;
|
|
50
50
|
if (str) str += " ";
|
|
51
51
|
str += x;
|