@rzl-zone/utils-js 3.12.0 β 3.12.1-beta.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 β LICENSE} +3 -3
- package/README.md +69 -96
- package/dist/.references/index.d.cts +25 -0
- package/dist/.references/index.d.ts +25 -0
- package/dist/assertIsArray-DJXkjHZs.cjs +26 -0
- package/dist/assertIsArray-DJXkjHZs.cjs.map +1 -0
- package/dist/assertIsArray-bTA3XLjq.js +20 -0
- package/dist/assertIsArray-bTA3XLjq.js.map +1 -0
- package/dist/assertIsBoolean-C8WEXVr2.cjs +1283 -0
- package/dist/assertIsBoolean-C8WEXVr2.cjs.map +1 -0
- package/dist/assertIsBoolean-DR1SaXPD.js +1073 -0
- package/dist/assertIsBoolean-DR1SaXPD.js.map +1 -0
- package/dist/assertIsString-BiHQSrB2.cjs +26 -0
- package/dist/assertIsString-BiHQSrB2.cjs.map +1 -0
- package/dist/assertIsString-CEB07_83.js +20 -0
- package/dist/assertIsString-CEB07_83.js.map +1 -0
- package/dist/assertions/index.cjs +37 -40
- package/dist/assertions/index.cjs.map +1 -0
- package/dist/assertions/index.d.cts +12 -0
- package/dist/assertions/index.d.ts +10 -824
- package/dist/assertions/index.js +30 -13
- package/dist/assertions/index.js.map +1 -0
- package/dist/conversions/index.cjs +34 -103
- package/dist/conversions/index.d.cts +12 -0
- package/dist/conversions/index.d.ts +10 -1791
- package/dist/conversions/index.js +14 -24
- package/dist/conversions-BNIh_tCH.js +380 -0
- package/dist/conversions-BNIh_tCH.js.map +1 -0
- package/dist/conversions-D_Kh0a_C.cjs +446 -0
- package/dist/conversions-D_Kh0a_C.cjs.map +1 -0
- package/dist/events/index.cjs +55 -31
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.d.cts +176 -0
- package/dist/events/index.d.ts +164 -166
- package/dist/events/index.js +50 -12
- package/dist/events/index.js.map +1 -0
- package/dist/formatEnvPort-B3OLxQk9.cjs +171 -0
- package/dist/formatEnvPort-B3OLxQk9.cjs.map +1 -0
- package/dist/formatEnvPort-ByFVLjSV.js +159 -0
- package/dist/formatEnvPort-ByFVLjSV.js.map +1 -0
- package/dist/formatters/index.cjs +21 -61
- package/dist/formatters/index.d.cts +12 -0
- package/dist/formatters/index.d.ts +10 -2152
- package/dist/formatters/index.js +10 -18
- package/dist/formatters--1m_vpE8.js +369 -0
- package/dist/formatters--1m_vpE8.js.map +1 -0
- package/dist/formatters-Cbij0XLU.cjs +429 -0
- package/dist/formatters-Cbij0XLU.cjs.map +1 -0
- package/dist/generators/index.cjs +165 -41
- package/dist/generators/index.cjs.map +1 -0
- package/dist/generators/index.d.cts +12 -0
- package/dist/generators/index.d.ts +10 -338
- package/dist/generators/index.js +158 -14
- package/dist/generators/index.js.map +1 -0
- package/dist/index-59zbLcPr.d.ts +340 -0
- package/dist/index-B6tawc8L.d.cts +1716 -0
- package/dist/index-C267akkJ.d.ts +2158 -0
- package/dist/index-CeBC2Vvl.d.cts +2361 -0
- package/dist/index-CgRDTI6f.d.ts +822 -0
- package/dist/index-CoiUBVmr.d.ts +720 -0
- package/dist/index-D4fcasfZ.d.cts +720 -0
- package/dist/index-DDrSQKIc.d.ts +1716 -0
- package/dist/index-DsGxO31H.d.cts +765 -0
- package/dist/index-Hg1qJkjl.d.ts +765 -0
- package/dist/index-Qm3iFwd0.d.cts +2158 -0
- package/dist/index-UPp94Agr.d.ts +2361 -0
- package/dist/index-gBA_8SuF.d.cts +340 -0
- package/dist/index-jyDqzicx.d.cts +822 -0
- package/dist/isBigInt-C4krUeAw.cjs +20 -0
- package/dist/isBigInt-C4krUeAw.cjs.map +1 -0
- package/dist/isBigInt-DKe0M6hp.js +14 -0
- package/dist/isBigInt-DKe0M6hp.js.map +1 -0
- package/dist/isEmptyObject-DCipFwxJ.js +25 -0
- package/dist/isEmptyObject-DCipFwxJ.js.map +1 -0
- package/dist/isEmptyObject-ZkSwRC_D.cjs +37 -0
- package/dist/isEmptyObject-ZkSwRC_D.cjs.map +1 -0
- package/dist/isEmptyString-BXzKAC2j.js +15 -0
- package/dist/isEmptyString-BXzKAC2j.js.map +1 -0
- package/dist/isEmptyString-UiiUsSQj.cjs +21 -0
- package/dist/isEmptyString-UiiUsSQj.cjs.map +1 -0
- package/dist/isEmptyValue-BQzcjVaL.cjs +30 -0
- package/dist/isEmptyValue-BQzcjVaL.cjs.map +1 -0
- package/dist/isEmptyValue-jqOr7OHD.js +24 -0
- package/dist/isEmptyValue-jqOr7OHD.js.map +1 -0
- package/dist/isEqual-BX49cF9m.js +87 -0
- package/dist/isEqual-BX49cF9m.js.map +1 -0
- package/dist/isEqual-BvumA3RA.cjs +111 -0
- package/dist/isEqual-BvumA3RA.cjs.map +1 -0
- package/dist/isFinite-BCnaDpod.js +15 -0
- package/dist/isFinite-BCnaDpod.js.map +1 -0
- package/dist/isFinite-D24ZaE6c.cjs +21 -0
- package/dist/isFinite-D24ZaE6c.cjs.map +1 -0
- package/dist/isInteger-Caeuz0rB.cjs +20 -0
- package/dist/isInteger-Caeuz0rB.cjs.map +1 -0
- package/dist/isInteger-naMbJsxJ.js +14 -0
- package/dist/isInteger-naMbJsxJ.js.map +1 -0
- package/dist/isPlainObject-BF-2-phb.d.cts +339 -0
- package/dist/isPlainObject-DxNDL8XU.d.ts +339 -0
- package/dist/isServer-BJHVnixd.cjs +20 -0
- package/dist/isServer-BJHVnixd.cjs.map +1 -0
- package/dist/isServer-Da3o3XSs.js +14 -0
- package/dist/isServer-Da3o3XSs.js.map +1 -0
- package/dist/isTypedArray-DuNA8tK6.js +31 -0
- package/dist/isTypedArray-DuNA8tK6.js.map +1 -0
- package/dist/isTypedArray-TJptiw2b.cjs +43 -0
- package/dist/isTypedArray-TJptiw2b.cjs.map +1 -0
- package/dist/isURL-C-kSk6KJ.js +14 -0
- package/dist/isURL-C-kSk6KJ.js.map +1 -0
- package/dist/isURL-DeUPO_oR.cjs +20 -0
- package/dist/isURL-DeUPO_oR.cjs.map +1 -0
- package/dist/isValidDomain-BB9IGhJs.cjs +1845 -0
- package/dist/isValidDomain-BB9IGhJs.cjs.map +1 -0
- package/dist/isValidDomain-DoE98yhJ.js +1827 -0
- package/dist/isValidDomain-DoE98yhJ.js.map +1 -0
- package/dist/next/index.cjs +119 -214
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +220 -0
- package/dist/next/index.d.ts +203 -214
- package/dist/next/index.js +117 -212
- package/dist/next/index.js.map +1 -0
- package/dist/next/server/index.cjs +25 -40
- package/dist/next/server/index.cjs.map +1 -0
- package/dist/next/server/index.d.cts +39 -0
- package/dist/next/server/index.d.ts +34 -35
- package/dist/next/server/index.js +23 -38
- package/dist/next/server/index.js.map +1 -0
- package/dist/noop-B13_ii35.cjs +18 -0
- package/dist/noop-B13_ii35.cjs.map +1 -0
- package/dist/noop-ubqAIbHD.js +12 -0
- package/dist/noop-ubqAIbHD.js.map +1 -0
- package/dist/normalizeSpaces-Bg2IZW7W.js +23 -0
- package/dist/normalizeSpaces-Bg2IZW7W.js.map +1 -0
- package/dist/normalizeSpaces-ZXnR4Qzp.cjs +29 -0
- package/dist/normalizeSpaces-ZXnR4Qzp.cjs.map +1 -0
- package/dist/normalizeString-BDdkaXui.js +15 -0
- package/dist/normalizeString-BDdkaXui.js.map +1 -0
- package/dist/normalizeString-BE6ELqEb.cjs +21 -0
- package/dist/normalizeString-BE6ELqEb.cjs.map +1 -0
- package/dist/operations/index.cjs +65 -32
- package/dist/operations/index.cjs.map +1 -0
- package/dist/operations/index.d.cts +139 -0
- package/dist/operations/index.d.ts +129 -134
- package/dist/operations/index.js +61 -17
- package/dist/operations/index.js.map +1 -0
- package/dist/parsers/index.cjs +12 -19
- package/dist/parsers/index.d.cts +239 -0
- package/dist/parsers/index.d.ts +234 -235
- package/dist/parsers/index.js +10 -12
- package/dist/parsers-BSBPgvsq.js +643 -0
- package/dist/parsers-BSBPgvsq.js.map +1 -0
- package/dist/parsers-OqDeffqc.cjs +649 -0
- package/dist/parsers-OqDeffqc.cjs.map +1 -0
- package/dist/parsing-Cao8b358.js +50 -0
- package/dist/parsing-Cao8b358.js.map +1 -0
- package/dist/parsing-DOGSCH6N.cjs +56 -0
- package/dist/parsing-DOGSCH6N.cjs.map +1 -0
- package/dist/predicates/index.cjs +91 -296
- package/dist/predicates/index.d.cts +13 -0
- package/dist/predicates/index.d.ts +12 -2482
- package/dist/predicates/index.js +23 -25
- package/dist/predicates-Bj6meyXV.js +256 -0
- package/dist/predicates-Bj6meyXV.js.map +1 -0
- package/dist/predicates-D0ubqgqy.cjs +412 -0
- package/dist/predicates-D0ubqgqy.cjs.map +1 -0
- package/dist/promises/index.cjs +76 -24
- package/dist/promises/index.cjs.map +1 -0
- package/dist/promises/index.d.cts +123 -0
- package/dist/promises/index.d.ts +116 -119
- package/dist/promises/index.js +73 -13
- package/dist/promises/index.js.map +1 -0
- package/dist/punyCode-8SrbMWfM.js +179 -0
- package/dist/punyCode-8SrbMWfM.js.map +1 -0
- package/dist/punyCode-D-Qu6nj6.cjs +185 -0
- package/dist/punyCode-D-Qu6nj6.cjs.map +1 -0
- package/dist/removeSpaces-Bmc5DX4F.js +19 -0
- package/dist/removeSpaces-Bmc5DX4F.js.map +1 -0
- package/dist/removeSpaces-CWIvhZHg.cjs +25 -0
- package/dist/removeSpaces-CWIvhZHg.cjs.map +1 -0
- package/dist/rzl-utils.global.js +20 -9
- package/dist/safeJsonParse-BP38mwlj.js +184 -0
- package/dist/safeJsonParse-BP38mwlj.js.map +1 -0
- package/dist/safeJsonParse-Sms2CJf4.cjs +208 -0
- package/dist/safeJsonParse-Sms2CJf4.cjs.map +1 -0
- package/dist/safeStableStringify-CJtP89qn.cjs +106 -0
- package/dist/safeStableStringify-CJtP89qn.cjs.map +1 -0
- package/dist/safeStableStringify-CXOZ9Ub8.js +88 -0
- package/dist/safeStableStringify-CXOZ9Ub8.js.map +1 -0
- package/dist/strings/index.cjs +79 -81
- package/dist/strings/index.cjs.map +1 -0
- package/dist/strings/index.d.cts +12 -0
- package/dist/strings/index.d.ts +10 -775
- package/dist/strings/index.js +62 -14
- package/dist/strings/index.js.map +1 -0
- package/dist/tailwind/index.cjs +19 -47
- package/dist/tailwind/index.d.cts +12 -0
- package/dist/tailwind/index.d.ts +11 -712
- package/dist/tailwind/index.js +10 -12
- package/dist/tailwind-B2ssevxq.js +199 -0
- package/dist/tailwind-B2ssevxq.js.map +1 -0
- package/dist/tailwind-CHIx9uxu.cjs +247 -0
- package/dist/tailwind-CHIx9uxu.cjs.map +1 -0
- package/dist/toStringArrayUnRecursive-C4zYCja7.cjs +51 -0
- package/dist/toStringArrayUnRecursive-C4zYCja7.cjs.map +1 -0
- package/dist/toStringArrayUnRecursive-DJGtPsFb.js +39 -0
- package/dist/toStringArrayUnRecursive-DJGtPsFb.js.map +1 -0
- package/dist/urls/index.cjs +130 -57
- package/dist/urls/index.cjs.map +1 -0
- package/dist/urls/index.d.cts +737 -0
- package/dist/urls/index.d.ts +699 -708
- package/dist/urls/index.js +122 -26
- package/dist/urls/index.js.map +1 -0
- package/package.json +203 -194
- package/dist/chunk-2AFQ33D3.cjs +0 -64
- package/dist/chunk-2CYDJVGM.js +0 -246
- package/dist/chunk-2MW4JDQ2.cjs +0 -598
- package/dist/chunk-2VTDXC3N.cjs +0 -1825
- package/dist/chunk-44XX2P34.js +0 -209
- package/dist/chunk-4YLBKLGS.cjs +0 -18
- package/dist/chunk-566CXQW7.cjs +0 -560
- package/dist/chunk-57EPKYID.cjs +0 -397
- package/dist/chunk-5MGEC3YG.js +0 -63
- package/dist/chunk-6EF52423.cjs +0 -249
- package/dist/chunk-6SCOKU3S.js +0 -109
- package/dist/chunk-6VUXD3CF.js +0 -119
- package/dist/chunk-7B76BSNK.cjs +0 -118
- package/dist/chunk-7Y6I2DSU.cjs +0 -101
- package/dist/chunk-A7S7E2EE.cjs +0 -308
- package/dist/chunk-AJZ6PMMZ.js +0 -16
- package/dist/chunk-AXGBL2IO.cjs +0 -251
- package/dist/chunk-B4TC6FBV.cjs +0 -678
- package/dist/chunk-BAV5T2E3.cjs +0 -15
- package/dist/chunk-BKIJBNIE.js +0 -21
- package/dist/chunk-BNIMTFK5.js +0 -59
- package/dist/chunk-BXW7YXB7.js +0 -1823
- package/dist/chunk-CFYZC4S6.js +0 -53
- package/dist/chunk-CSG4SCL3.js +0 -1587
- package/dist/chunk-CWQW7AKK.js +0 -676
- package/dist/chunk-DVMHRLKP.cjs +0 -16
- package/dist/chunk-EN7LVZBZ.js +0 -548
- package/dist/chunk-EV4Y7HCY.cjs +0 -26
- package/dist/chunk-F66VDYIZ.cjs +0 -18
- package/dist/chunk-FLJX37EL.cjs +0 -30
- package/dist/chunk-GKC3UDMC.cjs +0 -1623
- package/dist/chunk-H65I3GRZ.cjs +0 -106
- package/dist/chunk-HHYWB7VZ.js +0 -24
- package/dist/chunk-HNGGISFL.cjs +0 -65
- package/dist/chunk-HNSQAVSZ.cjs +0 -35
- package/dist/chunk-HSP6IWZK.js +0 -17
- package/dist/chunk-IDZS7J6T.js +0 -242
- package/dist/chunk-JS6R55VL.js +0 -302
- package/dist/chunk-JZVT5FK7.js +0 -232
- package/dist/chunk-KHO2SBNA.cjs +0 -16
- package/dist/chunk-KIDJCMNJ.js +0 -33
- package/dist/chunk-KOLEURVT.cjs +0 -38
- package/dist/chunk-L4V53MQK.cjs +0 -269
- package/dist/chunk-L5RDAVVH.js +0 -14
- package/dist/chunk-NODTV4F3.js +0 -16
- package/dist/chunk-NYK5K3V2.cjs +0 -211
- package/dist/chunk-ODUO3RTL.cjs +0 -113
- package/dist/chunk-ONZFBJVW.js +0 -14
- package/dist/chunk-PFXCTE37.js +0 -28
- package/dist/chunk-PPST7QAQ.js +0 -587
- package/dist/chunk-Q5IMYDFL.cjs +0 -33
- package/dist/chunk-QFFBIOJ4.js +0 -31
- package/dist/chunk-QNKGP5DY.js +0 -14
- package/dist/chunk-RRQHMOPE.cjs +0 -19
- package/dist/chunk-RU5OSRBU.js +0 -95
- package/dist/chunk-SDMPEJ4F.js +0 -35
- package/dist/chunk-SYNL5IKP.js +0 -115
- package/dist/chunk-TCDOWZQE.js +0 -16
- package/dist/chunk-TQPGXGKB.cjs +0 -123
- package/dist/chunk-TULOI4GL.js +0 -370
- package/dist/chunk-UBHCP4N5.cjs +0 -36
- package/dist/chunk-UCHF3M34.cjs +0 -56
- package/dist/chunk-UDA26MCU.cjs +0 -16
- package/dist/chunk-V3C4FYZL.cjs +0 -18
- package/dist/chunk-VAAHZFBF.js +0 -32
- package/dist/chunk-VJDDGRIK.cjs +0 -16
- package/dist/chunk-WVSPXFTY.js +0 -14
- package/dist/chunk-WYP76WXB.js +0 -101
- package/dist/chunk-YDE4ZBB7.cjs +0 -237
- package/dist/chunk-YKQEOO7C.cjs +0 -23
- package/dist/chunk-YSZC56SZ.js +0 -264
- package/dist/chunk-YWHHVDT4.js +0 -13
- package/dist/index.d.ts +0 -24
- package/dist/isPlainObject-DTJVV2Kf.d.ts +0 -536
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/utils-js
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `3.12.1-beta.1`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
import { r as getPreciseType } from "./assertIsBoolean-DR1SaXPD.js";
|
|
11
|
+
import { t as assertIsString } from "./assertIsString-CEB07_83.js";
|
|
12
|
+
const maxInt = 2147483647;
|
|
13
|
+
const base = 36, tMin = 1, tMax = 26, skew = 38, damp = 700;
|
|
14
|
+
const initialBias = 72, initialN = 128, delimiter = "-";
|
|
15
|
+
const regexPunycode = /^xn--/;
|
|
16
|
+
const regexNonASCII = /[^\0-\x7F]/;
|
|
17
|
+
const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g;
|
|
18
|
+
const errors = {
|
|
19
|
+
overflow: "Overflow: input needs wider integers to process",
|
|
20
|
+
"not-basic": "Illegal input >= 0x80 (not a basic code point)",
|
|
21
|
+
"invalid-input": "Invalid input"
|
|
22
|
+
};
|
|
23
|
+
const floor = Math.floor;
|
|
24
|
+
const stringFromCharCode = String.fromCharCode;
|
|
25
|
+
function error(type) {
|
|
26
|
+
throw new RangeError(errors[type]);
|
|
27
|
+
}
|
|
28
|
+
function map(array, fn) {
|
|
29
|
+
const result = [];
|
|
30
|
+
let length = array.length;
|
|
31
|
+
while (length--) if (array[length]) result[length] = fn(array[length]);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
function mapDomain(domain, fn) {
|
|
35
|
+
const parts = domain.split("@");
|
|
36
|
+
let result = "";
|
|
37
|
+
if (parts.length > 1) {
|
|
38
|
+
result = parts[0] + "@";
|
|
39
|
+
if (parts[1]) domain = parts[1];
|
|
40
|
+
}
|
|
41
|
+
domain = domain.replace(regexSeparators, ".");
|
|
42
|
+
const labels = domain.split(".");
|
|
43
|
+
return result + map(labels, fn).join(".");
|
|
44
|
+
}
|
|
45
|
+
function ucs2decode(input) {
|
|
46
|
+
assertIsString(input, { message: ({ currentType, validType }) => `Utils \`punycodeUtilsJS.ucs2.decode\`, parameter \`input\` must be of type \`${validType}\`, but received: \`${currentType}\`.` });
|
|
47
|
+
const output = [];
|
|
48
|
+
let counter = 0;
|
|
49
|
+
const length = input.length;
|
|
50
|
+
while (counter < length) {
|
|
51
|
+
const value = input.charCodeAt(counter++);
|
|
52
|
+
if (value >= 55296 && value <= 56319 && counter < length) {
|
|
53
|
+
const extra = input.charCodeAt(counter++);
|
|
54
|
+
if ((extra & 64512) === 56320) output.push(((value & 1023) << 10) + (extra & 1023) + 65536);
|
|
55
|
+
else {
|
|
56
|
+
output.push(value);
|
|
57
|
+
counter--;
|
|
58
|
+
}
|
|
59
|
+
} else output.push(value);
|
|
60
|
+
}
|
|
61
|
+
return output;
|
|
62
|
+
}
|
|
63
|
+
const ucs2encode = (points) => {
|
|
64
|
+
if (!Array.isArray(points) || !points.every((p) => typeof p === "number" && Number.isFinite(p))) throw new TypeError(`Utils \`punycodeUtilsJS.ucs2.encode\`, parameter \`points\` must be an array of numbers, but received: \`${getPreciseType(points)}\`.`);
|
|
65
|
+
return String.fromCodePoint(...points);
|
|
66
|
+
};
|
|
67
|
+
function basicToDigit(codePoint) {
|
|
68
|
+
if (codePoint >= 48 && codePoint < 58) return 26 + (codePoint - 48);
|
|
69
|
+
if (codePoint >= 65 && codePoint < 91) return codePoint - 65;
|
|
70
|
+
if (codePoint >= 97 && codePoint < 123) return codePoint - 97;
|
|
71
|
+
return base;
|
|
72
|
+
}
|
|
73
|
+
function digitToBasic(digit, flag) {
|
|
74
|
+
return digit + 22 + 75 * (digit < 26 ? 1 : 0) - Number(flag !== 0) * 32;
|
|
75
|
+
}
|
|
76
|
+
function adapt(delta, numPoints, firstTime) {
|
|
77
|
+
let k = 0;
|
|
78
|
+
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
|
79
|
+
delta += floor(delta / numPoints);
|
|
80
|
+
while (delta > (base - tMin) * tMax >> 1) {
|
|
81
|
+
delta = floor(delta / (base - tMin));
|
|
82
|
+
k += base;
|
|
83
|
+
}
|
|
84
|
+
return floor(k + (base - tMin + 1) * delta / (delta + skew));
|
|
85
|
+
}
|
|
86
|
+
function decode(input) {
|
|
87
|
+
assertIsString(input, { message: ({ currentType, validType }) => `Utils \`punycodeUtilsJS.decode\`, parameter \`input\` must be of type \`${validType}\`, but received: \`${currentType}\`.` });
|
|
88
|
+
const output = [];
|
|
89
|
+
const inputLength = input.length;
|
|
90
|
+
let i = 0, n = initialN, bias = initialBias;
|
|
91
|
+
let basic = input.lastIndexOf(delimiter);
|
|
92
|
+
if (basic < 0) basic = 0;
|
|
93
|
+
for (let j = 0; j < basic; j++) {
|
|
94
|
+
if (input.charCodeAt(j) >= 128) error("not-basic");
|
|
95
|
+
output.push(input.charCodeAt(j));
|
|
96
|
+
}
|
|
97
|
+
for (let index = basic > 0 ? basic + 1 : 0; index < inputLength;) {
|
|
98
|
+
const oldi = i;
|
|
99
|
+
let w = 1;
|
|
100
|
+
for (let k = base;; k += base) {
|
|
101
|
+
if (index >= inputLength) error("invalid-input");
|
|
102
|
+
const digit = basicToDigit(input.charCodeAt(index++));
|
|
103
|
+
if (digit >= base) error("invalid-input");
|
|
104
|
+
if (digit > floor((maxInt - i) / w)) error("overflow");
|
|
105
|
+
i += digit * w;
|
|
106
|
+
const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
|
|
107
|
+
if (digit < t) break;
|
|
108
|
+
const baseMinusT = base - t;
|
|
109
|
+
if (w > floor(maxInt / baseMinusT)) error("overflow");
|
|
110
|
+
w *= baseMinusT;
|
|
111
|
+
}
|
|
112
|
+
const out = output.length + 1;
|
|
113
|
+
bias = adapt(i - oldi, out, oldi === 0);
|
|
114
|
+
if (floor(i / out) > maxInt - n) error("overflow");
|
|
115
|
+
n += floor(i / out);
|
|
116
|
+
i %= out;
|
|
117
|
+
output.splice(i++, 0, n);
|
|
118
|
+
}
|
|
119
|
+
return String.fromCodePoint(...output);
|
|
120
|
+
}
|
|
121
|
+
function encode(input) {
|
|
122
|
+
assertIsString(input, { message: ({ currentType, validType }) => `Utils \`punycodeUtilsJS.encode\`, parameter \`input\` must be of type \`${validType}\`, but received: \`${currentType}\`.` });
|
|
123
|
+
const output = [];
|
|
124
|
+
const points = ucs2decode(input);
|
|
125
|
+
const inputLength = points.length;
|
|
126
|
+
let n = initialN, delta = 0, bias = initialBias;
|
|
127
|
+
for (const cp of points) if (cp < 128) output.push(stringFromCharCode(cp));
|
|
128
|
+
const basicLength = output.length;
|
|
129
|
+
let handledCPCount = basicLength;
|
|
130
|
+
if (basicLength) output.push(delimiter);
|
|
131
|
+
while (handledCPCount < inputLength) {
|
|
132
|
+
let m = maxInt;
|
|
133
|
+
for (const cp of points) if (cp >= n && cp < m) m = cp;
|
|
134
|
+
const handledCPCountPlusOne = handledCPCount + 1;
|
|
135
|
+
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) error("overflow");
|
|
136
|
+
delta += (m - n) * handledCPCountPlusOne;
|
|
137
|
+
n = m;
|
|
138
|
+
for (const cp of points) {
|
|
139
|
+
if (cp < n) delta++;
|
|
140
|
+
if (cp === n) {
|
|
141
|
+
let q = delta;
|
|
142
|
+
for (let k = base;; k += base) {
|
|
143
|
+
const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
|
|
144
|
+
if (q < t) break;
|
|
145
|
+
output.push(stringFromCharCode(digitToBasic(t + (q - t) % (base - t), 0)));
|
|
146
|
+
q = floor((q - t) / (base - t));
|
|
147
|
+
}
|
|
148
|
+
output.push(stringFromCharCode(digitToBasic(q, 0)));
|
|
149
|
+
bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
|
|
150
|
+
delta = 0;
|
|
151
|
+
handledCPCount++;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
delta++;
|
|
155
|
+
n++;
|
|
156
|
+
}
|
|
157
|
+
return output.join("");
|
|
158
|
+
}
|
|
159
|
+
function toUnicode(input) {
|
|
160
|
+
assertIsString(input, { message: ({ currentType, validType }) => `Utils \`punycodeUtilsJS.toUnicode\`, parameter \`input\` must be of type \`${validType}\`, but received: \`${currentType}\`.` });
|
|
161
|
+
return mapDomain(input, (str) => regexPunycode.test(str) ? decode(str.slice(4).toLowerCase()) : str);
|
|
162
|
+
}
|
|
163
|
+
function toASCII(input) {
|
|
164
|
+
assertIsString(input, { message: ({ currentType, validType }) => `Utils \`punycodeUtilsJS.toASCII\`, parameter \`input\` must be of type \`${validType}\`, but received: \`${currentType}\`.` });
|
|
165
|
+
return mapDomain(input, (str) => regexNonASCII.test(str) ? "xn--" + encode(str) : str);
|
|
166
|
+
}
|
|
167
|
+
const punycodeUtilsJS = {
|
|
168
|
+
version: "1.0.0",
|
|
169
|
+
ucs2: {
|
|
170
|
+
decode: ucs2decode,
|
|
171
|
+
encode: ucs2encode
|
|
172
|
+
},
|
|
173
|
+
decode,
|
|
174
|
+
encode,
|
|
175
|
+
toASCII,
|
|
176
|
+
toUnicode
|
|
177
|
+
};
|
|
178
|
+
export { punycodeUtilsJS as t };
|
|
179
|
+
//# sourceMappingURL=punyCode-8SrbMWfM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"punyCode-8SrbMWfM.js","names":[],"sources":["../src/urls/utils/punyCode.ts"],"sourcesContent":["/** ---------------------------------------------------------\n * * ***Constants for `Punycode-UtilsJS` algorithm.***\n * ---------------------------------------------------------\n * These constants are used internally for encoding and decoding.\n *\n * Unicode domain names to ASCII (`Punycode-UtilsJS`) and vice versa.\n */\n\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { assertIsString } from \"@/assertions/strings/assertIsString\";\n\n/**\n * Constant `maxInt` for validate.\n */\nconst maxInt = 2147483647;\n\n/**\n * Bootstring parameters for `Punycode-UtilsJS`.\n */\nconst base = 36,\n tMin = 1,\n tMax = 26,\n skew = 38,\n damp = 700;\n\n/**\n * Initial bias and code point.\n */\nconst initialBias = 72,\n initialN = 128,\n delimiter = \"-\";\n\n/**\n * Regular expressions used internally.\n * Matches `Punycode-UtilsJS` prefix.\n */\nconst regexPunycode = /^xn--/;\n/**\n * Regular expressions used internally.\n * Matches non-ASCII chars.\n */\nconst regexNonASCII = /[^\\0-\\x7F]/;\n/**\n * Regular expressions used internally.\n * Matches domain label separators.\n */\nconst regexSeparators = /[\\x2E\\u3002\\uFF0E\\uFF61]/g;\n\n/**\n * Error messages used internally.\n */\nconst errors: Record<string, string> = {\n overflow: \"Overflow: input needs wider integers to process\",\n \"not-basic\": \"Illegal input >= 0x80 (not a basic code point)\",\n \"invalid-input\": \"Invalid input\"\n};\n\n/**\n * Aliases of `Math.floor`.\n */\nconst floor = Math.floor;\n/** \n * Aliases of `String.fromCharCode`.\n\n*/\nconst stringFromCharCode = String.fromCharCode;\n\n/** ---------------------------------------------------------\n * * ***Throws a RangeError with a predefined error message.***\n * ---------------------------------------------------------\n *\n * @param type - Key of the error type to throw.\n */\nfunction error(type: keyof typeof errors): never {\n throw new RangeError(errors[type]);\n}\n\n/** ---------------------------------------------------------\n * * ***Maps an array using a callback function.***\n * ---------------------------------------------------------\n *\n * @param array - Array to transform.\n * @param fn - Function to apply to each element.\n * @returns Transformed array.\n */\nfunction map<T, U>(array: T[], fn: (v: T) => U): U[] {\n const result: U[] = [];\n let length = array.length;\n while (length--) {\n if (array[length]) {\n result[length] = fn(array[length]!);\n }\n }\n return result;\n}\n\n/** ---------------------------------------------------------\n * * ***Maps a domain name using a callback on each label.***\n * ---------------------------------------------------------\n *\n * Handles email-like domains (local@domain).\n * @param domain - Domain string to process.\n * @param fn - Function applied to each domain label.\n * @returns Transformed domain string.\n */\nfunction mapDomain(domain: string, fn: (v: string) => string): string {\n const parts = domain.split(\"@\");\n let result = \"\";\n if (parts.length > 1) {\n result = parts[0] + \"@\";\n if (parts[1]) domain = parts[1];\n }\n domain = domain.replace(regexSeparators, \"\\x2E\");\n const labels = domain.split(\".\");\n return result + map(labels, fn).join(\".\");\n}\n\n/** ---------------------------------------------------------\n * * ***Converts a UCS-2 encoded string to an array of Unicode code points.***\n * ---------------------------------------------------------\n *\n * @param input - String to decode.\n * @returns Array of Unicode code points.\n */\nfunction ucs2decode(input: string): number[] {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.ucs2.decode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: number[] = [];\n let counter = 0;\n const length = input.length;\n while (counter < length) {\n const value = input.charCodeAt(counter++);\n if (value >= 0xd800 && value <= 0xdbff && counter < length) {\n const extra = input.charCodeAt(counter++);\n if ((extra & 0xfc00) === 0xdc00)\n output.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);\n else {\n output.push(value);\n counter--;\n }\n } else output.push(value);\n }\n return output;\n}\n\n/** ---------------------------------------------------------\n * * ***Encodes an array of Unicode code points to a string.***\n * ---------------------------------------------------------\n *\n * @param points - Array of Unicode code points.\n * @returns Encoded string.\n */\nconst ucs2encode = (points: number[]): string => {\n if (\n !Array.isArray(points) ||\n !points.every((p) => typeof p === \"number\" && Number.isFinite(p))\n ) {\n throw new TypeError(\n `Utils \\`punycodeUtilsJS.ucs2.encode\\`, parameter \\`points\\` must be an array of numbers, but received: \\`${getPreciseType(\n points\n )}\\`.`\n );\n }\n\n return String.fromCodePoint(...points);\n};\n\n/** ---------------------------------------------------------\n * * ***Converts a basic code point to its digit value for `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param codePoint - Unicode code point.\n * @returns Digit value.\n */\nfunction basicToDigit(codePoint: number): number {\n if (codePoint >= 0x30 && codePoint < 0x3a) return 26 + (codePoint - 0x30);\n if (codePoint >= 0x41 && codePoint < 0x5b) return codePoint - 0x41;\n if (codePoint >= 0x61 && codePoint < 0x7b) return codePoint - 0x61;\n return base;\n}\n\n/** ---------------------------------------------------------\n * * ***Converts a digit to a basic code point for `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param digit - Numeric value.\n * @param flag - Bias flag (0 or 1).\n * @returns Code point.\n */\nfunction digitToBasic(digit: number, flag: number): number {\n return digit + 22 + 75 * (digit < 26 ? 1 : 0) - Number(flag !== 0) * 32;\n}\n\n/** ---------------------------------------------------------\n * * ***Bias adaptation function for `Punycode-UtilsJS` encoding/decoding.***\n * ---------------------------------------------------------\n *\n * @param delta - Delta value.\n * @param numPoints - Number of code points.\n * @param firstTime - Indicates first adaptation.\n * @returns Adapted bias.\n */\nfunction adapt(delta: number, numPoints: number, firstTime: boolean): number {\n let k = 0;\n delta = firstTime ? floor(delta / damp) : delta >> 1;\n delta += floor(delta / numPoints);\n while (delta > ((base - tMin) * tMax) >> 1) {\n delta = floor(delta / (base - tMin));\n k += base;\n }\n return floor(k + ((base - tMin + 1) * delta) / (delta + skew));\n}\n\n/** ---------------------------------------------------------\n * * ***Decodes a `Punycode-UtilsJS` string to Unicode.***\n * ---------------------------------------------------------\n *\n * @param input - `Punycode-UtilsJS` string.\n * @returns Decoded Unicode string.\n */\nfunction decode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.decode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: number[] = [];\n const inputLength = input.length;\n let i = 0,\n n = initialN,\n bias = initialBias;\n\n let basic = input.lastIndexOf(delimiter);\n if (basic < 0) basic = 0;\n\n for (let j = 0; j < basic; j++) {\n if (input.charCodeAt(j) >= 0x80) error(\"not-basic\");\n output.push(input.charCodeAt(j));\n }\n\n for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; ) {\n const oldi = i;\n let w = 1;\n for (let k = base; ; k += base) {\n if (index >= inputLength) error(\"invalid-input\");\n const digit = basicToDigit(input.charCodeAt(index++));\n if (digit >= base) error(\"invalid-input\");\n if (digit > floor((maxInt - i) / w)) error(\"overflow\");\n i += digit * w;\n const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;\n if (digit < t) break;\n const baseMinusT = base - t;\n if (w > floor(maxInt / baseMinusT)) error(\"overflow\");\n w *= baseMinusT;\n }\n const out = output.length + 1;\n bias = adapt(i - oldi, out, oldi === 0);\n if (floor(i / out) > maxInt - n) error(\"overflow\");\n n += floor(i / out);\n i %= out;\n output.splice(i++, 0, n);\n }\n return String.fromCodePoint(...output);\n}\n\n/** ---------------------------------------------------------\n * * ***Encodes a Unicode string to `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param input - Unicode string.\n * @returns `Punycode-UtilsJS` string.\n */\nfunction encode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.encode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: string[] = [];\n const points = ucs2decode(input);\n const inputLength = points.length;\n let n = initialN,\n delta = 0,\n bias = initialBias;\n\n for (const cp of points) if (cp < 0x80) output.push(stringFromCharCode(cp));\n const basicLength = output.length;\n let handledCPCount = basicLength;\n if (basicLength) output.push(delimiter);\n\n while (handledCPCount < inputLength) {\n let m = maxInt;\n for (const cp of points) if (cp >= n && cp < m) m = cp;\n\n const handledCPCountPlusOne = handledCPCount + 1;\n if (m - n > floor((maxInt - delta) / handledCPCountPlusOne))\n error(\"overflow\");\n delta += (m - n) * handledCPCountPlusOne;\n n = m;\n\n for (const cp of points) {\n if (cp < n) delta++;\n if (cp === n) {\n let q = delta;\n for (let k = base; ; k += base) {\n const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;\n if (q < t) break;\n output.push(\n stringFromCharCode(digitToBasic(t + ((q - t) % (base - t)), 0))\n );\n q = floor((q - t) / (base - t));\n }\n output.push(stringFromCharCode(digitToBasic(q, 0)));\n bias = adapt(\n delta,\n handledCPCountPlusOne,\n handledCPCount === basicLength\n );\n delta = 0;\n handledCPCount++;\n }\n }\n delta++;\n n++;\n }\n\n return output.join(\"\");\n}\n\n/** ---------------------------------------------------------\n * * ***Converts `Punycode-UtilsJS` to Unicode for domain names.***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label.\n * @returns Unicode string.\n */\nfunction toUnicode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.toUnicode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n return mapDomain(input, (str) =>\n regexPunycode.test(str) ? decode(str.slice(4).toLowerCase()) : str\n );\n}\n\n/** ---------------------------------------------------------\n * * ***Converts Unicode to ASCII (`Punycode-UtilsJS`) for domain names.***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label.\n * @returns ASCII string.\n */\nfunction toASCII(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.toASCII\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n return mapDomain(input, (str) =>\n regexNonASCII.test(str) ? \"xn--\" + encode(str) : str\n );\n}\n\ntype PunycodeUtilsJS = {\n /** ---------------------------------------------------------\n * * ***Version of the `Punycode-UtilsJS` implementation.***\n * ---------------------------------------------------------\n *\n * @example\n * console.log(punycodeUtilsJS.version); // \"1.0.0\"\n */\n version: string;\n /** ---------------------------------------------------------\n * * ***UCS-2 utility functions.***\n * ---------------------------------------------------------\n */\n ucs2: {\n /** ---------------------------------------------------------\n * * ***Decodes a UCS-2 encoded string to an array of Unicode code points.***\n * ---------------------------------------------------------\n *\n * @param input - The UCS-2 string to decode.\n * @returns Array of Unicode code points.\n * @example\n * punycodeUtilsJS.ucs2.decode(\"π\");\n * // β [66376]\n */\n decode: (input: string) => number[];\n /** ---------------------------------------------------------\n * * ***Encodes an array of Unicode code points to a UCS-2 string.***\n * ---------------------------------------------------------\n *\n * @param points - Array of Unicode code points.\n * @returns Encoded string.\n * @example\n * punycodeUtilsJS.ucs2.encode([66376]);\n * // β \"π\"\n */\n encode: (points: number[]) => string;\n };\n /** ---------------------------------------------------------\n * * ***Decodes a `Punycode-UtilsJS` string to a Unicode string.***\n * ---------------------------------------------------------\n *\n * @param input - The `Punycode-UtilsJS` string to decode.\n * @returns Decoded Unicode string.\n * @example\n * punycodeUtilsJS.decode(\"xn--fsq\");\n * // β \"ΓΌ\"\n */\n decode: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Encodes a Unicode string to `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param input - Unicode string to encode.\n * @returns `Punycode-UtilsJS` string.\n * @example\n * punycodeUtilsJS.encode(\"ΓΌ\");\n * // β \"xn--fsq\"\n */\n encode: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Converts a Unicode domain or label to ASCII (`Punycode-UtilsJS`).***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label string.\n * @returns ASCII string suitable for DNS.\n * @example\n * punycodeUtilsJS.toASCII(\"ΠΏΡΠΈΠΌΠ΅Ρ.ΡΡ\");\n * // β \"xn--e1afmkfd.xn--p1ai\"\n */\n toASCII: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Converts an ASCII (`Punycode-UtilsJS`) domain or label to Unicode.***\n * ---------------------------------------------------------\n *\n * @param input - ASCII string (with xn-- prefix if needed).\n * @returns Unicode string.\n * @example\n * punycodeUtilsJS.toUnicode(\"xn--e1afmkfd.xn--p1ai\");\n * // β \"ΠΏΡΠΈΠΌΠ΅Ρ.ΡΡ\"\n */\n toUnicode: (input: string) => string;\n};\n\n/** ---------------------------------------------------------\n * * ***`Punycode-UtilsJS` object exposing all API functions and version.***\n * ---------------------------------------------------------\n * Provides encoding and decoding of Unicode domain names to ASCII (`Punycode-UtilsJS`)\n * and vice versa.\n *\n * - Useful for IDN (Internationalized Domain Names) support.\n */\nconst punycodeUtilsJS: PunycodeUtilsJS = {\n version: \"1.0.0\",\n ucs2: {\n decode: ucs2decode,\n encode: ucs2encode\n },\n decode: decode,\n encode: encode,\n toASCII: toASCII,\n toUnicode: toUnicode\n};\n\n/**\n * Export individual functions.\n */\nexport { punycodeUtilsJS };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,SAAS;;;;AAKf,MAAM,OAAO,IACX,OAAO,GACP,OAAO,IACP,OAAO,IACP,OAAO;;;;AAKT,MAAM,cAAc,IAClB,WAAW,KACX,YAAY;;;;;AAMd,MAAM,gBAAgB;;;;;AAKtB,MAAM,gBAAgB;;;;;AAKtB,MAAM,kBAAkB;;;;AAKxB,MAAM,SAAiC;CACrC,UAAU;CACV,aAAa;CACb,iBAAiB;CAClB;;;;AAKD,MAAM,QAAQ,KAAK;;;;;AAKnB,MAAM,qBAAqB,OAAO;;;;;;;AAQlC,SAAS,MAAM,MAAkC;CAC/C,MAAM,IAAI,WAAW,OAAO,MAAM;;;;;;;;;;AAWp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
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `3.12.1-beta.1`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
const require_assertIsBoolean = require('./assertIsBoolean-C8WEXVr2.cjs');
|
|
12
|
+
const require_assertIsString = require('./assertIsString-BiHQSrB2.cjs');
|
|
13
|
+
const maxInt = 2147483647;
|
|
14
|
+
const base = 36, tMin = 1, tMax = 26, skew = 38, damp = 700;
|
|
15
|
+
const initialBias = 72, initialN = 128, delimiter = "-";
|
|
16
|
+
const regexPunycode = /^xn--/;
|
|
17
|
+
const regexNonASCII = /[^\0-\x7F]/;
|
|
18
|
+
const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g;
|
|
19
|
+
const errors = {
|
|
20
|
+
overflow: "Overflow: input needs wider integers to process",
|
|
21
|
+
"not-basic": "Illegal input >= 0x80 (not a basic code point)",
|
|
22
|
+
"invalid-input": "Invalid input"
|
|
23
|
+
};
|
|
24
|
+
const floor = Math.floor;
|
|
25
|
+
const stringFromCharCode = String.fromCharCode;
|
|
26
|
+
function error(type) {
|
|
27
|
+
throw new RangeError(errors[type]);
|
|
28
|
+
}
|
|
29
|
+
function map(array, fn) {
|
|
30
|
+
const result = [];
|
|
31
|
+
let length = array.length;
|
|
32
|
+
while (length--) if (array[length]) result[length] = fn(array[length]);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function mapDomain(domain, fn) {
|
|
36
|
+
const parts = domain.split("@");
|
|
37
|
+
let result = "";
|
|
38
|
+
if (parts.length > 1) {
|
|
39
|
+
result = parts[0] + "@";
|
|
40
|
+
if (parts[1]) domain = parts[1];
|
|
41
|
+
}
|
|
42
|
+
domain = domain.replace(regexSeparators, ".");
|
|
43
|
+
const labels = domain.split(".");
|
|
44
|
+
return result + map(labels, fn).join(".");
|
|
45
|
+
}
|
|
46
|
+
function ucs2decode(input) {
|
|
47
|
+
require_assertIsString.assertIsString(input, { message: ({ currentType, validType }) => `Utils \`punycodeUtilsJS.ucs2.decode\`, parameter \`input\` must be of type \`${validType}\`, but received: \`${currentType}\`.` });
|
|
48
|
+
const output = [];
|
|
49
|
+
let counter = 0;
|
|
50
|
+
const length = input.length;
|
|
51
|
+
while (counter < length) {
|
|
52
|
+
const value = input.charCodeAt(counter++);
|
|
53
|
+
if (value >= 55296 && value <= 56319 && counter < length) {
|
|
54
|
+
const extra = input.charCodeAt(counter++);
|
|
55
|
+
if ((extra & 64512) === 56320) output.push(((value & 1023) << 10) + (extra & 1023) + 65536);
|
|
56
|
+
else {
|
|
57
|
+
output.push(value);
|
|
58
|
+
counter--;
|
|
59
|
+
}
|
|
60
|
+
} else output.push(value);
|
|
61
|
+
}
|
|
62
|
+
return output;
|
|
63
|
+
}
|
|
64
|
+
const ucs2encode = (points) => {
|
|
65
|
+
if (!Array.isArray(points) || !points.every((p) => typeof p === "number" && Number.isFinite(p))) throw new TypeError(`Utils \`punycodeUtilsJS.ucs2.encode\`, parameter \`points\` must be an array of numbers, but received: \`${require_assertIsBoolean.getPreciseType(points)}\`.`);
|
|
66
|
+
return String.fromCodePoint(...points);
|
|
67
|
+
};
|
|
68
|
+
function basicToDigit(codePoint) {
|
|
69
|
+
if (codePoint >= 48 && codePoint < 58) return 26 + (codePoint - 48);
|
|
70
|
+
if (codePoint >= 65 && codePoint < 91) return codePoint - 65;
|
|
71
|
+
if (codePoint >= 97 && codePoint < 123) return codePoint - 97;
|
|
72
|
+
return base;
|
|
73
|
+
}
|
|
74
|
+
function digitToBasic(digit, flag) {
|
|
75
|
+
return digit + 22 + 75 * (digit < 26 ? 1 : 0) - Number(flag !== 0) * 32;
|
|
76
|
+
}
|
|
77
|
+
function adapt(delta, numPoints, firstTime) {
|
|
78
|
+
let k = 0;
|
|
79
|
+
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
|
80
|
+
delta += floor(delta / numPoints);
|
|
81
|
+
while (delta > (base - tMin) * tMax >> 1) {
|
|
82
|
+
delta = floor(delta / (base - tMin));
|
|
83
|
+
k += base;
|
|
84
|
+
}
|
|
85
|
+
return floor(k + (base - tMin + 1) * delta / (delta + skew));
|
|
86
|
+
}
|
|
87
|
+
function decode(input) {
|
|
88
|
+
require_assertIsString.assertIsString(input, { message: ({ currentType, validType }) => `Utils \`punycodeUtilsJS.decode\`, parameter \`input\` must be of type \`${validType}\`, but received: \`${currentType}\`.` });
|
|
89
|
+
const output = [];
|
|
90
|
+
const inputLength = input.length;
|
|
91
|
+
let i = 0, n = initialN, bias = initialBias;
|
|
92
|
+
let basic = input.lastIndexOf(delimiter);
|
|
93
|
+
if (basic < 0) basic = 0;
|
|
94
|
+
for (let j = 0; j < basic; j++) {
|
|
95
|
+
if (input.charCodeAt(j) >= 128) error("not-basic");
|
|
96
|
+
output.push(input.charCodeAt(j));
|
|
97
|
+
}
|
|
98
|
+
for (let index = basic > 0 ? basic + 1 : 0; index < inputLength;) {
|
|
99
|
+
const oldi = i;
|
|
100
|
+
let w = 1;
|
|
101
|
+
for (let k = base;; k += base) {
|
|
102
|
+
if (index >= inputLength) error("invalid-input");
|
|
103
|
+
const digit = basicToDigit(input.charCodeAt(index++));
|
|
104
|
+
if (digit >= base) error("invalid-input");
|
|
105
|
+
if (digit > floor((maxInt - i) / w)) error("overflow");
|
|
106
|
+
i += digit * w;
|
|
107
|
+
const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
|
|
108
|
+
if (digit < t) break;
|
|
109
|
+
const baseMinusT = base - t;
|
|
110
|
+
if (w > floor(maxInt / baseMinusT)) error("overflow");
|
|
111
|
+
w *= baseMinusT;
|
|
112
|
+
}
|
|
113
|
+
const out = output.length + 1;
|
|
114
|
+
bias = adapt(i - oldi, out, oldi === 0);
|
|
115
|
+
if (floor(i / out) > maxInt - n) error("overflow");
|
|
116
|
+
n += floor(i / out);
|
|
117
|
+
i %= out;
|
|
118
|
+
output.splice(i++, 0, n);
|
|
119
|
+
}
|
|
120
|
+
return String.fromCodePoint(...output);
|
|
121
|
+
}
|
|
122
|
+
function encode(input) {
|
|
123
|
+
require_assertIsString.assertIsString(input, { message: ({ currentType, validType }) => `Utils \`punycodeUtilsJS.encode\`, parameter \`input\` must be of type \`${validType}\`, but received: \`${currentType}\`.` });
|
|
124
|
+
const output = [];
|
|
125
|
+
const points = ucs2decode(input);
|
|
126
|
+
const inputLength = points.length;
|
|
127
|
+
let n = initialN, delta = 0, bias = initialBias;
|
|
128
|
+
for (const cp of points) if (cp < 128) output.push(stringFromCharCode(cp));
|
|
129
|
+
const basicLength = output.length;
|
|
130
|
+
let handledCPCount = basicLength;
|
|
131
|
+
if (basicLength) output.push(delimiter);
|
|
132
|
+
while (handledCPCount < inputLength) {
|
|
133
|
+
let m = maxInt;
|
|
134
|
+
for (const cp of points) if (cp >= n && cp < m) m = cp;
|
|
135
|
+
const handledCPCountPlusOne = handledCPCount + 1;
|
|
136
|
+
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) error("overflow");
|
|
137
|
+
delta += (m - n) * handledCPCountPlusOne;
|
|
138
|
+
n = m;
|
|
139
|
+
for (const cp of points) {
|
|
140
|
+
if (cp < n) delta++;
|
|
141
|
+
if (cp === n) {
|
|
142
|
+
let q = delta;
|
|
143
|
+
for (let k = base;; k += base) {
|
|
144
|
+
const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
|
|
145
|
+
if (q < t) break;
|
|
146
|
+
output.push(stringFromCharCode(digitToBasic(t + (q - t) % (base - t), 0)));
|
|
147
|
+
q = floor((q - t) / (base - t));
|
|
148
|
+
}
|
|
149
|
+
output.push(stringFromCharCode(digitToBasic(q, 0)));
|
|
150
|
+
bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
|
|
151
|
+
delta = 0;
|
|
152
|
+
handledCPCount++;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
delta++;
|
|
156
|
+
n++;
|
|
157
|
+
}
|
|
158
|
+
return output.join("");
|
|
159
|
+
}
|
|
160
|
+
function toUnicode(input) {
|
|
161
|
+
require_assertIsString.assertIsString(input, { message: ({ currentType, validType }) => `Utils \`punycodeUtilsJS.toUnicode\`, parameter \`input\` must be of type \`${validType}\`, but received: \`${currentType}\`.` });
|
|
162
|
+
return mapDomain(input, (str) => regexPunycode.test(str) ? decode(str.slice(4).toLowerCase()) : str);
|
|
163
|
+
}
|
|
164
|
+
function toASCII(input) {
|
|
165
|
+
require_assertIsString.assertIsString(input, { message: ({ currentType, validType }) => `Utils \`punycodeUtilsJS.toASCII\`, parameter \`input\` must be of type \`${validType}\`, but received: \`${currentType}\`.` });
|
|
166
|
+
return mapDomain(input, (str) => regexNonASCII.test(str) ? "xn--" + encode(str) : str);
|
|
167
|
+
}
|
|
168
|
+
const punycodeUtilsJS = {
|
|
169
|
+
version: "1.0.0",
|
|
170
|
+
ucs2: {
|
|
171
|
+
decode: ucs2decode,
|
|
172
|
+
encode: ucs2encode
|
|
173
|
+
},
|
|
174
|
+
decode,
|
|
175
|
+
encode,
|
|
176
|
+
toASCII,
|
|
177
|
+
toUnicode
|
|
178
|
+
};
|
|
179
|
+
Object.defineProperty(exports, 'punycodeUtilsJS', {
|
|
180
|
+
enumerable: true,
|
|
181
|
+
get: function () {
|
|
182
|
+
return punycodeUtilsJS;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
//# sourceMappingURL=punyCode-D-Qu6nj6.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"punyCode-D-Qu6nj6.cjs","names":["getPreciseType"],"sources":["../src/urls/utils/punyCode.ts"],"sourcesContent":["/** ---------------------------------------------------------\n * * ***Constants for `Punycode-UtilsJS` algorithm.***\n * ---------------------------------------------------------\n * These constants are used internally for encoding and decoding.\n *\n * Unicode domain names to ASCII (`Punycode-UtilsJS`) and vice versa.\n */\n\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { assertIsString } from \"@/assertions/strings/assertIsString\";\n\n/**\n * Constant `maxInt` for validate.\n */\nconst maxInt = 2147483647;\n\n/**\n * Bootstring parameters for `Punycode-UtilsJS`.\n */\nconst base = 36,\n tMin = 1,\n tMax = 26,\n skew = 38,\n damp = 700;\n\n/**\n * Initial bias and code point.\n */\nconst initialBias = 72,\n initialN = 128,\n delimiter = \"-\";\n\n/**\n * Regular expressions used internally.\n * Matches `Punycode-UtilsJS` prefix.\n */\nconst regexPunycode = /^xn--/;\n/**\n * Regular expressions used internally.\n * Matches non-ASCII chars.\n */\nconst regexNonASCII = /[^\\0-\\x7F]/;\n/**\n * Regular expressions used internally.\n * Matches domain label separators.\n */\nconst regexSeparators = /[\\x2E\\u3002\\uFF0E\\uFF61]/g;\n\n/**\n * Error messages used internally.\n */\nconst errors: Record<string, string> = {\n overflow: \"Overflow: input needs wider integers to process\",\n \"not-basic\": \"Illegal input >= 0x80 (not a basic code point)\",\n \"invalid-input\": \"Invalid input\"\n};\n\n/**\n * Aliases of `Math.floor`.\n */\nconst floor = Math.floor;\n/** \n * Aliases of `String.fromCharCode`.\n\n*/\nconst stringFromCharCode = String.fromCharCode;\n\n/** ---------------------------------------------------------\n * * ***Throws a RangeError with a predefined error message.***\n * ---------------------------------------------------------\n *\n * @param type - Key of the error type to throw.\n */\nfunction error(type: keyof typeof errors): never {\n throw new RangeError(errors[type]);\n}\n\n/** ---------------------------------------------------------\n * * ***Maps an array using a callback function.***\n * ---------------------------------------------------------\n *\n * @param array - Array to transform.\n * @param fn - Function to apply to each element.\n * @returns Transformed array.\n */\nfunction map<T, U>(array: T[], fn: (v: T) => U): U[] {\n const result: U[] = [];\n let length = array.length;\n while (length--) {\n if (array[length]) {\n result[length] = fn(array[length]!);\n }\n }\n return result;\n}\n\n/** ---------------------------------------------------------\n * * ***Maps a domain name using a callback on each label.***\n * ---------------------------------------------------------\n *\n * Handles email-like domains (local@domain).\n * @param domain - Domain string to process.\n * @param fn - Function applied to each domain label.\n * @returns Transformed domain string.\n */\nfunction mapDomain(domain: string, fn: (v: string) => string): string {\n const parts = domain.split(\"@\");\n let result = \"\";\n if (parts.length > 1) {\n result = parts[0] + \"@\";\n if (parts[1]) domain = parts[1];\n }\n domain = domain.replace(regexSeparators, \"\\x2E\");\n const labels = domain.split(\".\");\n return result + map(labels, fn).join(\".\");\n}\n\n/** ---------------------------------------------------------\n * * ***Converts a UCS-2 encoded string to an array of Unicode code points.***\n * ---------------------------------------------------------\n *\n * @param input - String to decode.\n * @returns Array of Unicode code points.\n */\nfunction ucs2decode(input: string): number[] {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.ucs2.decode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: number[] = [];\n let counter = 0;\n const length = input.length;\n while (counter < length) {\n const value = input.charCodeAt(counter++);\n if (value >= 0xd800 && value <= 0xdbff && counter < length) {\n const extra = input.charCodeAt(counter++);\n if ((extra & 0xfc00) === 0xdc00)\n output.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);\n else {\n output.push(value);\n counter--;\n }\n } else output.push(value);\n }\n return output;\n}\n\n/** ---------------------------------------------------------\n * * ***Encodes an array of Unicode code points to a string.***\n * ---------------------------------------------------------\n *\n * @param points - Array of Unicode code points.\n * @returns Encoded string.\n */\nconst ucs2encode = (points: number[]): string => {\n if (\n !Array.isArray(points) ||\n !points.every((p) => typeof p === \"number\" && Number.isFinite(p))\n ) {\n throw new TypeError(\n `Utils \\`punycodeUtilsJS.ucs2.encode\\`, parameter \\`points\\` must be an array of numbers, but received: \\`${getPreciseType(\n points\n )}\\`.`\n );\n }\n\n return String.fromCodePoint(...points);\n};\n\n/** ---------------------------------------------------------\n * * ***Converts a basic code point to its digit value for `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param codePoint - Unicode code point.\n * @returns Digit value.\n */\nfunction basicToDigit(codePoint: number): number {\n if (codePoint >= 0x30 && codePoint < 0x3a) return 26 + (codePoint - 0x30);\n if (codePoint >= 0x41 && codePoint < 0x5b) return codePoint - 0x41;\n if (codePoint >= 0x61 && codePoint < 0x7b) return codePoint - 0x61;\n return base;\n}\n\n/** ---------------------------------------------------------\n * * ***Converts a digit to a basic code point for `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param digit - Numeric value.\n * @param flag - Bias flag (0 or 1).\n * @returns Code point.\n */\nfunction digitToBasic(digit: number, flag: number): number {\n return digit + 22 + 75 * (digit < 26 ? 1 : 0) - Number(flag !== 0) * 32;\n}\n\n/** ---------------------------------------------------------\n * * ***Bias adaptation function for `Punycode-UtilsJS` encoding/decoding.***\n * ---------------------------------------------------------\n *\n * @param delta - Delta value.\n * @param numPoints - Number of code points.\n * @param firstTime - Indicates first adaptation.\n * @returns Adapted bias.\n */\nfunction adapt(delta: number, numPoints: number, firstTime: boolean): number {\n let k = 0;\n delta = firstTime ? floor(delta / damp) : delta >> 1;\n delta += floor(delta / numPoints);\n while (delta > ((base - tMin) * tMax) >> 1) {\n delta = floor(delta / (base - tMin));\n k += base;\n }\n return floor(k + ((base - tMin + 1) * delta) / (delta + skew));\n}\n\n/** ---------------------------------------------------------\n * * ***Decodes a `Punycode-UtilsJS` string to Unicode.***\n * ---------------------------------------------------------\n *\n * @param input - `Punycode-UtilsJS` string.\n * @returns Decoded Unicode string.\n */\nfunction decode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.decode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: number[] = [];\n const inputLength = input.length;\n let i = 0,\n n = initialN,\n bias = initialBias;\n\n let basic = input.lastIndexOf(delimiter);\n if (basic < 0) basic = 0;\n\n for (let j = 0; j < basic; j++) {\n if (input.charCodeAt(j) >= 0x80) error(\"not-basic\");\n output.push(input.charCodeAt(j));\n }\n\n for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; ) {\n const oldi = i;\n let w = 1;\n for (let k = base; ; k += base) {\n if (index >= inputLength) error(\"invalid-input\");\n const digit = basicToDigit(input.charCodeAt(index++));\n if (digit >= base) error(\"invalid-input\");\n if (digit > floor((maxInt - i) / w)) error(\"overflow\");\n i += digit * w;\n const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;\n if (digit < t) break;\n const baseMinusT = base - t;\n if (w > floor(maxInt / baseMinusT)) error(\"overflow\");\n w *= baseMinusT;\n }\n const out = output.length + 1;\n bias = adapt(i - oldi, out, oldi === 0);\n if (floor(i / out) > maxInt - n) error(\"overflow\");\n n += floor(i / out);\n i %= out;\n output.splice(i++, 0, n);\n }\n return String.fromCodePoint(...output);\n}\n\n/** ---------------------------------------------------------\n * * ***Encodes a Unicode string to `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param input - Unicode string.\n * @returns `Punycode-UtilsJS` string.\n */\nfunction encode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.encode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: string[] = [];\n const points = ucs2decode(input);\n const inputLength = points.length;\n let n = initialN,\n delta = 0,\n bias = initialBias;\n\n for (const cp of points) if (cp < 0x80) output.push(stringFromCharCode(cp));\n const basicLength = output.length;\n let handledCPCount = basicLength;\n if (basicLength) output.push(delimiter);\n\n while (handledCPCount < inputLength) {\n let m = maxInt;\n for (const cp of points) if (cp >= n && cp < m) m = cp;\n\n const handledCPCountPlusOne = handledCPCount + 1;\n if (m - n > floor((maxInt - delta) / handledCPCountPlusOne))\n error(\"overflow\");\n delta += (m - n) * handledCPCountPlusOne;\n n = m;\n\n for (const cp of points) {\n if (cp < n) delta++;\n if (cp === n) {\n let q = delta;\n for (let k = base; ; k += base) {\n const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;\n if (q < t) break;\n output.push(\n stringFromCharCode(digitToBasic(t + ((q - t) % (base - t)), 0))\n );\n q = floor((q - t) / (base - t));\n }\n output.push(stringFromCharCode(digitToBasic(q, 0)));\n bias = adapt(\n delta,\n handledCPCountPlusOne,\n handledCPCount === basicLength\n );\n delta = 0;\n handledCPCount++;\n }\n }\n delta++;\n n++;\n }\n\n return output.join(\"\");\n}\n\n/** ---------------------------------------------------------\n * * ***Converts `Punycode-UtilsJS` to Unicode for domain names.***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label.\n * @returns Unicode string.\n */\nfunction toUnicode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.toUnicode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n return mapDomain(input, (str) =>\n regexPunycode.test(str) ? decode(str.slice(4).toLowerCase()) : str\n );\n}\n\n/** ---------------------------------------------------------\n * * ***Converts Unicode to ASCII (`Punycode-UtilsJS`) for domain names.***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label.\n * @returns ASCII string.\n */\nfunction toASCII(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.toASCII\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n return mapDomain(input, (str) =>\n regexNonASCII.test(str) ? \"xn--\" + encode(str) : str\n );\n}\n\ntype PunycodeUtilsJS = {\n /** ---------------------------------------------------------\n * * ***Version of the `Punycode-UtilsJS` implementation.***\n * ---------------------------------------------------------\n *\n * @example\n * console.log(punycodeUtilsJS.version); // \"1.0.0\"\n */\n version: string;\n /** ---------------------------------------------------------\n * * ***UCS-2 utility functions.***\n * ---------------------------------------------------------\n */\n ucs2: {\n /** ---------------------------------------------------------\n * * ***Decodes a UCS-2 encoded string to an array of Unicode code points.***\n * ---------------------------------------------------------\n *\n * @param input - The UCS-2 string to decode.\n * @returns Array of Unicode code points.\n * @example\n * punycodeUtilsJS.ucs2.decode(\"π\");\n * // β [66376]\n */\n decode: (input: string) => number[];\n /** ---------------------------------------------------------\n * * ***Encodes an array of Unicode code points to a UCS-2 string.***\n * ---------------------------------------------------------\n *\n * @param points - Array of Unicode code points.\n * @returns Encoded string.\n * @example\n * punycodeUtilsJS.ucs2.encode([66376]);\n * // β \"π\"\n */\n encode: (points: number[]) => string;\n };\n /** ---------------------------------------------------------\n * * ***Decodes a `Punycode-UtilsJS` string to a Unicode string.***\n * ---------------------------------------------------------\n *\n * @param input - The `Punycode-UtilsJS` string to decode.\n * @returns Decoded Unicode string.\n * @example\n * punycodeUtilsJS.decode(\"xn--fsq\");\n * // β \"ΓΌ\"\n */\n decode: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Encodes a Unicode string to `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param input - Unicode string to encode.\n * @returns `Punycode-UtilsJS` string.\n * @example\n * punycodeUtilsJS.encode(\"ΓΌ\");\n * // β \"xn--fsq\"\n */\n encode: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Converts a Unicode domain or label to ASCII (`Punycode-UtilsJS`).***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label string.\n * @returns ASCII string suitable for DNS.\n * @example\n * punycodeUtilsJS.toASCII(\"ΠΏΡΠΈΠΌΠ΅Ρ.ΡΡ\");\n * // β \"xn--e1afmkfd.xn--p1ai\"\n */\n toASCII: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Converts an ASCII (`Punycode-UtilsJS`) domain or label to Unicode.***\n * ---------------------------------------------------------\n *\n * @param input - ASCII string (with xn-- prefix if needed).\n * @returns Unicode string.\n * @example\n * punycodeUtilsJS.toUnicode(\"xn--e1afmkfd.xn--p1ai\");\n * // β \"ΠΏΡΠΈΠΌΠ΅Ρ.ΡΡ\"\n */\n toUnicode: (input: string) => string;\n};\n\n/** ---------------------------------------------------------\n * * ***`Punycode-UtilsJS` object exposing all API functions and version.***\n * ---------------------------------------------------------\n * Provides encoding and decoding of Unicode domain names to ASCII (`Punycode-UtilsJS`)\n * and vice versa.\n *\n * - Useful for IDN (Internationalized Domain Names) support.\n */\nconst punycodeUtilsJS: PunycodeUtilsJS = {\n version: \"1.0.0\",\n ucs2: {\n decode: ucs2decode,\n encode: ucs2encode\n },\n decode: decode,\n encode: encode,\n toASCII: toASCII,\n toUnicode: toUnicode\n};\n\n/**\n * Export individual functions.\n */\nexport { punycodeUtilsJS };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,SAAS;;;;AAKf,MAAM,OAAO,IACX,OAAO,GACP,OAAO,IACP,OAAO,IACP,OAAO;;;;AAKT,MAAM,cAAc,IAClB,WAAW,KACX,YAAY;;;;;AAMd,MAAM,gBAAgB;;;;;AAKtB,MAAM,gBAAgB;;;;;AAKtB,MAAM,kBAAkB;;;;AAKxB,MAAM,SAAiC;CACrC,UAAU;CACV,aAAa;CACb,iBAAiB;CAClB;;;;AAKD,MAAM,QAAQ,KAAK;;;;;AAKnB,MAAM,qBAAqB,OAAO;;;;;;;AAQlC,SAAS,MAAM,MAAkC;CAC/C,MAAM,IAAI,WAAW,OAAO,MAAM;;;;;;;;;;AAWpC,SAAS,IAAU,OAAY,IAAsB;CACnD,MAAM,SAAc,EAAE;CACtB,IAAI,SAAS,MAAM;CACnB,OAAO,UACL,IAAI,MAAM,SACR,OAAO,UAAU,GAAG,MAAM,QAAS;CAGvC,OAAO;;;;;;;;;;;AAYT,SAAS,UAAU,QAAgB,IAAmC;CACpE,MAAM,QAAQ,OAAO,MAAM,IAAI;CAC/B,IAAI,SAAS;CACb,IAAI,MAAM,SAAS,GAAG;EACpB,SAAS,MAAM,KAAK;EACpB,IAAI,MAAM,IAAI,SAAS,MAAM;;CAE/B,SAAS,OAAO,QAAQ,iBAAiB,IAAO;CAChD,MAAM,SAAS,OAAO,MAAM,IAAI;CAChC,OAAO,SAAS,IAAI,QAAQ,GAAG,CAAC,KAAK,IAAI;;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AAO,MACL,OACA,uBACA,mBAAmB,YACpB;IACD,QAAQ;IACR;;;EAGJ;EACA;;CAGF,OAAO,OAAO,KAAK,GAAG;;;;;;;;;AAUxB,SAAS,UAAU,OAAuB;CACxC,sCAAe,OAAO,EACpB,UAAU,EAAE,aAAa,gBACvB,8EAA8E,UAAU,sBAAsB,YAAY,MAC7H,CAAC;CAEF,OAAO,UAAU,QAAQ,QACvB,cAAc,KAAK,IAAI,GAAG,OAAO,IAAI,MAAM,EAAE,CAAC,aAAa,CAAC,GAAG,IAChE;;;;;;;;;AAUH,SAAS,QAAQ,OAAuB;CACtC,sCAAe,OAAO,EACpB,UAAU,EAAE,aAAa,gBACvB,4EAA4E,UAAU,sBAAsB,YAAY,MAC3H,CAAC;CAEF,OAAO,UAAU,QAAQ,QACvB,cAAc,KAAK,IAAI,GAAG,SAAS,OAAO,IAAI,GAAG,IAClD;;;;;;;;;;AA8FH,MAAM,kBAAmC;CACvC,SAAS;CACT,MAAM;EACJ,QAAQ;EACR,QAAQ;EACT;CACO;CACA;CACC;CACE;CACZ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/utils-js
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `3.12.1-beta.1`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
import { A as isPlainObject, y as isNonEmptyString } from "./assertIsBoolean-DR1SaXPD.js";
|
|
11
|
+
const removeSpaces = (value, options = { trimOnly: false }) => {
|
|
12
|
+
if (!isNonEmptyString(value)) return "";
|
|
13
|
+
if (!isPlainObject(options)) options = {};
|
|
14
|
+
const { trimOnly = false } = options;
|
|
15
|
+
if (trimOnly) return value.trim();
|
|
16
|
+
return value.replace(/\s+/g, "");
|
|
17
|
+
};
|
|
18
|
+
export { removeSpaces as t };
|
|
19
|
+
//# sourceMappingURL=removeSpaces-Bmc5DX4F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeSpaces-Bmc5DX4F.js","names":[],"sources":["../src/strings/sanitizations/removeSpaces.ts"],"sourcesContent":["import { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\ntype RemoveSpacesOptions = {\n /** If `true`, only trims the string, defaultValue: `false`.\n *\n * @default false\n */\n trimOnly?: boolean;\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `removeSpaces`.***\n * ----------------------------------------------------------\n * **Removes all spaces from a string or trims only, based on the options provided.**\n * - **Behavior:**\n * - If `trimOnly` is `true`, the string is simply trimmed.\n * - Otherwise, removes **all spaces**, tabs, newlines, etc.\n * - If the input is `null` or `undefined`, returns an empty string `(\"\")`.\n * @param {string | null | undefined} value - The input string to be processed. If `null` or `undefined`, returns an empty string.\n * @param {RemoveSpacesOptions} [options] - The options object.\n * @param {RemoveSpacesOptions[\"trimOnly\"]} [options.trimOnly=false] - If `true`, only trims the string without removing spaces inside.\n * @returns {string} The processed string.\n * @example\n * removeSpaces(\" Hello World \");\n * // β \"HelloWorld\"\n * removeSpaces(\" Hello World \", { trimOnly: true });\n * // β \"Hello World\"\n * removeSpaces(null);\n * // β \"\"\n */\nexport const removeSpaces = (\n value: string | null | undefined,\n options: RemoveSpacesOptions = {\n trimOnly: false\n }\n): string => {\n if (!isNonEmptyString(value)) return \"\";\n\n if (!isPlainObject(options)) {\n options = {};\n }\n\n const { trimOnly = false } = options;\n\n if (trimOnly) return value.trim();\n\n // Remove all spaces (including tabs, newlines, etc.)\n return value.replace(/\\s+/g, \"\");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,gBACX,OACA,UAA+B,EAC7B,UAAU,OACX,KACU;CACX,IAAI,CAAC,iBAAiB,MAAM,EAAE,OAAO;CAErC,IAAI,CAAC,cAAc,QAAQ,EACzB,UAAU,EAAE;CAGd,MAAM,EAAE,WAAW,UAAU;CAE7B,IAAI,UAAU,OAAO,MAAM,MAAM;CAGjC,OAAO,MAAM,QAAQ,QAAQ,GAAG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/utils-js
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `3.12.1-beta.1`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
const require_assertIsBoolean = require('./assertIsBoolean-C8WEXVr2.cjs');
|
|
12
|
+
const removeSpaces = (value, options = { trimOnly: false }) => {
|
|
13
|
+
if (!require_assertIsBoolean.isNonEmptyString(value)) return "";
|
|
14
|
+
if (!require_assertIsBoolean.isPlainObject(options)) options = {};
|
|
15
|
+
const { trimOnly = false } = options;
|
|
16
|
+
if (trimOnly) return value.trim();
|
|
17
|
+
return value.replace(/\s+/g, "");
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, 'removeSpaces', {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return removeSpaces;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=removeSpaces-CWIvhZHg.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeSpaces-CWIvhZHg.cjs","names":["isNonEmptyString","isPlainObject"],"sources":["../src/strings/sanitizations/removeSpaces.ts"],"sourcesContent":["import { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\ntype RemoveSpacesOptions = {\n /** If `true`, only trims the string, defaultValue: `false`.\n *\n * @default false\n */\n trimOnly?: boolean;\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `removeSpaces`.***\n * ----------------------------------------------------------\n * **Removes all spaces from a string or trims only, based on the options provided.**\n * - **Behavior:**\n * - If `trimOnly` is `true`, the string is simply trimmed.\n * - Otherwise, removes **all spaces**, tabs, newlines, etc.\n * - If the input is `null` or `undefined`, returns an empty string `(\"\")`.\n * @param {string | null | undefined} value - The input string to be processed. If `null` or `undefined`, returns an empty string.\n * @param {RemoveSpacesOptions} [options] - The options object.\n * @param {RemoveSpacesOptions[\"trimOnly\"]} [options.trimOnly=false] - If `true`, only trims the string without removing spaces inside.\n * @returns {string} The processed string.\n * @example\n * removeSpaces(\" Hello World \");\n * // β \"HelloWorld\"\n * removeSpaces(\" Hello World \", { trimOnly: true });\n * // β \"Hello World\"\n * removeSpaces(null);\n * // β \"\"\n */\nexport const removeSpaces = (\n value: string | null | undefined,\n options: RemoveSpacesOptions = {\n trimOnly: false\n }\n): string => {\n if (!isNonEmptyString(value)) return \"\";\n\n if (!isPlainObject(options)) {\n options = {};\n }\n\n const { trimOnly = false } = options;\n\n if (trimOnly) return value.trim();\n\n // Remove all spaces (including tabs, newlines, etc.)\n return value.replace(/\\s+/g, \"\");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,gBACX,OACA,UAA+B,EAC7B,UAAU,OACX,KACU;CACX,IAAI,CAACA,yCAAiB,MAAM,EAAE,OAAO;CAErC,IAAI,CAACC,sCAAc,QAAQ,EACzB,UAAU,EAAE;CAGd,MAAM,EAAE,WAAW,UAAU;CAE7B,IAAI,UAAU,OAAO,MAAM,MAAM;CAGjC,OAAO,MAAM,QAAQ,QAAQ,GAAG"}
|