@coroboros/uri 1.0.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/CHANGELOG.md +5 -0
- package/LICENSE.md +21 -0
- package/README.md +990 -0
- package/dist/index.cjs +1665 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +560 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +560 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1639 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +93 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
//#region src/parser/index.d.ts
|
|
2
|
+
interface ParsedURI {
|
|
3
|
+
scheme: string | null;
|
|
4
|
+
authority: string | null;
|
|
5
|
+
authorityPunydecoded: string | null;
|
|
6
|
+
userinfo: string | null;
|
|
7
|
+
host: string | null;
|
|
8
|
+
hostPunydecoded: string | null;
|
|
9
|
+
port: number | string | null;
|
|
10
|
+
path: string | null;
|
|
11
|
+
pathqf: string | null;
|
|
12
|
+
query: string | null;
|
|
13
|
+
fragment: string | null;
|
|
14
|
+
href: string | null;
|
|
15
|
+
}
|
|
16
|
+
interface URIComponents {
|
|
17
|
+
scheme?: string | null;
|
|
18
|
+
userinfo?: string | null;
|
|
19
|
+
host?: string | null;
|
|
20
|
+
port?: number | string | null;
|
|
21
|
+
path?: string | null;
|
|
22
|
+
query?: string | null;
|
|
23
|
+
fragment?: string | null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @func recomposeURI
|
|
27
|
+
*
|
|
28
|
+
* Recompose an URI from its components with basic URI checking.
|
|
29
|
+
*
|
|
30
|
+
* The empty string is returned if unable to recompose the URI.
|
|
31
|
+
*
|
|
32
|
+
* Rules:
|
|
33
|
+
* 1. scheme is required and must be at least 1 character;
|
|
34
|
+
* 2. path is required and can be empty;
|
|
35
|
+
* 3. if host is present path must be empty or start with /;
|
|
36
|
+
* 4. if host is not present path must not start with //;
|
|
37
|
+
* 5. host, if any, must be at least 3 characters;
|
|
38
|
+
* 6. userinfo will be ignored if empty;
|
|
39
|
+
* 7. port will be ignored if empty or not an integer;
|
|
40
|
+
* 8. query is emitted when defined (a string, including ''); a null
|
|
41
|
+
* or undefined query is omitted (RFC-3986 §5.3);
|
|
42
|
+
* 9. fragment is emitted when defined (a string, including ''); a null
|
|
43
|
+
* or undefined fragment is omitted (RFC-3986 §5.3).
|
|
44
|
+
*
|
|
45
|
+
* Support:
|
|
46
|
+
* - IPv4 and IPv6.
|
|
47
|
+
*
|
|
48
|
+
* Note:
|
|
49
|
+
* / is added to any URI with a host and an empty path.
|
|
50
|
+
*
|
|
51
|
+
* Based on:
|
|
52
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986.
|
|
53
|
+
*/
|
|
54
|
+
declare const recomposeURI: (components?: URIComponents) => string;
|
|
55
|
+
/**
|
|
56
|
+
* @func parseURI
|
|
57
|
+
*
|
|
58
|
+
* Parse a string to get URI components.
|
|
59
|
+
*
|
|
60
|
+
* Support:
|
|
61
|
+
* - IPv4 and IPv6 hosts;
|
|
62
|
+
* - Internationalized Domain Name (IDN).
|
|
63
|
+
*
|
|
64
|
+
* Note:
|
|
65
|
+
* - RegExp from RFC-3986 https://tools.ietf.org/html/rfc3986#appendix-B;
|
|
66
|
+
* - scheme and host strings will always be put in lowercase once parsed,
|
|
67
|
+
* as specified in RFC-3986;
|
|
68
|
+
* - authority and its components will be put at null values if authority
|
|
69
|
+
* parsed is missing or empty.
|
|
70
|
+
*
|
|
71
|
+
* Based on:
|
|
72
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986.
|
|
73
|
+
*/
|
|
74
|
+
declare const parseURI: (uri: string) => ParsedURI;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/checkers/index.d.ts
|
|
77
|
+
interface CheckedURI extends ParsedURI {
|
|
78
|
+
valid: true;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @func checkURI
|
|
82
|
+
*
|
|
83
|
+
* Check an URI is valid according to RFC-3986.
|
|
84
|
+
*
|
|
85
|
+
* Rules:
|
|
86
|
+
* 1. scheme is required and cannot be empty;
|
|
87
|
+
* 2. path is required and can be empty;
|
|
88
|
+
* 3. if authority is present path must be empty or start with /;
|
|
89
|
+
* 4. if authority is not present path must not start with //;
|
|
90
|
+
* 5. scheme can only have specific characters:
|
|
91
|
+
* https://tools.ietf.org/html/rfc3986#section-3.1;
|
|
92
|
+
* 6. if authority is present:
|
|
93
|
+
* 1. host must be a valid IP or domain name;
|
|
94
|
+
* 2. userinfo, if any, can only have specific characters:
|
|
95
|
+
* https://tools.ietf.org/html/rfc3986#section-3.2.1;
|
|
96
|
+
* 3. port, if any, must be an integer in a specific range.
|
|
97
|
+
* 7. path, query and fragment can only have specific characters:
|
|
98
|
+
* https://tools.ietf.org/html/rfc3986#section-3.3.
|
|
99
|
+
*/
|
|
100
|
+
declare const checkURI: (uri: string, {
|
|
101
|
+
sitemap
|
|
102
|
+
}?: {
|
|
103
|
+
sitemap?: boolean | undefined;
|
|
104
|
+
}) => CheckedURI;
|
|
105
|
+
/**
|
|
106
|
+
* @func checkHttpURL
|
|
107
|
+
*
|
|
108
|
+
* Check an URI is a valid HTTP URL (sitemap URLs supported to create aliases).
|
|
109
|
+
*
|
|
110
|
+
* This function uses checkURI to check URI provided is valid.
|
|
111
|
+
*
|
|
112
|
+
* Rules:
|
|
113
|
+
* 1. scheme must be http or HTTP;
|
|
114
|
+
* 2. authority is required;
|
|
115
|
+
* 3. URL must be less than max length.
|
|
116
|
+
*
|
|
117
|
+
* Based on:
|
|
118
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986;
|
|
119
|
+
* - https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190.
|
|
120
|
+
*/
|
|
121
|
+
declare const checkHttpURL: (uri: string, {
|
|
122
|
+
https,
|
|
123
|
+
web,
|
|
124
|
+
sitemap
|
|
125
|
+
}?: {
|
|
126
|
+
https?: boolean | undefined;
|
|
127
|
+
web?: boolean | undefined;
|
|
128
|
+
sitemap?: boolean | undefined;
|
|
129
|
+
}) => CheckedURI;
|
|
130
|
+
/**
|
|
131
|
+
* @func checkHttpsURL
|
|
132
|
+
*
|
|
133
|
+
* Check an URI is a valid HTTPS URL.
|
|
134
|
+
*
|
|
135
|
+
* Same behavior than checkHttpURL except scheme must be https or HTTPS.
|
|
136
|
+
*/
|
|
137
|
+
declare const checkHttpsURL: (uri: string) => CheckedURI;
|
|
138
|
+
/**
|
|
139
|
+
* @func checkHttpSitemapURL
|
|
140
|
+
*
|
|
141
|
+
* Check an URI is a valid HTTP URL to be used in an XML sitemap file.
|
|
142
|
+
*
|
|
143
|
+
* This function uses checkHttpURL to check URI provided is a valid HTTP URL.
|
|
144
|
+
*
|
|
145
|
+
* Rules:
|
|
146
|
+
* 1. scheme must be http;
|
|
147
|
+
* 2. authority is required;
|
|
148
|
+
* 3. specific characters must be escaped;
|
|
149
|
+
* 4. can only contain lowercase characters;
|
|
150
|
+
* 5. URL must be less than max length.
|
|
151
|
+
*
|
|
152
|
+
* Based on:
|
|
153
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986;
|
|
154
|
+
* - https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190.
|
|
155
|
+
*/
|
|
156
|
+
declare const checkHttpSitemapURL: (uri: string) => CheckedURI;
|
|
157
|
+
/**
|
|
158
|
+
* @func checkHttpsSitemapURL
|
|
159
|
+
*
|
|
160
|
+
* Check an URI is a valid HTTPS URL to be used in an XML sitemap file.
|
|
161
|
+
* Same behavior than checkHttpSitemapURL except scheme must be https.
|
|
162
|
+
*/
|
|
163
|
+
declare const checkHttpsSitemapURL: (uri: string) => CheckedURI;
|
|
164
|
+
/**
|
|
165
|
+
* @func checkWebURL
|
|
166
|
+
*
|
|
167
|
+
* Check an URI is a valid HTTP or HTTPS URL.
|
|
168
|
+
*
|
|
169
|
+
* Same behavior than checkHttpURL except scheme can be http/HTTP or https/HTTPS.
|
|
170
|
+
*/
|
|
171
|
+
declare const checkWebURL: (uri: string) => CheckedURI;
|
|
172
|
+
/**
|
|
173
|
+
* @func checkSitemapURL
|
|
174
|
+
*
|
|
175
|
+
* Check an URI is a valid HTTP or HTTPS URL to be used in an XML sitemap file.
|
|
176
|
+
*
|
|
177
|
+
* Same behavior than checkHttpSitemapURL except scheme can be http or https.
|
|
178
|
+
*/
|
|
179
|
+
declare const checkSitemapURL: (uri: string) => CheckedURI;
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/decoders/index.d.ts
|
|
182
|
+
/**
|
|
183
|
+
* @func decodeURIComponentString
|
|
184
|
+
*
|
|
185
|
+
* Decode an URI component string with Sitemap's escape codes support.
|
|
186
|
+
*
|
|
187
|
+
* Native function decodeURIComponent could throw and to be consistent with
|
|
188
|
+
* encodeURIComponentString the empty string is returned if unable to decode.
|
|
189
|
+
*
|
|
190
|
+
* Based on:
|
|
191
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986;
|
|
192
|
+
* - https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190.
|
|
193
|
+
*/
|
|
194
|
+
declare const decodeURIComponentString: (component: string, {
|
|
195
|
+
sitemap,
|
|
196
|
+
lowercase
|
|
197
|
+
}?: {
|
|
198
|
+
sitemap?: boolean | undefined;
|
|
199
|
+
lowercase?: boolean | undefined;
|
|
200
|
+
}) => string;
|
|
201
|
+
/**
|
|
202
|
+
* @func decodeURIString
|
|
203
|
+
*
|
|
204
|
+
* Decode an URI string according to RFC-3986 with basic checking.
|
|
205
|
+
*
|
|
206
|
+
* Checked:
|
|
207
|
+
* - scheme is required;
|
|
208
|
+
* - path is required, can be empty;
|
|
209
|
+
* - port, if any, must be an integer in a specific range;
|
|
210
|
+
* - host must be a valid ip or domain name;
|
|
211
|
+
* - maximum size once encoded for URLs.
|
|
212
|
+
*
|
|
213
|
+
* Support:
|
|
214
|
+
* - IDNs: returns URI with its Punydecoded host (Unicode serialization of the domain), if any;
|
|
215
|
+
* - lower and upper case.
|
|
216
|
+
*
|
|
217
|
+
* Note:
|
|
218
|
+
* - if one of userinfo, path, query or fragment component cannot be decoded, it will be ignored;
|
|
219
|
+
* - native function decodeURI does not support IDNs and cannot properly work
|
|
220
|
+
* with encodeURI since the function is based on an outdated standard;
|
|
221
|
+
* - to stay fully RFC-3986 compliant, scheme and host are put in lowercase;
|
|
222
|
+
* - to only use with encodeURIString.
|
|
223
|
+
*
|
|
224
|
+
* Based on:
|
|
225
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986;
|
|
226
|
+
* - https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190.
|
|
227
|
+
*/
|
|
228
|
+
declare const decodeURIString: (uri: string, {
|
|
229
|
+
web,
|
|
230
|
+
sitemap,
|
|
231
|
+
lowercase
|
|
232
|
+
}?: {
|
|
233
|
+
web?: boolean | undefined;
|
|
234
|
+
sitemap?: boolean | undefined;
|
|
235
|
+
lowercase?: boolean | undefined;
|
|
236
|
+
}) => string;
|
|
237
|
+
/**
|
|
238
|
+
* @func decodeWebURL
|
|
239
|
+
*
|
|
240
|
+
* Decode an URI string with basic checking based on RFC-3986 standard applied
|
|
241
|
+
* to HTTP and HTTPS URLs.
|
|
242
|
+
*
|
|
243
|
+
* Uses a fixed decodeURI function to be RFC-3986 compliant.
|
|
244
|
+
*
|
|
245
|
+
* Checked:
|
|
246
|
+
* - scheme must be http/HTTP or https/HTTPS;
|
|
247
|
+
* - path is required, can be empty;
|
|
248
|
+
* - authority is required;
|
|
249
|
+
* - port, if any, must be an integer in a specific range;
|
|
250
|
+
* - parseURI prechecked host, will be null if invalid and so does authority.
|
|
251
|
+
*
|
|
252
|
+
* Support:
|
|
253
|
+
* - IDNs: returns URI with its Punydecoded host
|
|
254
|
+
* (Unicode serialization of the domain), if any;
|
|
255
|
+
* - lower and upper case.
|
|
256
|
+
*
|
|
257
|
+
* Note:
|
|
258
|
+
* - native function decodeURI does not support IDNs and cannot properly work
|
|
259
|
+
* with encodeURI since the function is based on an outdated standard;
|
|
260
|
+
* - to stay fully RFC-3986 compliant, scheme and host are put in lowercase;
|
|
261
|
+
* - to use only with encodeWebURL.
|
|
262
|
+
*/
|
|
263
|
+
declare const decodeWebURL: (uri: string, {
|
|
264
|
+
lowercase
|
|
265
|
+
}?: {
|
|
266
|
+
lowercase?: boolean | undefined;
|
|
267
|
+
}) => string;
|
|
268
|
+
/**
|
|
269
|
+
* @func decodeSitemapURL
|
|
270
|
+
*
|
|
271
|
+
* Decode an URI string with basic checking based on RFC-3986 standard applied
|
|
272
|
+
* to HTTP and HTTPS URLs and sitemap requirements regarding escape codes to decode.
|
|
273
|
+
*
|
|
274
|
+
* Checked:
|
|
275
|
+
* - scheme must be http/HTTP or https/HTTPS;
|
|
276
|
+
* - path is required, can be empty;
|
|
277
|
+
* - authority is required;
|
|
278
|
+
* - port, if any, must be an integer in a specific range;
|
|
279
|
+
* - parseURI prechecked host, will be null if invalid and so does authority.
|
|
280
|
+
*
|
|
281
|
+
* Support:
|
|
282
|
+
* - Sitemap's escape codes;
|
|
283
|
+
* - IDNs: returns URI with its Punydecoded host
|
|
284
|
+
* (Unicode serialization of the domain), if any;
|
|
285
|
+
* - lower and upper case.
|
|
286
|
+
*
|
|
287
|
+
* Note:
|
|
288
|
+
* - native function decodeURI does not support IDNs and cannot properly work
|
|
289
|
+
* with encodeURI since the function is based on an outdated standard;
|
|
290
|
+
* - to stay fully RFC-3986 compliant, scheme and host are put in lowercase;
|
|
291
|
+
* - to use only with encodeSitemapURL.
|
|
292
|
+
*
|
|
293
|
+
* Based on:
|
|
294
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986;
|
|
295
|
+
* - https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190.
|
|
296
|
+
*/
|
|
297
|
+
declare const decodeSitemapURL: (uri: string, {
|
|
298
|
+
lowercase
|
|
299
|
+
}?: {
|
|
300
|
+
lowercase?: boolean | undefined;
|
|
301
|
+
}) => string;
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region src/domain/index.d.ts
|
|
304
|
+
/**
|
|
305
|
+
* @func isDomainLabel
|
|
306
|
+
*
|
|
307
|
+
* Test a label is a valid domain label according to RFC-1034.
|
|
308
|
+
*
|
|
309
|
+
* "Note that while upper and lower case letters are allowed in domain names,
|
|
310
|
+
* no significance is attached to the case. That is, two names with the same
|
|
311
|
+
* spelling but different case are to be treated as if identical."
|
|
312
|
+
*
|
|
313
|
+
* By convention uppercased domain label will be considered invalid.
|
|
314
|
+
*
|
|
315
|
+
* Rules:
|
|
316
|
+
* 1. "Labels must be 63 characters or less.";
|
|
317
|
+
* 2. can be minimum one character;
|
|
318
|
+
* 3. must only use lowercase letters, digits or hyphens;
|
|
319
|
+
* 4. must not start or end with a hyphen;
|
|
320
|
+
* 5. must not have consecutive hyphens;
|
|
321
|
+
* 6. can start or end with a digit.
|
|
322
|
+
*
|
|
323
|
+
* Based on:
|
|
324
|
+
* - RFC-1034 https://www.ietf.org/rfc/rfc1034.txt.
|
|
325
|
+
*/
|
|
326
|
+
declare const isDomainLabel: (label: string) => boolean;
|
|
327
|
+
/**
|
|
328
|
+
* @func isDomain
|
|
329
|
+
*
|
|
330
|
+
* Test a name is a valid domain according to RFC-1034.
|
|
331
|
+
*
|
|
332
|
+
* Supports Fully-Qualified Domain Name (FQDN) and Internationalized Domain Name (IDN).
|
|
333
|
+
*
|
|
334
|
+
* Rules:
|
|
335
|
+
* 1. labels rules apply;
|
|
336
|
+
* 2. "[...] the total number of octets that represent a domain name
|
|
337
|
+
* (i.e., the sum of all label octets and label lengths) is limited to 255.";
|
|
338
|
+
* 3. labels are separated by dots (".");
|
|
339
|
+
* 4. must have at least one extension label;
|
|
340
|
+
* 5. must have labels different from each other;
|
|
341
|
+
* 6. last label can be empty (root label ".");
|
|
342
|
+
* 7. labels can start with `xn--` for IDNs if the ASCII serialization is a valid Punycode;
|
|
343
|
+
* 8. check also Punycodes as ॐ gives xn--'-6xd where ' is not valid.
|
|
344
|
+
*
|
|
345
|
+
* Based on:
|
|
346
|
+
* - RFC-1034 https://www.ietf.org/rfc/rfc1034.txt.
|
|
347
|
+
*/
|
|
348
|
+
declare const isDomain: (name: string) => boolean;
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/encoders/index.d.ts
|
|
351
|
+
/**
|
|
352
|
+
* @func encodeURIComponentString
|
|
353
|
+
*
|
|
354
|
+
* Encode an URI component according to RFC-3986 with Sitemap entities support.
|
|
355
|
+
*
|
|
356
|
+
* Support:
|
|
357
|
+
* - Sitemap's special characters;
|
|
358
|
+
* - lower and upper case.
|
|
359
|
+
*
|
|
360
|
+
* Note:
|
|
361
|
+
* - only userinfo, path, query and fragment components can be encoded;
|
|
362
|
+
* - scheme and authority host+port can never have percent encoded characters;
|
|
363
|
+
* - the empty string is returned if unable to encode;
|
|
364
|
+
* - sitemap characters must be in lowercase and escaped for XML sitemap.
|
|
365
|
+
*
|
|
366
|
+
* Based on:
|
|
367
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986;
|
|
368
|
+
* - https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190.
|
|
369
|
+
*/
|
|
370
|
+
declare const encodeURIComponentString: (component: string, {
|
|
371
|
+
type,
|
|
372
|
+
sitemap,
|
|
373
|
+
lowercase
|
|
374
|
+
}?: {
|
|
375
|
+
type?: string | undefined;
|
|
376
|
+
sitemap?: boolean | undefined;
|
|
377
|
+
lowercase?: boolean | undefined;
|
|
378
|
+
}) => string;
|
|
379
|
+
/**
|
|
380
|
+
* @func encodeURIString
|
|
381
|
+
*
|
|
382
|
+
* Encode an URI string according to RFC-3986 with basic checking.
|
|
383
|
+
*
|
|
384
|
+
* Checked:
|
|
385
|
+
* - scheme is required;
|
|
386
|
+
* - path is required, can be empty;
|
|
387
|
+
* - port, if any, must be an integer in a specific range;
|
|
388
|
+
* - host must be a valid ip or domain name;
|
|
389
|
+
* - maximum size once encoded for URLs.
|
|
390
|
+
*
|
|
391
|
+
* Support:
|
|
392
|
+
* - IDNs: returns URI with its Punycode host, if any;
|
|
393
|
+
* - lower and upper case.
|
|
394
|
+
*
|
|
395
|
+
* Note:
|
|
396
|
+
* - only userinfo, path, query and fragment can be percent encoded;
|
|
397
|
+
* - native function encodeURI encodes string according to RFC-2396 which is outdated;
|
|
398
|
+
* - native function encodeURI also encodes scheme and host that cannot have
|
|
399
|
+
* percend-encoded characters;
|
|
400
|
+
* - characters that should not be percent-encoded in RFC-3986 are [] to represent IPv6 host;
|
|
401
|
+
* - to stay fully RFC-3986 compliant, scheme and host are put in lowercase.
|
|
402
|
+
*
|
|
403
|
+
* Based on:
|
|
404
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986;
|
|
405
|
+
* - https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190.
|
|
406
|
+
*/
|
|
407
|
+
declare const encodeURIString: (uri: string, {
|
|
408
|
+
web,
|
|
409
|
+
sitemap,
|
|
410
|
+
lowercase
|
|
411
|
+
}?: {
|
|
412
|
+
web?: boolean | undefined;
|
|
413
|
+
sitemap?: boolean | undefined;
|
|
414
|
+
lowercase?: boolean | undefined;
|
|
415
|
+
}) => string;
|
|
416
|
+
/**
|
|
417
|
+
* @func encodeWebURL
|
|
418
|
+
*
|
|
419
|
+
* Encode an URI string with basic checking based on RFC-3986 standard applied
|
|
420
|
+
* to HTTP and HTTPS URLs.
|
|
421
|
+
*
|
|
422
|
+
* Uses a fixed encodeURI function to be RFC-3986 compliant.
|
|
423
|
+
*
|
|
424
|
+
* Checked:
|
|
425
|
+
* - scheme must be http/HTTP or https/HTTPS;
|
|
426
|
+
* - path is required, can be empty;
|
|
427
|
+
* - authority is required;
|
|
428
|
+
* - port, if any, must be an integer in a specific range;
|
|
429
|
+
* - host must be a valid IP or domain name;
|
|
430
|
+
* - maximum size once encoded.
|
|
431
|
+
*
|
|
432
|
+
* Support:
|
|
433
|
+
* - IDNs: returns URL with its Punycode host, if any;
|
|
434
|
+
* - lower and upper case.
|
|
435
|
+
*
|
|
436
|
+
* Note:
|
|
437
|
+
* - only userinfo, path, query and fragment can be percent encoded;
|
|
438
|
+
* - native function encodeURI encodes string according to RFC-2396 which is outdated;
|
|
439
|
+
* - native function encodes also scheme and host that cannot have percend encoded characters;
|
|
440
|
+
* - characters that should not be percent-encoded in RFC-3986 are [] to represent IPv6 host;
|
|
441
|
+
* - to stay fully RFC-3986 compliant, scheme and host are put in lowercase.
|
|
442
|
+
*
|
|
443
|
+
* Based on:
|
|
444
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986.
|
|
445
|
+
*/
|
|
446
|
+
declare const encodeWebURL: (uri: string, {
|
|
447
|
+
lowercase
|
|
448
|
+
}?: {
|
|
449
|
+
lowercase?: boolean | undefined;
|
|
450
|
+
}) => string;
|
|
451
|
+
/**
|
|
452
|
+
* @func encodeSitemapURL
|
|
453
|
+
*
|
|
454
|
+
* Encode an URI string with basic checking based on RFC-3986 standard applied
|
|
455
|
+
* to HTTP and HTTPS URLs and sitemap requirements regarding special entities to escape.
|
|
456
|
+
*
|
|
457
|
+
* Checked:
|
|
458
|
+
* - scheme must be http/HTTP or https/HTTPS;
|
|
459
|
+
* - path is required, can be empty;
|
|
460
|
+
* - authority is required;
|
|
461
|
+
* - port, if any, must be an integer in a specific range;
|
|
462
|
+
* - host must be a valid IP or domain name;
|
|
463
|
+
* - maximum size once encoded.
|
|
464
|
+
*
|
|
465
|
+
* Support:
|
|
466
|
+
* - Sitemap's special characters;
|
|
467
|
+
* - IDNs: returns URI with its Punycode host, if any;
|
|
468
|
+
* - lower case only.
|
|
469
|
+
*
|
|
470
|
+
* Note:
|
|
471
|
+
* - only userinfo, path, query and fragment can be percent encoded;
|
|
472
|
+
* - native function encodeURI encodes string according to RFC-2396 which is outdated;
|
|
473
|
+
* - native function encodes also scheme and host that cannot have percend encoded characters;
|
|
474
|
+
* - characters that should not be percent-encoded in RFC-3986 are [] to represent IPv6 host;
|
|
475
|
+
* - to stay fully RFC-3986 compliant, scheme and host are put in lowercase.
|
|
476
|
+
*
|
|
477
|
+
* Based on:
|
|
478
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986;
|
|
479
|
+
* - https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190.
|
|
480
|
+
*/
|
|
481
|
+
declare const encodeSitemapURL: (uri: string) => string;
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/ip/index.d.ts
|
|
484
|
+
/**
|
|
485
|
+
* @func isIP
|
|
486
|
+
*
|
|
487
|
+
* Test a string is a valid IP.
|
|
488
|
+
*/
|
|
489
|
+
declare const isIP: (ip: string) => boolean;
|
|
490
|
+
/**
|
|
491
|
+
* @func isIPv4
|
|
492
|
+
*
|
|
493
|
+
* Test a string is a valid IPv4.
|
|
494
|
+
*/
|
|
495
|
+
declare const isIPv4: (ip: string) => boolean;
|
|
496
|
+
/**
|
|
497
|
+
* @func isIPv6
|
|
498
|
+
*
|
|
499
|
+
* Test a string is a valid IPv6.
|
|
500
|
+
*/
|
|
501
|
+
declare const isIPv6: (ip: string) => boolean;
|
|
502
|
+
//#endregion
|
|
503
|
+
//#region src/punycode/index.d.ts
|
|
504
|
+
/**
|
|
505
|
+
* @func punycode
|
|
506
|
+
*
|
|
507
|
+
* Returns the Punycode ASCII serialization of the domain.
|
|
508
|
+
* If domain is an invalid domain, the empty string is returned.
|
|
509
|
+
*
|
|
510
|
+
* Note:
|
|
511
|
+
* - native function url.domainToASCII does not support IPv6 only IPv4;
|
|
512
|
+
* - native function url.domainToASCII throws if no domain is provided or returns
|
|
513
|
+
* `null`, `undefined`, `nan` for `null`, `undefined` or `NaN` values which is
|
|
514
|
+
* not what to be expected.
|
|
515
|
+
*/
|
|
516
|
+
declare const punycode: (domain: string) => string;
|
|
517
|
+
/**
|
|
518
|
+
* @func punydecode
|
|
519
|
+
*
|
|
520
|
+
* Returns the Unicode serialization of the domain.
|
|
521
|
+
* If domain is an invalid domain, the empty string is returned.
|
|
522
|
+
*
|
|
523
|
+
* Note:
|
|
524
|
+
* - native function url.domainToUnicode does not support IPv6 only IPv4;
|
|
525
|
+
* - native function url.domainToUnicode throws if no domain is provided or returns
|
|
526
|
+
* `null`, `undefined`, `nan` for `null`, `undefined` or `NaN` values which is
|
|
527
|
+
* not what to be expected.
|
|
528
|
+
*/
|
|
529
|
+
declare const punydecode: (domain: string) => string;
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/resolver/index.d.ts
|
|
532
|
+
/**
|
|
533
|
+
* @func removeDotSegments
|
|
534
|
+
*
|
|
535
|
+
* Remove the special "." and ".." complete path segments from a path,
|
|
536
|
+
* implementing the RFC-3986 §5.2.4 ordered loop verbatim.
|
|
537
|
+
*
|
|
538
|
+
* Based on:
|
|
539
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986#section-5.2.4.
|
|
540
|
+
*/
|
|
541
|
+
declare const removeDotSegments: (path: string) => string;
|
|
542
|
+
/**
|
|
543
|
+
* @func resolveURI
|
|
544
|
+
*
|
|
545
|
+
* Resolve a URI reference against a base URI, implementing the RFC-3986
|
|
546
|
+
* §5.2.2 strict transform (with §5.2.3 merge and §5.2.4 remove_dot_segments)
|
|
547
|
+
* and recomposing per §5.3.
|
|
548
|
+
*
|
|
549
|
+
* The base must be an absolute URI (a scheme is required, RFC-3986 §5.2.1);
|
|
550
|
+
* a fragment on the base is ignored (RFC-3986 §5.1: the base is used
|
|
551
|
+
* stripped of any fragment); the empty string is returned if base or
|
|
552
|
+
* reference is invalid.
|
|
553
|
+
*
|
|
554
|
+
* Based on:
|
|
555
|
+
* - RFC-3986 https://tools.ietf.org/html/rfc3986#section-5.2.
|
|
556
|
+
*/
|
|
557
|
+
declare const resolveURI: (base: string, reference: string) => string;
|
|
558
|
+
//#endregion
|
|
559
|
+
export { type CheckedURI, type ParsedURI, type URIComponents, checkHttpSitemapURL, checkHttpURL, checkHttpsSitemapURL, checkHttpsURL, checkSitemapURL, checkURI, checkWebURL, decodeSitemapURL, decodeURIComponentString, decodeURIString, decodeWebURL, encodeSitemapURL, encodeURIComponentString, encodeURIString, encodeWebURL, isDomain, isDomainLabel, isIP, isIPv4, isIPv6, parseURI, punycode, punydecode, recomposeURI, removeDotSegments, resolveURI };
|
|
560
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/parser/index.ts","../src/checkers/index.ts","../src/decoders/index.ts","../src/domain/index.ts","../src/encoders/index.ts","../src/ip/index.ts","../src/punycode/index.ts","../src/resolver/index.ts"],"mappings":"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"}
|