@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-HYRQMTRH.cjs
CHANGED
|
@@ -1 +1,24 @@
|
|
|
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 assertIsString = (value, options = {}) => {
|
|
15
|
+
if (chunkPZQ6I4JJ_cjs.isString(value)) return;
|
|
16
|
+
const errorMessage = chunkPZQ6I4JJ_cjs.resolveErrorMessageAssertions({
|
|
17
|
+
value,
|
|
18
|
+
options,
|
|
19
|
+
requiredValidType: "string"
|
|
20
|
+
});
|
|
21
|
+
throw new TypeError(errorMessage);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.assertIsString = assertIsString;
|
package/dist/chunk-IRFL4MAX.js
CHANGED
|
@@ -1 +1,63 @@
|
|
|
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 { isNonEmptyString } from './chunk-CMW2TBOQ.js';
|
|
11
|
+
|
|
12
|
+
var parseCurrencyString = (input) => {
|
|
13
|
+
if (!isNonEmptyString(input)) return 0;
|
|
14
|
+
let trimmed = input.trim().replace(/\u00A0/g, "").replace(/\u202F/g, "");
|
|
15
|
+
let isNegative = false;
|
|
16
|
+
if (/^\(.*\)$/.test(trimmed)) {
|
|
17
|
+
isNegative = true;
|
|
18
|
+
trimmed = trimmed.slice(1, -1).trim();
|
|
19
|
+
}
|
|
20
|
+
trimmed = trimmed.replace(/^[-\s]+/, (match) => match.includes("-") ? "-" : "").replace(/[\s.,-]+$/, "");
|
|
21
|
+
isNegative = isNegative || /^-/.test(trimmed) || /^[^\d]*-/.test(trimmed);
|
|
22
|
+
const cleaned = trimmed.replace(/[^0-9.,'\s]/g, "");
|
|
23
|
+
let cleanedNoSpace = cleaned.replace(/[\s']/g, "");
|
|
24
|
+
const indianMatches = cleanedNoSpace.match(/,\d{2}/g);
|
|
25
|
+
const isIndianStyle = indianMatches && indianMatches.length > 1;
|
|
26
|
+
if (isIndianStyle) {
|
|
27
|
+
cleanedNoSpace = cleanedNoSpace.replace(/,/g, "");
|
|
28
|
+
} else {
|
|
29
|
+
const dotCount = (cleanedNoSpace.match(/\./g) || []).length;
|
|
30
|
+
const commaCount = (cleanedNoSpace.match(/,/g) || []).length;
|
|
31
|
+
if (dotCount > 1 && commaCount === 0) {
|
|
32
|
+
cleanedNoSpace = cleanedNoSpace.replace(/\./g, "");
|
|
33
|
+
} else if (commaCount > 1 && dotCount === 0) {
|
|
34
|
+
cleanedNoSpace = cleanedNoSpace.replace(/,/g, "");
|
|
35
|
+
} else {
|
|
36
|
+
const lastComma = cleanedNoSpace.lastIndexOf(",");
|
|
37
|
+
const lastDot = cleanedNoSpace.lastIndexOf(".");
|
|
38
|
+
if (lastComma > lastDot) {
|
|
39
|
+
cleanedNoSpace = cleanedNoSpace.replace(/\./g, "").replace(",", ".");
|
|
40
|
+
} else if (lastDot > lastComma) {
|
|
41
|
+
cleanedNoSpace = cleanedNoSpace.replace(/,/g, "");
|
|
42
|
+
} else {
|
|
43
|
+
if (lastComma > lastDot) {
|
|
44
|
+
const beforeDecimal = cleanedNoSpace.slice(0, lastComma).replace(/,/g, "").replace(/\./g, "");
|
|
45
|
+
const afterDecimal = cleanedNoSpace.slice(lastComma + 1);
|
|
46
|
+
cleanedNoSpace = beforeDecimal + "." + afterDecimal;
|
|
47
|
+
} else if (lastDot > lastComma) {
|
|
48
|
+
const beforeDecimal = cleanedNoSpace.slice(0, lastDot).replace(/\./g, "").replace(/,/g, "");
|
|
49
|
+
const afterDecimal = cleanedNoSpace.slice(lastDot + 1);
|
|
50
|
+
cleanedNoSpace = beforeDecimal + "." + afterDecimal;
|
|
51
|
+
} else if (lastComma !== -1) {
|
|
52
|
+
cleanedNoSpace = cleanedNoSpace.replace(/,/g, "");
|
|
53
|
+
} else if (lastDot !== -1) {
|
|
54
|
+
cleanedNoSpace = cleanedNoSpace.replace(/\./g, "");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const num = parseFloat(cleanedNoSpace) || 0;
|
|
60
|
+
return isNegative ? -num : num;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { parseCurrencyString };
|
package/dist/chunk-IVL7CKVH.cjs
CHANGED
|
@@ -1 +1,37 @@
|
|
|
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 chunkUDA26MCU_cjs = require('./chunk-UDA26MCU.cjs');
|
|
13
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
14
|
+
|
|
15
|
+
var assertIsBigInt = (value, options = {}) => {
|
|
16
|
+
if (chunkUDA26MCU_cjs.isBigInt(value)) return;
|
|
17
|
+
const errorMessage = chunkPZQ6I4JJ_cjs.resolveErrorMessageAssertions({
|
|
18
|
+
value,
|
|
19
|
+
options,
|
|
20
|
+
requiredValidType: "big int"
|
|
21
|
+
});
|
|
22
|
+
throw new TypeError(errorMessage);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var assertIsNumber = (value, options = {}) => {
|
|
26
|
+
const includeNaN = chunkPZQ6I4JJ_cjs.hasOwnProp(options, "includeNaN") ? options.includeNaN : void 0;
|
|
27
|
+
if (chunkPZQ6I4JJ_cjs.isNumber(value, { includeNaN })) return;
|
|
28
|
+
const errorMessage = chunkPZQ6I4JJ_cjs.resolveErrorMessageAssertions({
|
|
29
|
+
value,
|
|
30
|
+
options,
|
|
31
|
+
requiredValidType: "number"
|
|
32
|
+
});
|
|
33
|
+
throw new TypeError(errorMessage);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.assertIsBigInt = assertIsBigInt;
|
|
37
|
+
exports.assertIsNumber = assertIsNumber;
|
package/dist/chunk-IZPBKKPO.js
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
|
+
import { isNonEmptyString } from './chunk-CMW2TBOQ.js';
|
|
11
|
+
|
|
12
|
+
var normalizeString = (input) => {
|
|
13
|
+
return isNonEmptyString(input) ? input.trim() : "";
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { normalizeString };
|
package/dist/chunk-JBQMXC5I.cjs
CHANGED
|
@@ -1 +1,106 @@
|
|
|
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 chunkT7PU2V7X_cjs = require('./chunk-T7PU2V7X.cjs');
|
|
13
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
14
|
+
|
|
15
|
+
var isRegExp = (value) => {
|
|
16
|
+
return value instanceof RegExp;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function isArrayBuffer(value) {
|
|
20
|
+
return value instanceof ArrayBuffer;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function baseDeepEqual(value, other, customizer, seen = /* @__PURE__ */ new WeakMap()) {
|
|
24
|
+
if (value === other) return true;
|
|
25
|
+
if (value !== value && other !== other) return true;
|
|
26
|
+
if (!chunkPZQ6I4JJ_cjs.isObjectOrArray(value) || !chunkPZQ6I4JJ_cjs.isObjectOrArray(other)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (seen.get(value) === other) return true;
|
|
30
|
+
seen.set(value, other);
|
|
31
|
+
const callCustomizer = (v, o, key, valObj, othObj) => {
|
|
32
|
+
if (customizer) {
|
|
33
|
+
const result = customizer(v, o, key, valObj, othObj, seen);
|
|
34
|
+
if (!chunkPZQ6I4JJ_cjs.isUndefined(result)) return result;
|
|
35
|
+
}
|
|
36
|
+
return baseDeepEqual(v, o, customizer, seen);
|
|
37
|
+
};
|
|
38
|
+
if (chunkT7PU2V7X_cjs.isDate(value) && chunkT7PU2V7X_cjs.isDate(other)) return value.getTime() === other.getTime();
|
|
39
|
+
if (isRegExp(value) && isRegExp(other))
|
|
40
|
+
return value.source === other.source && value.flags === other.flags;
|
|
41
|
+
if (chunkPZQ6I4JJ_cjs.isError(value) && chunkPZQ6I4JJ_cjs.isError(other))
|
|
42
|
+
return value.name === other.name && value.message === other.message;
|
|
43
|
+
if (ArrayBuffer.isView(value) && ArrayBuffer.isView(other)) {
|
|
44
|
+
const v = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
45
|
+
const o = new Uint8Array(other.buffer, other.byteOffset, other.byteLength);
|
|
46
|
+
if (v.length !== o.length) return false;
|
|
47
|
+
for (let i = 0; i < v.length; i++) if (v[i] !== o[i]) return false;
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (isArrayBuffer(value) && isArrayBuffer(other)) {
|
|
51
|
+
if (value.byteLength !== other.byteLength) return false;
|
|
52
|
+
const v = new Uint8Array(value), o = new Uint8Array(other);
|
|
53
|
+
for (let i = 0; i < v.length; i++) if (v[i] !== o[i]) return false;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (chunkT7PU2V7X_cjs.isMap(value) && chunkT7PU2V7X_cjs.isMap(other)) {
|
|
57
|
+
if (value.size !== other.size) return false;
|
|
58
|
+
for (const [k, v] of value) {
|
|
59
|
+
if (!other.has(k)) return false;
|
|
60
|
+
if (!baseDeepEqual(v, other.get(k), customizer, seen)) return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (chunkPZQ6I4JJ_cjs.isSet(value) && chunkPZQ6I4JJ_cjs.isSet(other)) {
|
|
65
|
+
if (value.size !== other.size) return false;
|
|
66
|
+
for (const v of value) {
|
|
67
|
+
let matched = false;
|
|
68
|
+
for (const o of other) {
|
|
69
|
+
if (baseDeepEqual(v, o, customizer, seen)) {
|
|
70
|
+
matched = true;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!matched) return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if (chunkPZQ6I4JJ_cjs.isArray(value) && chunkPZQ6I4JJ_cjs.isArray(other)) {
|
|
79
|
+
if (value.length !== other.length) return false;
|
|
80
|
+
for (let i = 0; i < value.length; i++) {
|
|
81
|
+
if (!callCustomizer(value[i], other[i], i, value, other)) return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
if (Object.getPrototypeOf(value) !== Object.getPrototypeOf(other)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const vKeys = Reflect.ownKeys(value);
|
|
89
|
+
const oKeys = Reflect.ownKeys(other);
|
|
90
|
+
if (vKeys.length !== oKeys.length) return false;
|
|
91
|
+
for (const key of vKeys) {
|
|
92
|
+
const vVal = value[key];
|
|
93
|
+
const oVal = other[key];
|
|
94
|
+
if (!callCustomizer(vVal, oVal, key, value, other)) return false;
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function isEqual(value, other) {
|
|
100
|
+
return baseDeepEqual(value, other, void 0, /* @__PURE__ */ new WeakMap());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
exports.baseDeepEqual = baseDeepEqual;
|
|
104
|
+
exports.isArrayBuffer = isArrayBuffer;
|
|
105
|
+
exports.isEqual = isEqual;
|
|
106
|
+
exports.isRegExp = isRegExp;
|
package/dist/chunk-JEQEF5WD.js
CHANGED
|
@@ -1 +1,95 @@
|
|
|
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 { isEmptyString } from './chunk-W2WNBUDE.js';
|
|
11
|
+
import { isNonEmptyString, isPlainObject, isString, isNumber, getPreciseType } from './chunk-CMW2TBOQ.js';
|
|
12
|
+
|
|
13
|
+
var capitalizeFirst = (string, options = {
|
|
14
|
+
lowerCaseNextRest: true,
|
|
15
|
+
trim: false
|
|
16
|
+
}) => {
|
|
17
|
+
if (!isNonEmptyString(string)) return "";
|
|
18
|
+
if (!isPlainObject(options)) {
|
|
19
|
+
options = {};
|
|
20
|
+
}
|
|
21
|
+
const lowerCaseNextRest = options.lowerCaseNextRest !== false;
|
|
22
|
+
const trim = options.trim === true;
|
|
23
|
+
if (trim) string = string.trim();
|
|
24
|
+
return string[0].toUpperCase() + (lowerCaseNextRest ? string.slice(1).toLowerCase() : string.slice(1));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var capitalizeWords = (value, options = {
|
|
28
|
+
collapseSpaces: false,
|
|
29
|
+
trim: false
|
|
30
|
+
}) => {
|
|
31
|
+
if (!isNonEmptyString(value)) return "";
|
|
32
|
+
let result = value;
|
|
33
|
+
if (!isPlainObject(options)) {
|
|
34
|
+
options = {};
|
|
35
|
+
}
|
|
36
|
+
const collapseSpaces = options.collapseSpaces === true;
|
|
37
|
+
const trim = options.trim === true;
|
|
38
|
+
if (trim) {
|
|
39
|
+
result = result.trim();
|
|
40
|
+
}
|
|
41
|
+
if (collapseSpaces) {
|
|
42
|
+
const leadingSpaces = result.match(/^\s*/)?.[0] ?? "";
|
|
43
|
+
const trailingSpaces = result.match(/\s*$/)?.[0] ?? "";
|
|
44
|
+
result = result.trim().replace(/\s+/g, " ");
|
|
45
|
+
result = `${leadingSpaces}${result}${trailingSpaces}`;
|
|
46
|
+
}
|
|
47
|
+
return result.toLowerCase().split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function stripHtmlTags(input) {
|
|
51
|
+
if (!isString(input)) {
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
if (isEmptyString(input)) {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
const stripped = input.replace(/<\/?[a-zA-Z][^<>]*\/?>/g, " ").trim();
|
|
58
|
+
const cleaned = stripped.replace(/\s+/g, " ").trim();
|
|
59
|
+
return cleaned;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var getInitialsName = (name) => {
|
|
63
|
+
if (!isNonEmptyString(name)) return "";
|
|
64
|
+
name = name.replace(/\s+/g, " ").trim();
|
|
65
|
+
const nameParts = name.split(" ");
|
|
66
|
+
if (nameParts.length > 1) {
|
|
67
|
+
return nameParts[0][0] + nameParts[1][0].toUpperCase();
|
|
68
|
+
}
|
|
69
|
+
return name.length > 1 ? name.substring(0, 2).toUpperCase() : (
|
|
70
|
+
// First two letters for single-word names
|
|
71
|
+
name[0].toUpperCase()
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
var replaceAt = (index, originalString, replaceTo) => {
|
|
76
|
+
if (!isNumber(index) || !isString(replaceTo) || !isString(originalString)) {
|
|
77
|
+
throw new TypeError(
|
|
78
|
+
`First parameter (\`index\`) must be of type \`number\`, second parameter (\`originalString\`) and third parameter (\`replaceTo\`) must be of type \`string\`, but received: "['index': \`${getPreciseType(
|
|
79
|
+
index
|
|
80
|
+
)}\`, 'originalString': \`${getPreciseType(
|
|
81
|
+
originalString
|
|
82
|
+
)}\`, 'replaceTo': \`${getPreciseType(replaceTo)}\`]".`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (index < 0 || index >= originalString.length) {
|
|
86
|
+
throw new RangeError(
|
|
87
|
+
`First parameter (\`index\`) is out of range from second parameter (\`originalString\`).`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return originalString.slice(0, index) + // Extract before the index
|
|
91
|
+
replaceTo + // Insert replacement
|
|
92
|
+
originalString.slice(index + 1);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export { capitalizeFirst, capitalizeWords, getInitialsName, replaceAt, stripHtmlTags };
|