@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.
- package/README.md +28 -1
- package/dist/assertions/index.cjs +11 -11
- package/dist/assertions/index.d.ts +169 -58
- package/dist/assertions/index.js +5 -5
- package/dist/{chunk-EK7FSI7F.cjs → chunk-2XGQQZ6A.cjs} +3 -3
- package/dist/{chunk-YS27V6LS.js → chunk-3LE6NX57.js} +5 -176
- package/dist/{chunk-PZQC3FZY.js → chunk-44X74C26.js} +4 -4
- package/dist/{chunk-4ACKNPL5.js → chunk-5KDVIEVO.js} +2 -2
- package/dist/{chunk-JY4HLZ4W.js → chunk-5O66AUEC.js} +2 -2
- package/dist/chunk-5Y6JL47L.js +302 -0
- package/dist/{chunk-KIYALQQF.cjs → chunk-62FS7WMB.cjs} +35 -35
- package/dist/{chunk-VJVCXEH7.cjs → chunk-6AMDHVS2.cjs} +9 -181
- package/dist/{chunk-6PKW4WCT.js → chunk-6WVOUVWD.js} +27 -15
- package/dist/{chunk-BYUT376O.cjs → chunk-76ATVDCR.cjs} +3 -3
- package/dist/{chunk-F3WBQKRI.cjs → chunk-7C7TQC5J.cjs} +29 -7
- package/dist/{chunk-QUITZ3GP.js → chunk-7EIFPHV3.js} +32 -16
- package/dist/{chunk-6RFNZ2ZZ.cjs → chunk-7NXFGJJE.cjs} +14 -14
- package/dist/{chunk-TFDXRT6D.cjs → chunk-ALRISPTL.cjs} +3 -3
- package/dist/chunk-BAV5T2E3.cjs +1 -1
- package/dist/{chunk-4ZOXSUXB.js → chunk-C7GC2PFX.js} +3 -3
- package/dist/chunk-DVMHRLKP.cjs +1 -1
- package/dist/{chunk-XFTUHS4Y.js → chunk-DXPM4NOU.js} +10 -8
- package/dist/{chunk-DPLL67OT.js → chunk-EJV5AF4L.js} +2 -2
- package/dist/{chunk-NREACG6M.cjs → chunk-FWWPEL7J.cjs} +3 -3
- package/dist/{chunk-LEX4TQW2.js → chunk-GHU356XQ.js} +4 -6
- package/dist/chunk-GKDSBOYE.js +209 -0
- package/dist/{chunk-YC7AK3KX.cjs → chunk-H44QVAZL.cjs} +31 -31
- package/dist/{chunk-AKKM6MOX.cjs → chunk-I33PB44Q.cjs} +15 -15
- package/dist/{chunk-LIU4S3JA.cjs → chunk-IX6PF5ZP.cjs} +4 -4
- package/dist/{chunk-3KTD3QDI.js → chunk-J4TT33ZX.js} +29 -7
- package/dist/{chunk-SZJ7OI4S.js → chunk-J6VLFVIL.js} +3 -3
- package/dist/{chunk-KTQLDIIT.cjs → chunk-JI57K7D4.cjs} +173 -163
- package/dist/{chunk-OFBFGFVH.js → chunk-JYOCB6OV.js} +2 -2
- package/dist/chunk-KHO2SBNA.cjs +1 -1
- package/dist/{chunk-66WLOZOD.cjs → chunk-KUVRZ2JW.cjs} +53 -51
- package/dist/chunk-L5RDAVVH.js +1 -1
- package/dist/{chunk-VCVND6CH.js → chunk-M5QB2GM5.js} +2 -2
- package/dist/{chunk-3LEWQV3R.js → chunk-MBFVTGYS.js} +8 -8
- package/dist/{chunk-UKAUXY2U.cjs → chunk-MMRHKYT6.cjs} +12 -12
- package/dist/{chunk-U5VR4TJN.js → chunk-MS2KSKD7.js} +9 -9
- package/dist/{chunk-7ZNEUWYP.js → chunk-MZ3T6L7Z.js} +2 -2
- package/dist/{chunk-ATLFMKAF.cjs → chunk-NAOVH4OH.cjs} +7 -7
- package/dist/chunk-NJ24M6ZH.cjs +308 -0
- package/dist/chunk-OCTHWEZK.cjs +249 -0
- package/dist/chunk-ONZFBJVW.js +1 -1
- package/dist/{chunk-FI76UZRF.js → chunk-OSSFLQDD.js} +3 -4
- package/dist/{chunk-7WBMA2VE.cjs → chunk-OYFUBKEG.cjs} +4 -5
- package/dist/{chunk-B4SDEBN7.cjs → chunk-PWKOFPAH.cjs} +3 -3
- package/dist/{chunk-2CQI36UD.cjs → chunk-QGTFQ7RO.cjs} +8 -6
- package/dist/chunk-QNKGP5DY.js +1 -1
- package/dist/chunk-QXTJVDWE.js +676 -0
- package/dist/{chunk-B6UIKBHR.cjs → chunk-QZI5PVCI.cjs} +4 -4
- package/dist/{chunk-WNO3EPYT.js → chunk-R2DR7SPJ.js} +102 -26
- package/dist/{chunk-TDYGYHSH.js → chunk-SN5HAK3Y.js} +4 -4
- package/dist/{chunk-D53CE4BT.js → chunk-SRWL4YCP.js} +11 -8
- package/dist/{chunk-7QQV66RX.cjs → chunk-TJ5OY6MC.cjs} +10 -10
- package/dist/{chunk-6WMB5AJR.js → chunk-TXOVQZPU.js} +3 -4
- package/dist/chunk-UDA26MCU.cjs +1 -1
- package/dist/{chunk-R3PBF6F7.cjs → chunk-UFYMRRJH.cjs} +73 -61
- package/dist/{chunk-5NN4ZDE2.cjs → chunk-UV5BKAYW.cjs} +6 -8
- package/dist/{chunk-GAJBF6DR.js → chunk-UXT4XSUK.js} +2 -2
- package/dist/{chunk-TDPYR5JY.js → chunk-VBSLIIDB.js} +24 -14
- package/dist/chunk-VCYXNIZ2.cjs +678 -0
- package/dist/chunk-VJDDGRIK.cjs +1 -1
- package/dist/{chunk-VNADVWSJ.js → chunk-WB3FT62A.js} +6 -4
- package/dist/{chunk-K63WO3XA.cjs → chunk-WKM6UVMG.cjs} +4 -5
- package/dist/{chunk-OS5OT5JA.cjs → chunk-WLEZ2KSG.cjs} +142 -126
- package/dist/{chunk-ZN53RM3R.js → chunk-WRGN6UBK.js} +2 -2
- package/dist/chunk-WVSPXFTY.js +1 -1
- package/dist/{chunk-2VO2CBTU.js → chunk-X6ULJZ3X.js} +2 -2
- package/dist/{chunk-CKUEZF4R.cjs → chunk-XYWC4EQ3.cjs} +71 -71
- package/dist/{chunk-A3YI6Y2P.js → chunk-YHFRCVTN.js} +3 -3
- package/dist/{chunk-RMJC3B5P.cjs → chunk-YQHJB7KR.cjs} +30 -27
- package/dist/{chunk-YGB2BQPB.cjs → chunk-YVRUY4EW.cjs} +8 -8
- package/dist/chunk-YWHHVDT4.js +1 -1
- package/dist/chunk-ZTHJQJ5F.cjs +211 -0
- package/dist/conversions/index.cjs +34 -34
- package/dist/conversions/index.d.ts +10 -12
- package/dist/conversions/index.js +15 -15
- package/dist/events/index.cjs +8 -8
- package/dist/events/index.d.ts +9 -9
- package/dist/events/index.js +4 -4
- package/dist/formatters/index.cjs +19 -19
- package/dist/formatters/index.d.ts +19 -24
- package/dist/formatters/index.js +9 -9
- package/dist/generators/index.cjs +12 -8
- package/dist/generators/index.d.ts +155 -26
- package/dist/generators/index.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/{isPlainObject-FWmcJF6k.d.ts → isPlainObject-BTPjv6zB.d.ts} +2 -2
- package/dist/next/index.cjs +39 -36
- package/dist/next/index.d.ts +11 -11
- package/dist/next/index.js +12 -9
- package/dist/next/server/index.cjs +4 -4
- package/dist/next/server/index.d.ts +4 -4
- package/dist/next/server/index.js +2 -2
- package/dist/operations/index.cjs +11 -11
- package/dist/operations/index.d.ts +8 -9
- package/dist/operations/index.js +8 -8
- package/dist/parsers/index.cjs +6 -4
- package/dist/parsers/index.d.ts +224 -32
- package/dist/parsers/index.js +5 -3
- package/dist/predicates/index.cjs +77 -76
- package/dist/predicates/index.d.ts +15 -28
- package/dist/predicates/index.js +14 -13
- package/dist/promises/index.cjs +6 -6
- package/dist/promises/index.d.ts +5 -7
- package/dist/promises/index.js +4 -4
- package/dist/rzl-utils.global.js +2 -2
- package/dist/strings/index.cjs +23 -23
- package/dist/strings/index.d.ts +1 -1
- package/dist/strings/index.js +7 -7
- package/dist/tailwind/index.cjs +13 -13
- package/dist/tailwind/index.d.ts +18 -18
- package/dist/tailwind/index.js +5 -5
- package/dist/urls/index.cjs +23 -21
- package/dist/urls/index.d.ts +188 -121
- package/dist/urls/index.js +16 -14
- package/package.json +1 -1
- package/dist/chunk-ABA2ZSBQ.js +0 -152
- package/dist/chunk-BG3AS5BU.cjs +0 -173
- package/dist/chunk-K3SONK25.cjs +0 -157
- package/dist/chunk-KPCDDYTZ.js +0 -417
- package/dist/chunk-QAPYHLHC.cjs +0 -419
|
@@ -2,185 +2,14 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
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 {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
var maxInt = 2147483647;
|
|
14
|
-
var base = 36;
|
|
15
|
-
var tMin = 1;
|
|
16
|
-
var tMax = 26;
|
|
17
|
-
var skew = 38;
|
|
18
|
-
var damp = 700;
|
|
19
|
-
var initialBias = 72;
|
|
20
|
-
var initialN = 128;
|
|
21
|
-
var delimiter = "-";
|
|
22
|
-
var regexPunycode = /^xn--/;
|
|
23
|
-
var regexNonASCII = /[^\0-\x7F]/;
|
|
24
|
-
var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g;
|
|
25
|
-
var errors = {
|
|
26
|
-
overflow: "Overflow: input needs wider integers to process",
|
|
27
|
-
"not-basic": "Illegal input >= 0x80 (not a basic code point)",
|
|
28
|
-
"invalid-input": "Invalid input"
|
|
29
|
-
};
|
|
30
|
-
var floor = Math.floor;
|
|
31
|
-
var stringFromCharCode = String.fromCharCode;
|
|
32
|
-
function error(type) {
|
|
33
|
-
throw new RangeError(errors[type]);
|
|
34
|
-
}
|
|
35
|
-
function map(array, fn) {
|
|
36
|
-
const result = [];
|
|
37
|
-
let length = array.length;
|
|
38
|
-
while (length--) result[length] = fn(array[length]);
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
function mapDomain(domain, fn) {
|
|
42
|
-
const parts = domain.split("@");
|
|
43
|
-
let result = "";
|
|
44
|
-
if (parts.length > 1) {
|
|
45
|
-
result = parts[0] + "@";
|
|
46
|
-
domain = parts[1];
|
|
47
|
-
}
|
|
48
|
-
domain = domain.replace(regexSeparators, ".");
|
|
49
|
-
const labels = domain.split(".");
|
|
50
|
-
return result + map(labels, fn).join(".");
|
|
51
|
-
}
|
|
52
|
-
function ucs2decode(input) {
|
|
53
|
-
const output = [];
|
|
54
|
-
let counter = 0;
|
|
55
|
-
const length = input.length;
|
|
56
|
-
while (counter < length) {
|
|
57
|
-
const value = input.charCodeAt(counter++);
|
|
58
|
-
if (value >= 55296 && value <= 56319 && counter < length) {
|
|
59
|
-
const extra = input.charCodeAt(counter++);
|
|
60
|
-
if ((extra & 64512) === 56320)
|
|
61
|
-
output.push(((value & 1023) << 10) + (extra & 1023) + 65536);
|
|
62
|
-
else {
|
|
63
|
-
output.push(value);
|
|
64
|
-
counter--;
|
|
65
|
-
}
|
|
66
|
-
} else output.push(value);
|
|
67
|
-
}
|
|
68
|
-
return output;
|
|
69
|
-
}
|
|
70
|
-
var ucs2encode = (points) => String.fromCodePoint(...points);
|
|
71
|
-
function basicToDigit(codePoint) {
|
|
72
|
-
if (codePoint >= 48 && codePoint < 58) return 26 + (codePoint - 48);
|
|
73
|
-
if (codePoint >= 65 && codePoint < 91) return codePoint - 65;
|
|
74
|
-
if (codePoint >= 97 && codePoint < 123) return codePoint - 97;
|
|
75
|
-
return base;
|
|
76
|
-
}
|
|
77
|
-
function digitToBasic(digit, flag) {
|
|
78
|
-
return digit + 22 + 75 * (digit < 26 ? 1 : 0) - Number(flag !== 0) * 32;
|
|
79
|
-
}
|
|
80
|
-
function adapt(delta, numPoints, firstTime) {
|
|
81
|
-
let k = 0;
|
|
82
|
-
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
|
83
|
-
delta += floor(delta / numPoints);
|
|
84
|
-
while (delta > (base - tMin) * tMax >> 1) {
|
|
85
|
-
delta = floor(delta / (base - tMin));
|
|
86
|
-
k += base;
|
|
87
|
-
}
|
|
88
|
-
return floor(k + (base - tMin + 1) * delta / (delta + skew));
|
|
89
|
-
}
|
|
90
|
-
function decode(input) {
|
|
91
|
-
const output = [];
|
|
92
|
-
const inputLength = input.length;
|
|
93
|
-
let i = 0, n = initialN, bias = initialBias;
|
|
94
|
-
let basic = input.lastIndexOf(delimiter);
|
|
95
|
-
if (basic < 0) basic = 0;
|
|
96
|
-
for (let j = 0; j < basic; j++) {
|
|
97
|
-
if (input.charCodeAt(j) >= 128) error("not-basic");
|
|
98
|
-
output.push(input.charCodeAt(j));
|
|
99
|
-
}
|
|
100
|
-
for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; ) {
|
|
101
|
-
const oldi = i;
|
|
102
|
-
let w = 1;
|
|
103
|
-
for (let k = base; ; k += base) {
|
|
104
|
-
if (index >= inputLength) error("invalid-input");
|
|
105
|
-
const digit = basicToDigit(input.charCodeAt(index++));
|
|
106
|
-
if (digit >= base) error("invalid-input");
|
|
107
|
-
if (digit > floor((maxInt - i) / w)) error("overflow");
|
|
108
|
-
i += digit * w;
|
|
109
|
-
const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
|
|
110
|
-
if (digit < t) break;
|
|
111
|
-
const baseMinusT = base - t;
|
|
112
|
-
if (w > floor(maxInt / baseMinusT)) error("overflow");
|
|
113
|
-
w *= baseMinusT;
|
|
114
|
-
}
|
|
115
|
-
const out = output.length + 1;
|
|
116
|
-
bias = adapt(i - oldi, out, oldi === 0);
|
|
117
|
-
if (floor(i / out) > maxInt - n) error("overflow");
|
|
118
|
-
n += floor(i / out);
|
|
119
|
-
i %= out;
|
|
120
|
-
output.splice(i++, 0, n);
|
|
121
|
-
}
|
|
122
|
-
return String.fromCodePoint(...output);
|
|
123
|
-
}
|
|
124
|
-
function encode(input) {
|
|
125
|
-
const output = [];
|
|
126
|
-
const points = ucs2decode(input);
|
|
127
|
-
const inputLength = points.length;
|
|
128
|
-
let n = initialN, delta = 0, bias = initialBias;
|
|
129
|
-
for (const cp of points) if (cp < 128) output.push(stringFromCharCode(cp));
|
|
130
|
-
const basicLength = output.length;
|
|
131
|
-
let handledCPCount = basicLength;
|
|
132
|
-
if (basicLength) output.push(delimiter);
|
|
133
|
-
while (handledCPCount < inputLength) {
|
|
134
|
-
let m = maxInt;
|
|
135
|
-
for (const cp of points) if (cp >= n && cp < m) m = cp;
|
|
136
|
-
const handledCPCountPlusOne = handledCPCount + 1;
|
|
137
|
-
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) error("overflow");
|
|
138
|
-
delta += (m - n) * handledCPCountPlusOne;
|
|
139
|
-
n = m;
|
|
140
|
-
for (const cp of points) {
|
|
141
|
-
if (cp < n) delta++;
|
|
142
|
-
if (cp === n) {
|
|
143
|
-
let q = delta;
|
|
144
|
-
for (let k = base; ; k += base) {
|
|
145
|
-
const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
|
|
146
|
-
if (q < t) break;
|
|
147
|
-
output.push(stringFromCharCode(digitToBasic(t + (q - t) % (base - t), 0)));
|
|
148
|
-
q = floor((q - t) / (base - t));
|
|
149
|
-
}
|
|
150
|
-
output.push(stringFromCharCode(digitToBasic(q, 0)));
|
|
151
|
-
bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
|
|
152
|
-
delta = 0;
|
|
153
|
-
handledCPCount++;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
delta++;
|
|
157
|
-
n++;
|
|
158
|
-
}
|
|
159
|
-
return output.join("");
|
|
160
|
-
}
|
|
161
|
-
function toUnicode(input) {
|
|
162
|
-
return mapDomain(
|
|
163
|
-
input,
|
|
164
|
-
(str) => regexPunycode.test(str) ? decode(str.slice(4).toLowerCase()) : str
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
function toASCII(input) {
|
|
168
|
-
return mapDomain(
|
|
169
|
-
input,
|
|
170
|
-
(str) => regexNonASCII.test(str) ? "xn--" + encode(str) : str
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
var punycodeUtilsJS = {
|
|
174
|
-
version: "1.0.0",
|
|
175
|
-
ucs2: {
|
|
176
|
-
decode: ucs2decode,
|
|
177
|
-
encode: ucs2encode
|
|
178
|
-
},
|
|
179
|
-
decode,
|
|
180
|
-
encode,
|
|
181
|
-
toASCII,
|
|
182
|
-
toUnicode
|
|
183
|
-
};
|
|
10
|
+
import { punycodeUtilsJS } from './chunk-GKDSBOYE.js';
|
|
11
|
+
import { safeStableStringify } from './chunk-X6ULJZ3X.js';
|
|
12
|
+
import { isString, assertIsPlainObject, isBoolean, getPreciseType } from './chunk-J4TT33ZX.js';
|
|
184
13
|
|
|
185
14
|
var sldMap_default = {
|
|
186
15
|
"com.ac": true,
|
|
@@ -1991,4 +1820,4 @@ ${msg}`
|
|
|
1991
1820
|
});
|
|
1992
1821
|
}
|
|
1993
1822
|
|
|
1994
|
-
export { isValidDomain
|
|
1823
|
+
export { isValidDomain };
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
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 { isEmptyString } from './chunk-
|
|
11
|
-
import { isEmptyArray, isEmptyObject } from './chunk-
|
|
12
|
-
import { assertIsPlainObject, hasOwnProp, assertIsBoolean, isNil, isNaN, isString, isArray, isObject } from './chunk-
|
|
10
|
+
import { isEmptyString } from './chunk-5O66AUEC.js';
|
|
11
|
+
import { isEmptyArray, isEmptyObject } from './chunk-M5QB2GM5.js';
|
|
12
|
+
import { assertIsPlainObject, hasOwnProp, assertIsBoolean, isNil, isNaN, isString, isArray, isObject } from './chunk-J4TT33ZX.js';
|
|
13
13
|
|
|
14
14
|
var isEmptyValue = (value, options = {}) => {
|
|
15
15
|
assertIsPlainObject(options, {
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
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 { isNonEmptyString, isPlainObject } from './chunk-
|
|
10
|
+
import { isNonEmptyString, isPlainObject } from './chunk-J4TT33ZX.js';
|
|
11
11
|
|
|
12
12
|
var removeSpaces = (value, options = {
|
|
13
13
|
trimOnly: false
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
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 { isNonEmptyString } from './chunk-
|
|
10
|
+
import { isNonEmptyString } from './chunk-J4TT33ZX.js';
|
|
11
11
|
|
|
12
12
|
var isEmptyString = (value, options = {}) => {
|
|
13
13
|
return !isNonEmptyString(value, options);
|
|
@@ -0,0 +1,302 @@
|
|
|
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
|
+
import { isInteger } from './chunk-WVSPXFTY.js';
|
|
11
|
+
import { safeStableStringify } from './chunk-X6ULJZ3X.js';
|
|
12
|
+
import { isNonEmptyArray, getPreciseType, isNumber, isPlainObject, assertIsBoolean, isNaN, isNonEmptyString, isBoolean } from './chunk-J4TT33ZX.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 };
|