@rzl-zone/utils-js 3.4.0 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +94 -45
- package/dist/assertions/index.cjs +41 -1
- package/dist/assertions/index.d.ts +11 -2
- package/dist/assertions/index.js +14 -1
- package/dist/chunk-2CQX5CBG.js +262 -1
- package/dist/chunk-2IOOEY45.cjs +30 -1
- package/dist/chunk-2WA36TC5.cjs +189 -0
- package/dist/chunk-3IBQ5MOM.js +16 -1
- package/dist/chunk-3VA554KW.js +34 -1
- package/dist/chunk-5757UBXJ.cjs +157 -1
- package/dist/chunk-5IGC6PBH.js +33 -1
- package/dist/chunk-5KJFVIQT.cjs +65 -1
- package/dist/chunk-6JFCSH7J.js +35 -1
- package/dist/chunk-6JFZL7YE.cjs +24 -1
- package/dist/chunk-7ODAAXX5.cjs +397 -1
- package/dist/chunk-BAV5T2E3.cjs +15 -1
- package/dist/chunk-CAH33WOQ.cjs +36 -1
- package/dist/chunk-CDCERIZ2.js +177 -0
- package/dist/chunk-CKTLUNWX.js +22 -1
- package/dist/chunk-CMW2TBOQ.js +567 -1
- package/dist/chunk-D3ENH7H6.cjs +101 -1
- package/dist/chunk-DEZZUYE2.js +152 -1
- package/dist/chunk-DVMHRLKP.cjs +16 -1
- package/dist/chunk-DWF2R5GD.cjs +225 -1
- package/dist/chunk-E55EQK2U.cjs +18 -1
- package/dist/chunk-E74U6CYP.cjs +18 -1
- package/dist/chunk-EL6A35UR.cjs +64 -1
- package/dist/chunk-F6IPNNSJ.cjs +554 -1
- package/dist/chunk-FJZGG54N.cjs +267 -1
- package/dist/chunk-FWCKOJZM.js +542 -1
- package/dist/chunk-FWHNWL2P.cjs +419 -1
- package/dist/chunk-GGEADHZO.js +90 -1
- package/dist/chunk-GQR4R5WY.js +31 -1
- package/dist/chunk-H66AC7GK.cjs +93 -1
- package/dist/chunk-HQWOFR56.cjs +33 -1
- package/dist/chunk-HYRQMTRH.cjs +24 -1
- package/dist/chunk-IRFL4MAX.js +63 -1
- package/dist/chunk-IVL7CKVH.cjs +37 -1
- package/dist/chunk-IZPBKKPO.js +16 -1
- package/dist/chunk-JBQMXC5I.cjs +106 -1
- package/dist/chunk-JEQEF5WD.js +95 -1
- package/dist/chunk-JMJQCN74.js +370 -1
- package/dist/chunk-KHO2SBNA.cjs +16 -1
- package/dist/chunk-KVAL5PAG.cjs +26 -1
- package/dist/chunk-L5RDAVVH.js +14 -1
- package/dist/chunk-LS6U7FAY.cjs +110 -1
- package/dist/chunk-NBZWMBO6.js +101 -1
- package/dist/chunk-NRF6LWBC.cjs +56 -1
- package/dist/chunk-OI5XKNZO.js +53 -1
- package/dist/chunk-ONZFBJVW.js +14 -1
- package/dist/chunk-OYTYSY7G.js +106 -1
- package/dist/chunk-PET42Z7W.js +119 -1
- package/dist/chunk-PZQ6I4JJ.cjs +605 -1
- package/dist/chunk-QBKAEVYG.js +113 -1
- package/dist/chunk-QNKGP5DY.js +14 -1
- package/dist/chunk-RIPKY4RU.js +417 -1
- package/dist/chunk-RZW35UN5.cjs +116 -1
- package/dist/chunk-SBFNXGTJ.js +220 -1
- package/dist/chunk-SBKGWRS5.js +22 -1
- package/dist/chunk-SIM77PU4.js +59 -1
- package/dist/chunk-T2T7K3KR.js +28 -1
- package/dist/chunk-T7PU2V7X.cjs +123 -1
- package/dist/chunk-UDA26MCU.cjs +16 -1
- package/dist/chunk-V45XJKHW.cjs +18 -1
- package/dist/chunk-VJDDGRIK.cjs +16 -1
- package/dist/chunk-W2WNBUDE.js +16 -1
- package/dist/chunk-WVSPXFTY.js +14 -1
- package/dist/chunk-XABCB3Y7.cjs +582 -1
- package/dist/chunk-XEDXFSGI.js +24 -1
- package/dist/chunk-YKPSRP5G.js +571 -1
- package/dist/chunk-YWHHVDT4.js +13 -1
- package/dist/chunk-ZETAZZLD.cjs +38 -1
- package/dist/conversions/index.cjs +104 -1
- package/dist/conversions/index.d.ts +10 -1
- package/dist/conversions/index.js +25 -1
- package/dist/events/index.cjs +32 -1
- package/dist/events/index.d.ts +10 -1
- package/dist/events/index.js +13 -1
- package/dist/formatters/index.cjs +62 -1
- package/dist/formatters/index.d.ts +10 -1
- package/dist/formatters/index.js +19 -1
- package/dist/generators/index.cjs +38 -1
- package/dist/generators/index.d.ts +10 -1
- package/dist/generators/index.js +15 -1
- package/dist/index.d.ts +39 -12
- package/dist/{isPlainObject-CEPWPiXh.d.ts → isPlainObject-FWmcJF6k.d.ts} +13 -4
- package/dist/next/index.cjs +218 -1
- package/dist/next/index.d.ts +10 -1
- package/dist/next/index.js +213 -1
- package/dist/next/server/index.cjs +43 -1
- package/dist/next/server/index.d.ts +10 -1
- package/dist/next/server/index.js +41 -1
- package/dist/operations/index.cjs +33 -1
- package/dist/operations/index.d.ts +10 -1
- package/dist/operations/index.js +18 -1
- package/dist/parsers/index.cjs +18 -1
- package/dist/parsers/index.d.ts +10 -1
- package/dist/parsers/index.js +11 -1
- package/dist/predicates/index.cjs +299 -1
- package/dist/predicates/index.d.ts +13 -4
- package/dist/predicates/index.js +24 -1
- package/dist/promises/index.cjs +25 -1
- package/dist/promises/index.d.ts +10 -1
- package/dist/promises/index.js +14 -1
- package/dist/rzl-utils.global.js +25 -1
- package/dist/strings/index.cjs +82 -1
- package/dist/strings/index.d.ts +10 -1
- package/dist/strings/index.js +15 -1
- package/dist/tailwind/index.cjs +43 -1
- package/dist/tailwind/index.d.ts +10 -1
- package/dist/tailwind/index.js +12 -1
- package/dist/urls/index.cjs +51 -1
- package/dist/urls/index.d.ts +10 -1
- package/dist/urls/index.js +24 -1
- package/package.json +60 -179
- package/dist/chunk-JYQTCICM.js +0 -1
- package/dist/chunk-YLA3DURS.cjs +0 -1
package/dist/chunk-D3ENH7H6.cjs
CHANGED
|
@@ -1 +1,101 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* ====================================================
|
|
3
|
+
* Rzl Utils-JS.
|
|
4
|
+
* ----------------------------------------------------
|
|
5
|
+
* Version: 3.5.1.
|
|
6
|
+
* Author: Rizalvin Dwiky.
|
|
7
|
+
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
|
+
* ====================================================
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var chunkE55EQK2U_cjs = require('./chunk-E55EQK2U.cjs');
|
|
13
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
14
|
+
|
|
15
|
+
var capitalizeFirst = (string, options = {
|
|
16
|
+
lowerCaseNextRest: true,
|
|
17
|
+
trim: false
|
|
18
|
+
}) => {
|
|
19
|
+
if (!chunkPZQ6I4JJ_cjs.isNonEmptyString(string)) return "";
|
|
20
|
+
if (!chunkPZQ6I4JJ_cjs.isPlainObject(options)) {
|
|
21
|
+
options = {};
|
|
22
|
+
}
|
|
23
|
+
const lowerCaseNextRest = options.lowerCaseNextRest !== false;
|
|
24
|
+
const trim = options.trim === true;
|
|
25
|
+
if (trim) string = string.trim();
|
|
26
|
+
return string[0].toUpperCase() + (lowerCaseNextRest ? string.slice(1).toLowerCase() : string.slice(1));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var capitalizeWords = (value, options = {
|
|
30
|
+
collapseSpaces: false,
|
|
31
|
+
trim: false
|
|
32
|
+
}) => {
|
|
33
|
+
if (!chunkPZQ6I4JJ_cjs.isNonEmptyString(value)) return "";
|
|
34
|
+
let result = value;
|
|
35
|
+
if (!chunkPZQ6I4JJ_cjs.isPlainObject(options)) {
|
|
36
|
+
options = {};
|
|
37
|
+
}
|
|
38
|
+
const collapseSpaces = options.collapseSpaces === true;
|
|
39
|
+
const trim = options.trim === true;
|
|
40
|
+
if (trim) {
|
|
41
|
+
result = result.trim();
|
|
42
|
+
}
|
|
43
|
+
if (collapseSpaces) {
|
|
44
|
+
const leadingSpaces = result.match(/^\s*/)?.[0] ?? "";
|
|
45
|
+
const trailingSpaces = result.match(/\s*$/)?.[0] ?? "";
|
|
46
|
+
result = result.trim().replace(/\s+/g, " ");
|
|
47
|
+
result = `${leadingSpaces}${result}${trailingSpaces}`;
|
|
48
|
+
}
|
|
49
|
+
return result.toLowerCase().split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function stripHtmlTags(input) {
|
|
53
|
+
if (!chunkPZQ6I4JJ_cjs.isString(input)) {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
if (chunkE55EQK2U_cjs.isEmptyString(input)) {
|
|
57
|
+
return "";
|
|
58
|
+
}
|
|
59
|
+
const stripped = input.replace(/<\/?[a-zA-Z][^<>]*\/?>/g, " ").trim();
|
|
60
|
+
const cleaned = stripped.replace(/\s+/g, " ").trim();
|
|
61
|
+
return cleaned;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var getInitialsName = (name) => {
|
|
65
|
+
if (!chunkPZQ6I4JJ_cjs.isNonEmptyString(name)) return "";
|
|
66
|
+
name = name.replace(/\s+/g, " ").trim();
|
|
67
|
+
const nameParts = name.split(" ");
|
|
68
|
+
if (nameParts.length > 1) {
|
|
69
|
+
return nameParts[0][0] + nameParts[1][0].toUpperCase();
|
|
70
|
+
}
|
|
71
|
+
return name.length > 1 ? name.substring(0, 2).toUpperCase() : (
|
|
72
|
+
// First two letters for single-word names
|
|
73
|
+
name[0].toUpperCase()
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
var replaceAt = (index, originalString, replaceTo) => {
|
|
78
|
+
if (!chunkPZQ6I4JJ_cjs.isNumber(index) || !chunkPZQ6I4JJ_cjs.isString(replaceTo) || !chunkPZQ6I4JJ_cjs.isString(originalString)) {
|
|
79
|
+
throw new TypeError(
|
|
80
|
+
`First parameter (\`index\`) must be of type \`number\`, second parameter (\`originalString\`) and third parameter (\`replaceTo\`) must be of type \`string\`, but received: "['index': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
81
|
+
index
|
|
82
|
+
)}\`, 'originalString': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
83
|
+
originalString
|
|
84
|
+
)}\`, 'replaceTo': \`${chunkPZQ6I4JJ_cjs.getPreciseType(replaceTo)}\`]".`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (index < 0 || index >= originalString.length) {
|
|
88
|
+
throw new RangeError(
|
|
89
|
+
`First parameter (\`index\`) is out of range from second parameter (\`originalString\`).`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return originalString.slice(0, index) + // Extract before the index
|
|
93
|
+
replaceTo + // Insert replacement
|
|
94
|
+
originalString.slice(index + 1);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
exports.capitalizeFirst = capitalizeFirst;
|
|
98
|
+
exports.capitalizeWords = capitalizeWords;
|
|
99
|
+
exports.getInitialsName = getInitialsName;
|
|
100
|
+
exports.replaceAt = replaceAt;
|
|
101
|
+
exports.stripHtmlTags = stripHtmlTags;
|
package/dist/chunk-DEZZUYE2.js
CHANGED
|
@@ -1 +1,152 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* ====================================================
|
|
3
|
+
* Rzl Utils-JS.
|
|
4
|
+
* ----------------------------------------------------
|
|
5
|
+
* Version: 3.5.1.
|
|
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-PET42Z7W.js';
|
|
12
|
+
import { isNonEmptyArray, getPreciseType, isNumber, isPlainObject, assertIsBoolean, isNaN } from './chunk-CMW2TBOQ.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)})\`, 'max': \`${getPreciseType(
|
|
29
|
+
max
|
|
30
|
+
)}\` - (with value: \`${safeStableStringify(max)}\`)].`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (min > max) {
|
|
34
|
+
throw new RangeError(
|
|
35
|
+
`First parameter (\`min\`) must be less than or equal to second parameter (\`max\`), but received: ['min': ${formatValue(
|
|
36
|
+
min
|
|
37
|
+
)}, 'max': ${formatValue(max)}].`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
min = Math.max(1, min);
|
|
41
|
+
max = Math.min(Number.MAX_SAFE_INTEGER, max);
|
|
42
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
43
|
+
};
|
|
44
|
+
var formatValue = (value) => {
|
|
45
|
+
return isNumber(value, { includeNaN: true }) ? value === Number.MIN_VALUE ? "`Number.MIN_VALUE`" : `${value}` : `\`${getPreciseType(value)}\``;
|
|
46
|
+
};
|
|
47
|
+
var minValueNote = (...values) => {
|
|
48
|
+
return values.some((v) => isNumber(v, { includeNaN: true }) && v === Number.MIN_VALUE) ? " and can't be `Number.MIN_VALUE` " : " ";
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
var randomIntByLength = (options) => {
|
|
52
|
+
if (!isPlainObject(options)) {
|
|
53
|
+
options = {};
|
|
54
|
+
}
|
|
55
|
+
const { minLength = 1, maxLength = 16, avoidZero = false } = options;
|
|
56
|
+
assertIsBoolean(avoidZero, {
|
|
57
|
+
message({ currentType, validType }) {
|
|
58
|
+
return `Parameters \`avoidZero\` must be of type \`${validType}\`, but received: \`${currentType}\`.`;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (!isInteger(minLength) || !isInteger(maxLength)) {
|
|
62
|
+
throw new TypeError(
|
|
63
|
+
`Parameters \`minLength\` and \`maxLength\` must be of type \`integer-number\`, but received: ['minLength': \`${getPreciseType(
|
|
64
|
+
minLength
|
|
65
|
+
)}\` - (with value: ${safeStableStringify(
|
|
66
|
+
minLength
|
|
67
|
+
)}), 'maxLength': \`${getPreciseType(
|
|
68
|
+
maxLength
|
|
69
|
+
)}\` - (with value: ${safeStableStringify(maxLength)})].`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
if (minLength < 1 || maxLength > 16 || minLength > maxLength) {
|
|
73
|
+
throw new RangeError(
|
|
74
|
+
`Invalid range at parameters \`minLength\` must be \u2265 1, \`maxLength\` must be \u2264 16, and \`minLength\` \u2264 \`maxLength\`, but received: ['minLength': \`${minLength}\`, 'maxLength': \`${maxLength}\`].`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const randomLength = minLength === maxLength ? minLength : randomInt(minLength, maxLength);
|
|
78
|
+
const minValue = 10 ** (randomLength - 1);
|
|
79
|
+
const maxValue = 10 ** randomLength - 1;
|
|
80
|
+
let result = randomInt(minValue, maxValue);
|
|
81
|
+
if (avoidZero && result === 0) {
|
|
82
|
+
result = minValue;
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
var randomStr = (options) => {
|
|
88
|
+
if (!isPlainObject(options)) {
|
|
89
|
+
options = {};
|
|
90
|
+
}
|
|
91
|
+
const {
|
|
92
|
+
minLength = 40,
|
|
93
|
+
maxLength = 40,
|
|
94
|
+
type = "string",
|
|
95
|
+
avoidWhiteSpace = true
|
|
96
|
+
} = options;
|
|
97
|
+
assertIsBoolean(avoidWhiteSpace, {
|
|
98
|
+
message({ currentType, validType }) {
|
|
99
|
+
return `Parameters \`avoidWhiteSpace\` property of the \`options\` (first-parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
if (!isInteger(minLength) || !isInteger(maxLength)) {
|
|
103
|
+
throw new TypeError(
|
|
104
|
+
`Parameters \`minLength\` and \`maxLength\` must be of type \`integer-number\`, but received: ['minLength': \`${getPreciseType(
|
|
105
|
+
minLength
|
|
106
|
+
)}\` - (with value: ${safeStableStringify(
|
|
107
|
+
minLength
|
|
108
|
+
)}), 'maxLength': \`${getPreciseType(
|
|
109
|
+
maxLength
|
|
110
|
+
)}\` - (with value: ${safeStableStringify(maxLength)})].`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (minLength < 1 || maxLength > 5e3 || minLength > maxLength) {
|
|
114
|
+
throw new RangeError(
|
|
115
|
+
`Invalid range at parameters \`minLength\` must be \u2265 1, \`maxLength\` must be \u2264 5000, and \`minLength\` \u2264 \`maxLength\`, but received: ['minLength': \`${minLength}\`, 'maxLength': \`${maxLength}\`].`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
if (type !== "string" && type !== "number") {
|
|
119
|
+
throw new TypeError(
|
|
120
|
+
`Parameter \`type\` must be of type \`string\` with value one of "string" | "number", but received: \`${getPreciseType(
|
|
121
|
+
type
|
|
122
|
+
)}\`, with value: ${safeStableStringify(type)}.`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
const length = randomInt(minLength, maxLength);
|
|
126
|
+
const cleanCharacters = (charSet) => {
|
|
127
|
+
return avoidWhiteSpace ? charSet.replace(/\s|\n|\t/g, "") : charSet;
|
|
128
|
+
};
|
|
129
|
+
const defaultNumberSet = "0123456789";
|
|
130
|
+
const defaultStringSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
131
|
+
const baseCharSet = type === "number" ? (!isNaN(Number(options.replaceGenInt)) ? options.replaceGenInt : void 0) ?? defaultNumberSet : (options.replaceGenStr ? options.replaceGenStr : void 0) ?? defaultStringSet;
|
|
132
|
+
const characterSet = cleanCharacters(baseCharSet) + (options.addChar || "");
|
|
133
|
+
if (!characterSet.length) {
|
|
134
|
+
const errCharSet = () => {
|
|
135
|
+
if (type === "number") {
|
|
136
|
+
if (avoidWhiteSpace) {
|
|
137
|
+
return `If \`avoidWhiteSpace\` is true, and \`replaceGenInt\` cant be empty-string value, ensure \`replaceGenInt\` has valid characters and non-nan string number.`;
|
|
138
|
+
}
|
|
139
|
+
return `Ensure \`replaceGenInt\` has valid characters and not a NaN number string while convert to number.`;
|
|
140
|
+
}
|
|
141
|
+
return `Ensure \`replaceGenStr\` has valid characters and non empty string.`;
|
|
142
|
+
};
|
|
143
|
+
throw new Error(`Character set is empty. ${errCharSet()}`);
|
|
144
|
+
}
|
|
145
|
+
let result = "";
|
|
146
|
+
for (let i = 0; i < length; i++) {
|
|
147
|
+
result += characterSet.charAt(Math.floor(Math.random() * characterSet.length));
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export { getRandomItem, randomInt, randomIntByLength, randomStr };
|
package/dist/chunk-DVMHRLKP.cjs
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* ====================================================
|
|
3
|
+
* Rzl Utils-JS.
|
|
4
|
+
* ----------------------------------------------------
|
|
5
|
+
* Version: 3.5.1.
|
|
6
|
+
* Author: Rizalvin Dwiky.
|
|
7
|
+
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
|
+
* ====================================================
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
function isInteger(value) {
|
|
13
|
+
return typeof value === "number" && Number.isInteger(value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.isInteger = isInteger;
|
package/dist/chunk-DWF2R5GD.cjs
CHANGED
|
@@ -1 +1,225 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* ====================================================
|
|
3
|
+
* Rzl Utils-JS.
|
|
4
|
+
* ----------------------------------------------------
|
|
5
|
+
* Version: 3.5.1.
|
|
6
|
+
* Author: Rizalvin Dwiky.
|
|
7
|
+
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
|
+
* ====================================================
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var chunkKHO2SBNA_cjs = require('./chunk-KHO2SBNA.cjs');
|
|
13
|
+
var chunkE74U6CYP_cjs = require('./chunk-E74U6CYP.cjs');
|
|
14
|
+
var chunkNRF6LWBC_cjs = require('./chunk-NRF6LWBC.cjs');
|
|
15
|
+
var chunkHQWOFR56_cjs = require('./chunk-HQWOFR56.cjs');
|
|
16
|
+
var chunkDVMHRLKP_cjs = require('./chunk-DVMHRLKP.cjs');
|
|
17
|
+
var chunkH66AC7GK_cjs = require('./chunk-H66AC7GK.cjs');
|
|
18
|
+
var chunkE55EQK2U_cjs = require('./chunk-E55EQK2U.cjs');
|
|
19
|
+
var chunk6JFZL7YE_cjs = require('./chunk-6JFZL7YE.cjs');
|
|
20
|
+
var chunkT7PU2V7X_cjs = require('./chunk-T7PU2V7X.cjs');
|
|
21
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
22
|
+
|
|
23
|
+
var constructURL = (baseUrl, queryParams, removeParams) => {
|
|
24
|
+
if (chunkPZQ6I4JJ_cjs.isString(baseUrl)) {
|
|
25
|
+
if (chunkE55EQK2U_cjs.isEmptyString(baseUrl)) {
|
|
26
|
+
throw new TypeError(`First parameter (\`baseUrl\`) cannot be an empty-string.`);
|
|
27
|
+
}
|
|
28
|
+
baseUrl = chunkE74U6CYP_cjs.normalizeString(baseUrl);
|
|
29
|
+
} else if (!chunkKHO2SBNA_cjs.isURL(baseUrl)) {
|
|
30
|
+
throw new TypeError(
|
|
31
|
+
`First parameter (\`baseUrl\`) must be of type an URL instance or a \`string\` and a non empty-string, but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
32
|
+
baseUrl
|
|
33
|
+
)}\`, with current value: \`${chunkT7PU2V7X_cjs.safeStableStringify(baseUrl)}\`.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (!chunkPZQ6I4JJ_cjs.isUndefined(removeParams)) {
|
|
37
|
+
chunk6JFZL7YE_cjs.assertIsArray(removeParams, {
|
|
38
|
+
message: ({ currentType, validType }) => `Third parameter (\`removeParams\`) must be of type \`${validType} of strings\`, but received: \`${currentType}\`.`
|
|
39
|
+
});
|
|
40
|
+
if (!removeParams.every((param) => chunkPZQ6I4JJ_cjs.isNonEmptyString(param))) {
|
|
41
|
+
throw new TypeError(
|
|
42
|
+
`Third parameter (\`removeParams\`) must be of type \`array\` and contains \`string\` only and non empty-string.`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
if (!chunkPZQ6I4JJ_cjs.isUndefined(queryParams) && !chunkPZQ6I4JJ_cjs.isFunction(queryParams[Symbol.iterator])) {
|
|
48
|
+
throw new TypeError(
|
|
49
|
+
`Second parameter (\`queryParams\`) must be iterable (like URLSearchParams.entries() or an array of [[string, string | number]...]), but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
50
|
+
queryParams
|
|
51
|
+
)}\`, with value: \`${chunkT7PU2V7X_cjs.safeStableStringify(queryParams)}\`.`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const urlInstance = new URL(baseUrl);
|
|
55
|
+
if (!chunkPZQ6I4JJ_cjs.isUndefined(queryParams)) {
|
|
56
|
+
const paramObject = Object.fromEntries(queryParams);
|
|
57
|
+
if (!chunkHQWOFR56_cjs.isEmptyValue(paramObject)) {
|
|
58
|
+
const mergedParams = new URLSearchParams(urlInstance.search);
|
|
59
|
+
for (const [key, value] of Object.entries(paramObject)) {
|
|
60
|
+
if (!chunkPZQ6I4JJ_cjs.isNonEmptyString(value) && !chunkPZQ6I4JJ_cjs.isNumber(value, { includeNaN: true })) {
|
|
61
|
+
throw new TypeError(
|
|
62
|
+
`Second parameter (\`queryParams\`) must be iterable (like URLSearchParams.entries() or an array of [[string, string | number]...]), but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
63
|
+
queryParams
|
|
64
|
+
)}\`, with value: \`${chunkT7PU2V7X_cjs.safeStableStringify(queryParams)}\`.`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
mergedParams.set(key, String(value));
|
|
68
|
+
}
|
|
69
|
+
if (removeParams?.length) {
|
|
70
|
+
chunkNRF6LWBC_cjs.toStringArrayUnRecursive(removeParams).map((paramKey) => {
|
|
71
|
+
mergedParams.delete(paramKey);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
urlInstance.search = mergedParams.toString();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
removeParams?.forEach((param) => urlInstance.searchParams.delete(param));
|
|
78
|
+
return urlInstance;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (chunkPZQ6I4JJ_cjs.isError(error)) throw error;
|
|
81
|
+
throw new Error(
|
|
82
|
+
"Failed to construct a valid URL in `constructURL()`, Error:" + error
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
var extractURLs = (url) => {
|
|
88
|
+
if (!chunkPZQ6I4JJ_cjs.isNonEmptyString(url)) return null;
|
|
89
|
+
let decoded;
|
|
90
|
+
try {
|
|
91
|
+
decoded = decodeURIComponent(url);
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
const urlPattern = /https?:\/\/.*?(?=https?:\/\/|\s|$)/g;
|
|
96
|
+
const matches = decoded.match(urlPattern);
|
|
97
|
+
if (!matches) return null;
|
|
98
|
+
const cleaned = matches.map((url2) => url2.replace(/[.,;:!?)]*$/, "")).filter((url2) => {
|
|
99
|
+
try {
|
|
100
|
+
const u = new URL(url2);
|
|
101
|
+
return u.protocol === "http:" || u.protocol === "https:";
|
|
102
|
+
} catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return cleaned.length ? cleaned : null;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
var getFirstPrefixPathname = (result, defaultValue = "/") => {
|
|
110
|
+
if (!chunkPZQ6I4JJ_cjs.isNonEmptyString(defaultValue)) {
|
|
111
|
+
throw new TypeError(
|
|
112
|
+
`Second parameter (\`defaultValue\`) must be of type \`string\` and not an \`empty-string\`, but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
113
|
+
defaultValue
|
|
114
|
+
)}\`, with value: \`${chunkT7PU2V7X_cjs.safeStableStringify(defaultValue)}\`.`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
if (chunkPZQ6I4JJ_cjs.isArray(result)) {
|
|
118
|
+
if (!result.every((item) => chunkPZQ6I4JJ_cjs.isString(item))) {
|
|
119
|
+
throw new TypeError(
|
|
120
|
+
`First parameter (\`result\`) must be of type \`string\` or \`array of string\`, but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
121
|
+
result
|
|
122
|
+
)}\`, with value: \`${chunkT7PU2V7X_cjs.safeStableStringify(result)}\`.`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
for (const item of result) {
|
|
126
|
+
const normalized = chunkH66AC7GK_cjs.normalizePathname(item);
|
|
127
|
+
if (normalized !== "/") {
|
|
128
|
+
return normalized;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return chunkH66AC7GK_cjs.normalizePathname(defaultValue);
|
|
132
|
+
}
|
|
133
|
+
if (chunkPZQ6I4JJ_cjs.isString(result)) {
|
|
134
|
+
const normalized = chunkH66AC7GK_cjs.normalizePathname(result);
|
|
135
|
+
return normalized !== "/" ? normalized : chunkH66AC7GK_cjs.normalizePathname(defaultValue);
|
|
136
|
+
}
|
|
137
|
+
if (!chunkPZQ6I4JJ_cjs.isNil(result)) {
|
|
138
|
+
throw new TypeError(
|
|
139
|
+
`First parameter (\`result\`) must be of type \`string\`, \`array-string\`, \`null\` or \`undefined\`, but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
140
|
+
result
|
|
141
|
+
)}\`.`
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
return chunkH66AC7GK_cjs.normalizePathname(defaultValue);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
var getPrefixPathname = (url, base = null, options = {}) => {
|
|
148
|
+
const errors = [];
|
|
149
|
+
if (!chunkPZQ6I4JJ_cjs.isString(url) && !chunkPZQ6I4JJ_cjs.isArray(url)) {
|
|
150
|
+
errors.push(
|
|
151
|
+
`First parameter (\`url\`) must be of type \`string\` or \`array-string\`, but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
152
|
+
url
|
|
153
|
+
)}\`.`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (!chunkPZQ6I4JJ_cjs.isString(base) && !chunkPZQ6I4JJ_cjs.isArray(base) && !chunkPZQ6I4JJ_cjs.isNull(base)) {
|
|
157
|
+
errors.push(
|
|
158
|
+
`Second parameter (\`base\`) must be of type \`string\`, \`array-string\` or \`null\`, but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
159
|
+
base
|
|
160
|
+
)}\`.`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
if (!chunkPZQ6I4JJ_cjs.isPlainObject(options)) {
|
|
164
|
+
errors.push(
|
|
165
|
+
`Second parameter (\`options\`) must be of type \`plain-object\`, but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
166
|
+
options
|
|
167
|
+
)}\`.`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
const { levels = 1, removeDuplicates = true } = options;
|
|
171
|
+
if (!chunkDVMHRLKP_cjs.isInteger(levels) || chunkDVMHRLKP_cjs.isInteger(levels) && levels < 0) {
|
|
172
|
+
errors.push(
|
|
173
|
+
`Parameter \`levels\` property of the \`options\` (second parameter) must be of type \`integer-number\` and minimum is \`0\`, but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
174
|
+
levels
|
|
175
|
+
)}\`, with value: \`${chunkT7PU2V7X_cjs.safeStableStringify(levels)}\`.`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if (!chunkPZQ6I4JJ_cjs.isBoolean(removeDuplicates)) {
|
|
179
|
+
errors.push(
|
|
180
|
+
`Parameter \`removeDuplicates\` property of the \`options\` (second parameter) must be of type \`boolean\`, but received: \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
181
|
+
removeDuplicates
|
|
182
|
+
)}\`.`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (chunkPZQ6I4JJ_cjs.isNonEmptyArray(errors)) {
|
|
186
|
+
throw new TypeError(
|
|
187
|
+
`Invalid parameter(s) in \`getPrefixPathname\` function:
|
|
188
|
+
- ${errors.join("\n- ")}`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
function getLevel(singleUrl) {
|
|
192
|
+
const parts = chunkH66AC7GK_cjs.normalizePathname(singleUrl).split("/").filter(Boolean);
|
|
193
|
+
return `/${parts.slice(0, levels).join("/")}`;
|
|
194
|
+
}
|
|
195
|
+
function processUrl(singleUrl) {
|
|
196
|
+
if (base) {
|
|
197
|
+
singleUrl = chunkH66AC7GK_cjs.normalizePathname(singleUrl);
|
|
198
|
+
if (chunkPZQ6I4JJ_cjs.isArray(base)) {
|
|
199
|
+
for (const b of base) {
|
|
200
|
+
if (singleUrl.startsWith(chunkH66AC7GK_cjs.normalizePathname(b))) {
|
|
201
|
+
return getLevel(singleUrl);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
} else if (chunkPZQ6I4JJ_cjs.isNonEmptyString(base) && singleUrl.startsWith(chunkH66AC7GK_cjs.normalizePathname(base))) {
|
|
205
|
+
return getLevel(singleUrl);
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
return getLevel(singleUrl);
|
|
210
|
+
}
|
|
211
|
+
if (chunkPZQ6I4JJ_cjs.isArray(url)) {
|
|
212
|
+
const result = url.map(processUrl).filter((r) => !chunkPZQ6I4JJ_cjs.isNull(r));
|
|
213
|
+
const uniqueResult = removeDuplicates ? [...new Set(result)] : result;
|
|
214
|
+
if (uniqueResult.length === 1) {
|
|
215
|
+
return uniqueResult[0];
|
|
216
|
+
}
|
|
217
|
+
return uniqueResult;
|
|
218
|
+
}
|
|
219
|
+
return processUrl(url);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
exports.constructURL = constructURL;
|
|
223
|
+
exports.extractURLs = extractURLs;
|
|
224
|
+
exports.getFirstPrefixPathname = getFirstPrefixPathname;
|
|
225
|
+
exports.getPrefixPathname = getPrefixPathname;
|
package/dist/chunk-E55EQK2U.cjs
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* ====================================================
|
|
3
|
+
* Rzl Utils-JS.
|
|
4
|
+
* ----------------------------------------------------
|
|
5
|
+
* Version: 3.5.1.
|
|
6
|
+
* Author: Rizalvin Dwiky.
|
|
7
|
+
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
|
+
* ====================================================
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
13
|
+
|
|
14
|
+
var isEmptyString = (value, options = {}) => {
|
|
15
|
+
return !chunkPZQ6I4JJ_cjs.isNonEmptyString(value, options);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.isEmptyString = isEmptyString;
|
package/dist/chunk-E74U6CYP.cjs
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* ====================================================
|
|
3
|
+
* Rzl Utils-JS.
|
|
4
|
+
* ----------------------------------------------------
|
|
5
|
+
* Version: 3.5.1.
|
|
6
|
+
* Author: Rizalvin Dwiky.
|
|
7
|
+
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
|
+
* ====================================================
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
13
|
+
|
|
14
|
+
var normalizeString = (input) => {
|
|
15
|
+
return chunkPZQ6I4JJ_cjs.isNonEmptyString(input) ? input.trim() : "";
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.normalizeString = normalizeString;
|
package/dist/chunk-EL6A35UR.cjs
CHANGED
|
@@ -1 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* ====================================================
|
|
3
|
+
* Rzl Utils-JS.
|
|
4
|
+
* ----------------------------------------------------
|
|
5
|
+
* Version: 3.5.1.
|
|
6
|
+
* Author: Rizalvin Dwiky.
|
|
7
|
+
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
|
+
* ====================================================
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var chunkVJDDGRIK_cjs = require('./chunk-VJDDGRIK.cjs');
|
|
13
|
+
var chunkHYRQMTRH_cjs = require('./chunk-HYRQMTRH.cjs');
|
|
14
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
15
|
+
|
|
16
|
+
var disableUserInteraction = (className = "on_processing") => {
|
|
17
|
+
if (chunkVJDDGRIK_cjs.isServer()) return;
|
|
18
|
+
chunkHYRQMTRH_cjs.assertIsString(className, {
|
|
19
|
+
message({ validType, currentType }) {
|
|
20
|
+
return `First parameter \`className\` must be of type \`${validType}\`, but received: \`${currentType}\`.`;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const { documentElement } = document;
|
|
24
|
+
if (documentElement && !documentElement.classList.contains(className)) {
|
|
25
|
+
documentElement.classList.add(className);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var enableUserInteraction = (className = "on_processing") => {
|
|
30
|
+
if (chunkVJDDGRIK_cjs.isServer()) return;
|
|
31
|
+
chunkHYRQMTRH_cjs.assertIsString(className, {
|
|
32
|
+
message({ validType, currentType }) {
|
|
33
|
+
return `First parameter \`className\` must be of type \`${validType}\`, but received: \`${currentType}\`.`;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const { documentElement } = document;
|
|
37
|
+
if (documentElement && documentElement.classList.contains(className)) {
|
|
38
|
+
documentElement.classList.remove(className);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var removeElementFocus = () => {
|
|
43
|
+
if (chunkVJDDGRIK_cjs.isServer()) return;
|
|
44
|
+
const activeElement = document.activeElement;
|
|
45
|
+
if (activeElement instanceof HTMLElement) {
|
|
46
|
+
activeElement.blur();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var scrollToTop = (options) => {
|
|
51
|
+
if (chunkVJDDGRIK_cjs.isServer()) return;
|
|
52
|
+
if (!chunkPZQ6I4JJ_cjs.isPlainObject(options)) {
|
|
53
|
+
options = {};
|
|
54
|
+
}
|
|
55
|
+
const behavior = chunkPZQ6I4JJ_cjs.hasOwnProp(options, "behavior") && chunkPZQ6I4JJ_cjs.isNonEmptyString(options.behavior) && ["auto", "instant", "smooth"].includes(options.behavior) ? options.behavior : "smooth";
|
|
56
|
+
let timeout = chunkPZQ6I4JJ_cjs.hasOwnProp(options, "timeout") && chunkPZQ6I4JJ_cjs.isNumber(options.timeout) && options.timeout >= 1 ? options.timeout : 1;
|
|
57
|
+
timeout = timeout > 2147483647 ? 2147483647 : timeout;
|
|
58
|
+
setTimeout(() => window.scrollTo({ top: 0, left: 0, behavior }), timeout);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
exports.disableUserInteraction = disableUserInteraction;
|
|
62
|
+
exports.enableUserInteraction = enableUserInteraction;
|
|
63
|
+
exports.removeElementFocus = removeElementFocus;
|
|
64
|
+
exports.scrollToTop = scrollToTop;
|