cizgile 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -31
- package/dist/index.d.mts +41 -2
- package/dist/index.mjs +112 -56
- package/dist/shared/locales-latin-Bm94HAeL.mjs +595 -0
- package/dist/shared/percent-DG-pZhJI.mjs +268 -0
- package/dist/shared/types-DbyhfPRc.d.mts +24 -0
- package/dist/transliterate.d.mts +126 -12
- package/dist/transliterate.mjs +545 -3
- package/dist/uri.d.mts +125 -0
- package/dist/uri.mjs +457 -5
- package/package.json +7 -2
- package/dist/shared/iri-CzbwHYgr.mjs +0 -572
- package/dist/shared/locales-latin-D8enWKzw.mjs +0 -372
- package/dist/shared/types-C1iMvUXh.d.mts +0 -13
|
@@ -1,572 +0,0 @@
|
|
|
1
|
-
//#region src/uri/charset.ts
|
|
2
|
-
function inChars(chars, cp) {
|
|
3
|
-
return cp < 128 && chars.indexOf(String.fromCodePoint(cp)) !== -1;
|
|
4
|
-
}
|
|
5
|
-
function isAlpha(cp) {
|
|
6
|
-
return cp >= 65 && cp <= 90 || cp >= 97 && cp <= 122;
|
|
7
|
-
}
|
|
8
|
-
function isDigit(cp) {
|
|
9
|
-
return cp >= 48 && cp <= 57;
|
|
10
|
-
}
|
|
11
|
-
function isHexDigit(cp) {
|
|
12
|
-
return isDigit(cp) || cp >= 65 && cp <= 70 || cp >= 97 && cp <= 102;
|
|
13
|
-
}
|
|
14
|
-
function isScheme(text) {
|
|
15
|
-
return /^[A-Za-z][A-Za-z0-9+.-]*$/.test(text);
|
|
16
|
-
}
|
|
17
|
-
function isUnreserved(cp) {
|
|
18
|
-
return isAlpha(cp) || isDigit(cp) || inChars("-._~", cp);
|
|
19
|
-
}
|
|
20
|
-
function isGenDelim(cp) {
|
|
21
|
-
return inChars(":/?#[]@", cp);
|
|
22
|
-
}
|
|
23
|
-
function isSubDelim(cp) {
|
|
24
|
-
return inChars("!$&'()*+,;=", cp);
|
|
25
|
-
}
|
|
26
|
-
function isReserved(cp) {
|
|
27
|
-
return isGenDelim(cp) || isSubDelim(cp);
|
|
28
|
-
}
|
|
29
|
-
function isPchar(cp) {
|
|
30
|
-
return isUnreserved(cp) || isSubDelim(cp) || cp === 58 || cp === 64;
|
|
31
|
-
}
|
|
32
|
-
function isSegmentNzNc(cp) {
|
|
33
|
-
return isUnreserved(cp) || isSubDelim(cp) || cp === 64;
|
|
34
|
-
}
|
|
35
|
-
function isQueryChar(cp) {
|
|
36
|
-
return isPchar(cp) || cp === 47 || cp === 63;
|
|
37
|
-
}
|
|
38
|
-
function isWhatwgC0Safe(cp) {
|
|
39
|
-
return cp >= 32 && cp <= 126;
|
|
40
|
-
}
|
|
41
|
-
function isWhatwgFragmentSafe(cp) {
|
|
42
|
-
return cp >= 33 && cp <= 126 && !inChars("\"<>`", cp);
|
|
43
|
-
}
|
|
44
|
-
function isWhatwgQuerySafe(cp) {
|
|
45
|
-
return cp >= 33 && cp <= 126 && !inChars("\"#<>", cp);
|
|
46
|
-
}
|
|
47
|
-
function isWhatwgSpecialQuerySafe(cp) {
|
|
48
|
-
return isWhatwgQuerySafe(cp) && cp !== 39;
|
|
49
|
-
}
|
|
50
|
-
function isWhatwgPathSafe(cp) {
|
|
51
|
-
return isWhatwgQuerySafe(cp) && !inChars("?^`{}", cp);
|
|
52
|
-
}
|
|
53
|
-
function isWhatwgUserinfoSafe(cp) {
|
|
54
|
-
return isWhatwgPathSafe(cp) && !inChars("/:;=@[\\]|", cp);
|
|
55
|
-
}
|
|
56
|
-
function isWhatwgComponentSafe(cp) {
|
|
57
|
-
return isWhatwgUserinfoSafe(cp) && !inChars("$&+,", cp);
|
|
58
|
-
}
|
|
59
|
-
function isFormSafe(cp) {
|
|
60
|
-
return isAlpha(cp) || isDigit(cp) || inChars("*-._", cp);
|
|
61
|
-
}
|
|
62
|
-
const SETS = {
|
|
63
|
-
unreserved: isUnreserved,
|
|
64
|
-
pchar: isPchar,
|
|
65
|
-
"segment-nz-nc": isSegmentNzNc,
|
|
66
|
-
path: (cp) => isPchar(cp) || cp === 47,
|
|
67
|
-
query: isQueryChar,
|
|
68
|
-
fragment: isQueryChar,
|
|
69
|
-
userinfo: (cp) => isUnreserved(cp) || isSubDelim(cp) || cp === 58,
|
|
70
|
-
"whatwg-c0-control": isWhatwgC0Safe,
|
|
71
|
-
"whatwg-fragment": isWhatwgFragmentSafe,
|
|
72
|
-
"whatwg-query": isWhatwgQuerySafe,
|
|
73
|
-
"whatwg-special-query": isWhatwgSpecialQuerySafe,
|
|
74
|
-
"whatwg-path": isWhatwgPathSafe,
|
|
75
|
-
"whatwg-userinfo": isWhatwgUserinfoSafe,
|
|
76
|
-
"whatwg-component": isWhatwgComponentSafe,
|
|
77
|
-
form: isFormSafe
|
|
78
|
-
};
|
|
79
|
-
function resolveEncodeSet(set) {
|
|
80
|
-
return typeof set === "function" ? set : SETS[set];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/uri/parse.ts
|
|
85
|
-
const URI_REFERENCE = /^(?:([A-Za-z][A-Za-z0-9+.-]*):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?$/s;
|
|
86
|
-
function parseUri(input) {
|
|
87
|
-
const [, scheme, authority, path = "", query, fragment] = URI_REFERENCE.exec(input) ?? [];
|
|
88
|
-
const out = { path };
|
|
89
|
-
if (scheme !== void 0) out.scheme = scheme;
|
|
90
|
-
if (authority !== void 0) out.authority = authority;
|
|
91
|
-
if (query !== void 0) out.query = query;
|
|
92
|
-
if (fragment !== void 0) out.fragment = fragment;
|
|
93
|
-
return out;
|
|
94
|
-
}
|
|
95
|
-
function serializeUri(components) {
|
|
96
|
-
let out = "";
|
|
97
|
-
let path = components.path;
|
|
98
|
-
if (components.scheme !== void 0) out += components.scheme + ":";
|
|
99
|
-
if (components.authority !== void 0) {
|
|
100
|
-
out += "//" + components.authority;
|
|
101
|
-
if (path !== "" && !path.startsWith("/")) path = "/" + path;
|
|
102
|
-
} else if (path.startsWith("//")) path = "/." + path;
|
|
103
|
-
else if (components.scheme === void 0) {
|
|
104
|
-
if ((path.split("/", 1)[0] ?? "").includes(":")) path = "./" + path;
|
|
105
|
-
}
|
|
106
|
-
out += path;
|
|
107
|
-
if (components.query !== void 0) out += "?" + components.query;
|
|
108
|
-
if (components.fragment !== void 0) out += "#" + components.fragment;
|
|
109
|
-
return out;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/uri/utf8.ts
|
|
114
|
-
const HEX = "0123456789ABCDEF";
|
|
115
|
-
function hexByte(byte) {
|
|
116
|
-
return "%" + HEX[byte >> 4] + HEX[byte & 15];
|
|
117
|
-
}
|
|
118
|
-
function utf8Bytes(codePoint) {
|
|
119
|
-
const cp = codePoint >= 55296 && codePoint <= 57343 ? 65533 : codePoint;
|
|
120
|
-
if (cp < 128) return [cp];
|
|
121
|
-
if (cp < 2048) return [192 | cp >> 6, 128 | cp & 63];
|
|
122
|
-
if (cp < 65536) return [
|
|
123
|
-
224 | cp >> 12,
|
|
124
|
-
128 | cp >> 6 & 63,
|
|
125
|
-
128 | cp & 63
|
|
126
|
-
];
|
|
127
|
-
return [
|
|
128
|
-
240 | cp >> 18,
|
|
129
|
-
128 | cp >> 12 & 63,
|
|
130
|
-
128 | cp >> 6 & 63,
|
|
131
|
-
128 | cp & 63
|
|
132
|
-
];
|
|
133
|
-
}
|
|
134
|
-
function isContinuation(byte) {
|
|
135
|
-
return byte !== void 0 && (byte & 192) === 128;
|
|
136
|
-
}
|
|
137
|
-
function readUtf8(bytes, index) {
|
|
138
|
-
const b0 = bytes[index];
|
|
139
|
-
if (b0 === void 0) return void 0;
|
|
140
|
-
if (b0 < 128) return {
|
|
141
|
-
codePoint: b0,
|
|
142
|
-
length: 1
|
|
143
|
-
};
|
|
144
|
-
const b1 = bytes[index + 1];
|
|
145
|
-
if (b0 >= 194 && b0 <= 223) {
|
|
146
|
-
if (!isContinuation(b1)) return void 0;
|
|
147
|
-
return {
|
|
148
|
-
codePoint: (b0 & 31) << 6 | b1 & 63,
|
|
149
|
-
length: 2
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
const b2 = bytes[index + 2];
|
|
153
|
-
if (b0 >= 224 && b0 <= 239) {
|
|
154
|
-
if (!isContinuation(b1) || !isContinuation(b2)) return void 0;
|
|
155
|
-
if (b0 === 224 && b1 < 160) return void 0;
|
|
156
|
-
if (b0 === 237 && b1 > 159) return void 0;
|
|
157
|
-
return {
|
|
158
|
-
codePoint: (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63,
|
|
159
|
-
length: 3
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
const b3 = bytes[index + 3];
|
|
163
|
-
if (b0 >= 240 && b0 <= 244) {
|
|
164
|
-
if (!isContinuation(b1) || !isContinuation(b2) || !isContinuation(b3)) return void 0;
|
|
165
|
-
if (b0 === 240 && b1 < 144) return void 0;
|
|
166
|
-
if (b0 === 244 && b1 > 143) return void 0;
|
|
167
|
-
return {
|
|
168
|
-
codePoint: (b0 & 7) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63,
|
|
169
|
-
length: 4
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function readHexByte(input, index) {
|
|
174
|
-
if (input.codePointAt(index) !== 37) return -1;
|
|
175
|
-
const hex = input.slice(index + 1, index + 3);
|
|
176
|
-
if (!/^[0-9A-Fa-f]{2}$/.test(hex)) return -1;
|
|
177
|
-
return parseInt(hex, 16);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/uri/percent.ts
|
|
182
|
-
function percentEncode(input, keep = "unreserved") {
|
|
183
|
-
const keepFn = resolveEncodeSet(keep);
|
|
184
|
-
const plusForSpace = keep === "form";
|
|
185
|
-
let out = "";
|
|
186
|
-
for (const ch of input) {
|
|
187
|
-
const cp = ch.codePointAt(0) ?? 0;
|
|
188
|
-
if (cp < 128 && keepFn(cp)) out += ch;
|
|
189
|
-
else if (plusForSpace && cp === 32) out += "+";
|
|
190
|
-
else for (const byte of utf8Bytes(cp)) out += hexByte(byte);
|
|
191
|
-
}
|
|
192
|
-
return out;
|
|
193
|
-
}
|
|
194
|
-
function decodeBytes(bytes) {
|
|
195
|
-
let out = "";
|
|
196
|
-
let i = 0;
|
|
197
|
-
while (i < bytes.length) {
|
|
198
|
-
const char = readUtf8(bytes, i);
|
|
199
|
-
if (char === void 0) {
|
|
200
|
-
out += "�";
|
|
201
|
-
i += 1;
|
|
202
|
-
} else {
|
|
203
|
-
out += String.fromCodePoint(char.codePoint);
|
|
204
|
-
i += char.length;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return out;
|
|
208
|
-
}
|
|
209
|
-
function percentDecode(input, options = {}) {
|
|
210
|
-
let out = "";
|
|
211
|
-
let i = 0;
|
|
212
|
-
const bytes = [];
|
|
213
|
-
while (i < input.length) {
|
|
214
|
-
const byte = readHexByte(input, i);
|
|
215
|
-
if (byte !== -1) {
|
|
216
|
-
bytes.push(byte);
|
|
217
|
-
i += 3;
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (bytes.length > 0) {
|
|
221
|
-
out += decodeBytes(bytes);
|
|
222
|
-
bytes.length = 0;
|
|
223
|
-
}
|
|
224
|
-
const ch = input.charAt(i);
|
|
225
|
-
out += options.plusAsSpace && ch === "+" ? " " : ch;
|
|
226
|
-
i += 1;
|
|
227
|
-
}
|
|
228
|
-
if (bytes.length > 0) out += decodeBytes(bytes);
|
|
229
|
-
return out;
|
|
230
|
-
}
|
|
231
|
-
function normalizePercentEncoding(input) {
|
|
232
|
-
let out = "";
|
|
233
|
-
let i = 0;
|
|
234
|
-
while (i < input.length) {
|
|
235
|
-
const byte = readHexByte(input, i);
|
|
236
|
-
if (byte === -1) {
|
|
237
|
-
out += input.charAt(i);
|
|
238
|
-
i += 1;
|
|
239
|
-
} else {
|
|
240
|
-
out += isUnreserved(byte) ? String.fromCodePoint(byte) : hexByte(byte);
|
|
241
|
-
i += 3;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return out;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
//#endregion
|
|
248
|
-
//#region src/uri/path.ts
|
|
249
|
-
function removeLastSegment(output) {
|
|
250
|
-
const index = output.lastIndexOf("/");
|
|
251
|
-
return index === -1 ? "" : output.slice(0, index);
|
|
252
|
-
}
|
|
253
|
-
function removeDotSegments(path) {
|
|
254
|
-
let input = path;
|
|
255
|
-
let output = "";
|
|
256
|
-
while (input.length > 0) if (input.startsWith("../")) input = input.slice(3);
|
|
257
|
-
else if (input.startsWith("./")) input = input.slice(2);
|
|
258
|
-
else if (input.startsWith("/./")) input = input.slice(2);
|
|
259
|
-
else if (input === "/.") input = "/";
|
|
260
|
-
else if (input.startsWith("/../")) {
|
|
261
|
-
input = input.slice(3);
|
|
262
|
-
output = removeLastSegment(output);
|
|
263
|
-
} else if (input === "/..") {
|
|
264
|
-
input = "/";
|
|
265
|
-
output = removeLastSegment(output);
|
|
266
|
-
} else if (input === "." || input === "..") input = "";
|
|
267
|
-
else {
|
|
268
|
-
const start = input.startsWith("/") ? 1 : 0;
|
|
269
|
-
const next = input.indexOf("/", start);
|
|
270
|
-
const end = next === -1 ? input.length : next;
|
|
271
|
-
output += input.slice(0, end);
|
|
272
|
-
input = input.slice(end);
|
|
273
|
-
}
|
|
274
|
-
return output;
|
|
275
|
-
}
|
|
276
|
-
function normalizePath(path, options = {}) {
|
|
277
|
-
let out = normalizePercentEncoding(path);
|
|
278
|
-
if (out.startsWith("/")) out = removeDotSegments(out);
|
|
279
|
-
const mode = options.trailingSlash ?? "keep";
|
|
280
|
-
if (mode === "add" && out.length > 0 && !out.endsWith("/")) out += "/";
|
|
281
|
-
if (mode === "remove" && out.length > 1 && out.endsWith("/")) out = out.slice(0, -1);
|
|
282
|
-
return out;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
//#endregion
|
|
286
|
-
//#region src/uri/normalize.ts
|
|
287
|
-
const DEFAULT_PORTS = {
|
|
288
|
-
http: 80,
|
|
289
|
-
https: 443,
|
|
290
|
-
ws: 80,
|
|
291
|
-
wss: 443,
|
|
292
|
-
ftp: 21
|
|
293
|
-
};
|
|
294
|
-
function parseAuthority(authority) {
|
|
295
|
-
const at = authority.lastIndexOf("@");
|
|
296
|
-
const out = { host: "" };
|
|
297
|
-
let hostPort = authority;
|
|
298
|
-
if (at !== -1) {
|
|
299
|
-
out.userinfo = authority.slice(0, at);
|
|
300
|
-
hostPort = authority.slice(at + 1);
|
|
301
|
-
}
|
|
302
|
-
const bracket = hostPort.startsWith("[") ? hostPort.indexOf("]") : -1;
|
|
303
|
-
const colon = hostPort.lastIndexOf(":");
|
|
304
|
-
if (hostPort.startsWith("[") && bracket === -1) {
|
|
305
|
-
out.host = hostPort;
|
|
306
|
-
return out;
|
|
307
|
-
}
|
|
308
|
-
if (colon !== -1 && colon > bracket && /^:\d*$/.test(hostPort.slice(colon))) {
|
|
309
|
-
out.host = hostPort.slice(0, colon);
|
|
310
|
-
out.port = hostPort.slice(colon + 1);
|
|
311
|
-
} else out.host = hostPort;
|
|
312
|
-
return out;
|
|
313
|
-
}
|
|
314
|
-
function serializeAuthority(components) {
|
|
315
|
-
let out = "";
|
|
316
|
-
if (components.userinfo !== void 0) out += components.userinfo + "@";
|
|
317
|
-
out += components.host;
|
|
318
|
-
if (components.port !== void 0) out += ":" + components.port;
|
|
319
|
-
return out;
|
|
320
|
-
}
|
|
321
|
-
function normalizeUri(input, options = {}) {
|
|
322
|
-
const ports = options.defaultPorts ?? DEFAULT_PORTS;
|
|
323
|
-
const schemeBased = options.schemeBased ?? true;
|
|
324
|
-
const c = parseUri(input);
|
|
325
|
-
const scheme = c.scheme?.toLowerCase();
|
|
326
|
-
if (scheme !== void 0) c.scheme = scheme;
|
|
327
|
-
const defaultPort = scheme === void 0 || !schemeBased ? void 0 : ports[scheme];
|
|
328
|
-
if (c.authority !== void 0) {
|
|
329
|
-
const a = parseAuthority(c.authority);
|
|
330
|
-
const userinfo = options.userinfo ?? "keep";
|
|
331
|
-
if (userinfo === "strip") delete a.userinfo;
|
|
332
|
-
else if (a.userinfo !== void 0) {
|
|
333
|
-
if (userinfo === "strip-password") a.userinfo = a.userinfo.split(":", 1)[0] ?? "";
|
|
334
|
-
a.userinfo = normalizePercentEncoding(a.userinfo);
|
|
335
|
-
}
|
|
336
|
-
a.host = normalizePercentEncoding(a.host.replace(/[A-Z]+/g, (m) => m.toLowerCase()));
|
|
337
|
-
if (a.port !== void 0 && (a.port === "" || Number(a.port) === defaultPort)) delete a.port;
|
|
338
|
-
c.authority = serializeAuthority(a);
|
|
339
|
-
}
|
|
340
|
-
c.path = normalizePercentEncoding(c.path);
|
|
341
|
-
if (c.scheme !== void 0 || c.authority !== void 0) c.path = removeDotSegments(c.path);
|
|
342
|
-
if (schemeBased && c.scheme !== void 0 && c.authority !== void 0 && c.path === "") c.path = "/";
|
|
343
|
-
if (c.query !== void 0) c.query = normalizePercentEncoding(c.query);
|
|
344
|
-
if (c.fragment !== void 0) c.fragment = normalizePercentEncoding(c.fragment);
|
|
345
|
-
return serializeUri(c);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
//#endregion
|
|
349
|
-
//#region src/uri/punycode.ts
|
|
350
|
-
const BASE = 36;
|
|
351
|
-
const T_MIN = 1;
|
|
352
|
-
const T_MAX = 26;
|
|
353
|
-
const SKEW = 38;
|
|
354
|
-
const DAMP = 700;
|
|
355
|
-
const INITIAL_BIAS = 72;
|
|
356
|
-
const INITIAL_N = 128;
|
|
357
|
-
const DELIMITER = "-";
|
|
358
|
-
const PREFIX = "xn--";
|
|
359
|
-
function adapt(delta, numPoints, firstTime) {
|
|
360
|
-
let d = firstTime ? Math.floor(delta / DAMP) : delta >> 1;
|
|
361
|
-
d += Math.floor(d / numPoints);
|
|
362
|
-
let k = 0;
|
|
363
|
-
while (d > 455) {
|
|
364
|
-
d = Math.floor(d / 35);
|
|
365
|
-
k += BASE;
|
|
366
|
-
}
|
|
367
|
-
return k + Math.floor(36 * d / (d + SKEW));
|
|
368
|
-
}
|
|
369
|
-
function digit(value) {
|
|
370
|
-
return String.fromCodePoint(value + (value < 26 ? 97 : 22));
|
|
371
|
-
}
|
|
372
|
-
function digitValue(cp) {
|
|
373
|
-
if (cp >= 48 && cp <= 57) return cp - 22;
|
|
374
|
-
if (cp >= 65 && cp <= 90) return cp - 65;
|
|
375
|
-
if (cp >= 97 && cp <= 122) return cp - 97;
|
|
376
|
-
return -1;
|
|
377
|
-
}
|
|
378
|
-
function punycodeEncode(input) {
|
|
379
|
-
const points = Array.from(input, (ch) => ch.codePointAt(0) ?? 0);
|
|
380
|
-
let out = "";
|
|
381
|
-
for (const cp of points) if (cp < 128) out += String.fromCodePoint(cp);
|
|
382
|
-
const basicCount = out.length;
|
|
383
|
-
let handled = basicCount;
|
|
384
|
-
if (basicCount > 0) out += DELIMITER;
|
|
385
|
-
let n = INITIAL_N;
|
|
386
|
-
let delta = 0;
|
|
387
|
-
let bias = INITIAL_BIAS;
|
|
388
|
-
while (handled < points.length) {
|
|
389
|
-
let m = 1114112;
|
|
390
|
-
for (const cp of points) if (cp >= n && cp < m) m = cp;
|
|
391
|
-
delta += (m - n) * (handled + 1);
|
|
392
|
-
n = m;
|
|
393
|
-
for (const cp of points) {
|
|
394
|
-
if (cp < n) delta += 1;
|
|
395
|
-
if (cp === n) {
|
|
396
|
-
let q = delta;
|
|
397
|
-
for (let k = BASE;; k += BASE) {
|
|
398
|
-
const t = k <= bias ? T_MIN : k >= bias + T_MAX ? T_MAX : k - bias;
|
|
399
|
-
if (q < t) break;
|
|
400
|
-
out += digit(t + (q - t) % (BASE - t));
|
|
401
|
-
q = Math.floor((q - t) / (BASE - t));
|
|
402
|
-
}
|
|
403
|
-
out += digit(q);
|
|
404
|
-
bias = adapt(delta, handled + 1, handled === basicCount);
|
|
405
|
-
delta = 0;
|
|
406
|
-
handled += 1;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
delta += 1;
|
|
410
|
-
n += 1;
|
|
411
|
-
}
|
|
412
|
-
return out;
|
|
413
|
-
}
|
|
414
|
-
function punycodeDecode(input) {
|
|
415
|
-
const output = [];
|
|
416
|
-
const last = input.lastIndexOf(DELIMITER);
|
|
417
|
-
const basicEnd = last > 0 ? last : 0;
|
|
418
|
-
for (let i = 0; i < basicEnd; i++) {
|
|
419
|
-
const cp = input.codePointAt(i) ?? 0;
|
|
420
|
-
if (cp >= 128) throw new RangeError("punycodeDecode: invalid basic code point");
|
|
421
|
-
output.push(cp);
|
|
422
|
-
}
|
|
423
|
-
let n = INITIAL_N;
|
|
424
|
-
let bias = INITIAL_BIAS;
|
|
425
|
-
let i = 0;
|
|
426
|
-
let index = basicEnd > 0 ? basicEnd + 1 : 0;
|
|
427
|
-
while (index < input.length) {
|
|
428
|
-
const oldI = i;
|
|
429
|
-
let w = 1;
|
|
430
|
-
for (let k = BASE;; k += BASE) {
|
|
431
|
-
if (index >= input.length) throw new RangeError("punycodeDecode: truncated input");
|
|
432
|
-
const d = digitValue(input.codePointAt(index) ?? 0);
|
|
433
|
-
index += 1;
|
|
434
|
-
if (d < 0) throw new RangeError("punycodeDecode: invalid digit");
|
|
435
|
-
i += d * w;
|
|
436
|
-
const t = k <= bias ? T_MIN : k >= bias + T_MAX ? T_MAX : k - bias;
|
|
437
|
-
if (d < t) break;
|
|
438
|
-
w *= BASE - t;
|
|
439
|
-
}
|
|
440
|
-
const count = output.length + 1;
|
|
441
|
-
bias = adapt(i - oldI, count, oldI === 0);
|
|
442
|
-
n += Math.floor(i / count);
|
|
443
|
-
i %= count;
|
|
444
|
-
if (n > 1114111) throw new RangeError("punycodeDecode: code point out of range");
|
|
445
|
-
output.splice(i, 0, n);
|
|
446
|
-
i += 1;
|
|
447
|
-
}
|
|
448
|
-
return String.fromCodePoint(...output);
|
|
449
|
-
}
|
|
450
|
-
function isAsciiLabel(label) {
|
|
451
|
-
for (const ch of label) if ((ch.codePointAt(0) ?? 0) >= 128) return false;
|
|
452
|
-
return true;
|
|
453
|
-
}
|
|
454
|
-
function mapLabel(label) {
|
|
455
|
-
return label.replace(/\p{Cf}/gu, "").normalize("NFKC").toLowerCase().normalize("NFC").replace(/[\u3002\uFF0E\uFF61]/g, ".");
|
|
456
|
-
}
|
|
457
|
-
function domainToAscii(host) {
|
|
458
|
-
if (host.startsWith("[")) return host;
|
|
459
|
-
return host.split(/[.\u3002\uFF0E\uFF61]/).map((label) => {
|
|
460
|
-
if (isAsciiLabel(label)) return label;
|
|
461
|
-
const mapped = mapLabel(label);
|
|
462
|
-
if (mapped.includes(".")) return domainToAscii(mapped);
|
|
463
|
-
if (isAsciiLabel(mapped)) return mapped;
|
|
464
|
-
const encoded = PREFIX + punycodeEncode(mapped);
|
|
465
|
-
if (encoded.length > 63) throw new RangeError(`domainToAscii: label ${JSON.stringify(label)} exceeds 63 octets`);
|
|
466
|
-
return encoded;
|
|
467
|
-
}).join(".");
|
|
468
|
-
}
|
|
469
|
-
function domainToUnicode(host) {
|
|
470
|
-
if (host.startsWith("[")) return host;
|
|
471
|
-
return host.split(".").map((label) => {
|
|
472
|
-
const lower = label.toLowerCase();
|
|
473
|
-
return lower.startsWith(PREFIX) ? punycodeDecode(lower.slice(4)) : label;
|
|
474
|
-
}).join(".");
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
//#endregion
|
|
478
|
-
//#region src/uri/iri.ts
|
|
479
|
-
function isUcschar(cp) {
|
|
480
|
-
return cp >= 160 && cp <= 55295 || cp >= 63744 && cp <= 64975 || cp >= 65008 && cp <= 65519 || cp >= 65536 && cp <= 983037 && (cp & 65535) <= 65533 && !(cp >= 917504 && cp <= 921599);
|
|
481
|
-
}
|
|
482
|
-
function isIprivate(cp) {
|
|
483
|
-
return cp >= 57344 && cp <= 63743 || cp >= 983040 && cp <= 1048573 || cp >= 1048576 && cp <= 1114109;
|
|
484
|
-
}
|
|
485
|
-
const BIDI_CONTROLS = /\p{Bidi_Control}/u;
|
|
486
|
-
const BIDI_CONTROLS_GLOBAL = /\p{Bidi_Control}/gu;
|
|
487
|
-
const IRI_ASCII_MAY_ENCODE = "<>\"{}|\\^` ";
|
|
488
|
-
function isBidiControl(cp) {
|
|
489
|
-
return cp === 1564 || cp === 8206 || cp === 8207 || cp >= 8234 && cp <= 8238 || cp >= 8294 && cp <= 8297;
|
|
490
|
-
}
|
|
491
|
-
function hasBidiControls(input) {
|
|
492
|
-
return BIDI_CONTROLS.test(input);
|
|
493
|
-
}
|
|
494
|
-
function isIunreserved(cp) {
|
|
495
|
-
return isUnreserved(cp) || isUcschar(cp) && !isBidiControl(cp);
|
|
496
|
-
}
|
|
497
|
-
function isIpchar(cp) {
|
|
498
|
-
return isIunreserved(cp) || isSubDelim(cp) || cp === 58 || cp === 64;
|
|
499
|
-
}
|
|
500
|
-
function iriToUri(iri, options = {}) {
|
|
501
|
-
let input = iri;
|
|
502
|
-
if (hasBidiControls(input)) {
|
|
503
|
-
if ((options.bidi ?? "throw") === "throw") throw new RangeError("IRI contains bidi formatting characters (RFC 3987 section 4.1)");
|
|
504
|
-
input = input.replace(BIDI_CONTROLS_GLOBAL, "");
|
|
505
|
-
}
|
|
506
|
-
if (options.nfc === true) input = input.normalize("NFC");
|
|
507
|
-
if (options.host === "punycode") {
|
|
508
|
-
const c = parseUri(input);
|
|
509
|
-
if (c.authority !== void 0) {
|
|
510
|
-
const a = parseAuthority(c.authority);
|
|
511
|
-
a.host = domainToAscii(a.host);
|
|
512
|
-
c.authority = serializeAuthority(a);
|
|
513
|
-
input = serializeUri(c);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
const strict = options.strict ?? false;
|
|
517
|
-
let out = "";
|
|
518
|
-
for (const ch of input) {
|
|
519
|
-
const cp = ch.codePointAt(0) ?? 0;
|
|
520
|
-
if (cp < 128 && (isUnreserved(cp) || isReserved(cp) || cp === 37)) {
|
|
521
|
-
out += ch;
|
|
522
|
-
continue;
|
|
523
|
-
}
|
|
524
|
-
if (strict && !(cp < 128 ? IRI_ASCII_MAY_ENCODE.includes(ch) : isUcschar(cp) || isIprivate(cp))) throw new RangeError(`iriToUri: U+${cp.toString(16).toUpperCase().padStart(4, "0")} is not allowed in an IRI`);
|
|
525
|
-
for (const byte of utf8Bytes(cp)) out += hexByte(byte);
|
|
526
|
-
}
|
|
527
|
-
return out;
|
|
528
|
-
}
|
|
529
|
-
function decodeComponent(text, allowPrivate) {
|
|
530
|
-
let out = "";
|
|
531
|
-
let i = 0;
|
|
532
|
-
while (i < text.length) {
|
|
533
|
-
const first = readHexByte(text, i);
|
|
534
|
-
if (first === -1) {
|
|
535
|
-
out += text.charAt(i);
|
|
536
|
-
i += 1;
|
|
537
|
-
continue;
|
|
538
|
-
}
|
|
539
|
-
const bytes = [];
|
|
540
|
-
let j = i;
|
|
541
|
-
for (let byte = first; byte !== -1; byte = readHexByte(text, j)) {
|
|
542
|
-
bytes.push(byte);
|
|
543
|
-
j += 3;
|
|
544
|
-
}
|
|
545
|
-
let k = 0;
|
|
546
|
-
while (k < bytes.length) {
|
|
547
|
-
const char = readUtf8(bytes, k);
|
|
548
|
-
const cp = char?.codePoint ?? -1;
|
|
549
|
-
if (char !== void 0 && (isUnreserved(cp) || isUcschar(cp) && !isBidiControl(cp) || allowPrivate && isIprivate(cp))) {
|
|
550
|
-
out += String.fromCodePoint(cp);
|
|
551
|
-
k += char.length;
|
|
552
|
-
} else {
|
|
553
|
-
out += text.slice(i + k * 3, i + k * 3 + 3);
|
|
554
|
-
k += 1;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
i = j;
|
|
558
|
-
}
|
|
559
|
-
return out;
|
|
560
|
-
}
|
|
561
|
-
function uriToIri(uri) {
|
|
562
|
-
const c = parseUri(uri);
|
|
563
|
-
if (c.scheme === void 0 && c.authority === void 0 && c.query === void 0 && c.fragment === void 0) return decodeComponent(uri, false);
|
|
564
|
-
if (c.authority !== void 0) c.authority = decodeComponent(c.authority, false);
|
|
565
|
-
c.path = decodeComponent(c.path, false);
|
|
566
|
-
if (c.query !== void 0) c.query = decodeComponent(c.query, true);
|
|
567
|
-
if (c.fragment !== void 0) c.fragment = decodeComponent(c.fragment, false);
|
|
568
|
-
return serializeUri(c);
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
//#endregion
|
|
572
|
-
export { isQueryChar as A, parseUri as C, isGenDelim as D, isDigit as E, isUnreserved as F, resolveEncodeSet as I, isScheme as M, isSegmentNzNc as N, isHexDigit as O, isSubDelim as P, readHexByte as S, isAlpha as T, normalizePath as _, isIprivate as a, percentDecode as b, uriToIri as c, punycodeDecode as d, punycodeEncode as f, serializeAuthority as g, parseAuthority as h, isIpchar as i, isReserved as j, isPchar as k, domainToAscii as l, normalizeUri as m, iriToUri as n, isIunreserved as o, DEFAULT_PORTS as p, isBidiControl as r, isUcschar as s, hasBidiControls as t, domainToUnicode as u, removeDotSegments as v, serializeUri as w, percentEncode as x, normalizePercentEncoding as y };
|