@oozcitak/url 0.0.7 → 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.
Files changed (47) hide show
  1. package/README.md +14 -0
  2. package/lib/URLAlgorithm.d.ts +267 -321
  3. package/lib/URLAlgorithm.js +2217 -2184
  4. package/lib/URLAlgorithm.js.map +1 -1
  5. package/lib/URLImpl.d.ts +22 -14
  6. package/lib/URLImpl.js +24 -25
  7. package/lib/URLImpl.js.map +1 -1
  8. package/lib/URLSearchParamsImpl.d.ts +0 -2
  9. package/lib/URLSearchParamsImpl.js +4 -5
  10. package/lib/URLSearchParamsImpl.js.map +1 -1
  11. package/lib/index.d.ts +2 -4
  12. package/lib/index.js +4 -15
  13. package/lib/index.js.map +1 -1
  14. package/package.json +5 -5
  15. package/lib/IDNAMappingTable.d.ts +0 -41
  16. package/lib/IDNAMappingTable.js +0 -8688
  17. package/lib/IDNAMappingTable.js.map +0 -1
  18. package/lib/TreeMap.d.ts +0 -39
  19. package/lib/TreeMap.js +0 -105
  20. package/lib/TreeMap.js.map +0 -1
  21. package/lib/algorithm/URLAlgorithm.d.ts +0 -321
  22. package/lib/algorithm/URLAlgorithm.js +0 -2552
  23. package/lib/algorithm/URLAlgorithm.js.map +0 -1
  24. package/lib/algorithm/index.d.ts +0 -1
  25. package/lib/algorithm/index.js +0 -5
  26. package/lib/algorithm/index.js.map +0 -1
  27. package/lib/interfacesInternal.d.ts +0 -22
  28. package/lib/interfacesInternal.js +0 -3
  29. package/lib/interfacesInternal.js.map +0 -1
  30. package/lib/url/URLImpl.d.ts +0 -45
  31. package/lib/url/URLImpl.js +0 -329
  32. package/lib/url/URLImpl.js.map +0 -1
  33. package/lib/url/URLSearchParamsImpl.d.ts +0 -40
  34. package/lib/url/URLSearchParamsImpl.js +0 -184
  35. package/lib/url/URLSearchParamsImpl.js.map +0 -1
  36. package/lib/url/index.d.ts +0 -4
  37. package/lib/url/index.js +0 -16
  38. package/lib/url/index.js.map +0 -1
  39. package/lib/url/interfaces.d.ts +0 -195
  40. package/lib/url/interfaces.js +0 -31
  41. package/lib/url/interfaces.js.map +0 -1
  42. package/lib/util/StringWalker.d.ts +0 -48
  43. package/lib/util/StringWalker.js +0 -92
  44. package/lib/util/StringWalker.js.map +0 -1
  45. package/lib/util/index.d.ts +0 -59
  46. package/lib/util/index.js +0 -170
  47. package/lib/util/index.js.map +0 -1
package/README.md CHANGED
@@ -11,3 +11,17 @@ A Javascript implementation of the [URL Living Standard](https://url.spec.whatwg
11
11
 
12
12
  # Version
13
13
  Current version implements the standard as of commit [7ae1c69](https://url.spec.whatwg.org/commit-snapshots/7ae1c691c96f0d82fafa24c33aa1e8df9ffbf2bc/).
14
+
15
+ # Installation
16
+ ```
17
+ npm install @oozcitak/url
18
+ ```
19
+
20
+ # Usage
21
+ Create an instance of the `URL` or `URLSearchParams` classes.
22
+
23
+ ```js
24
+ const { URL } = require("@oozcitak/url");
25
+
26
+ const url = new URL("https://example.org/file.aspx")
27
+ ```
@@ -1,321 +1,267 @@
1
- import { URLRecord, ParserState, Host, Origin } from './interfaces';
2
- /**
3
- * Represents algorithms to manipulate URLs.
4
- */
5
- export declare class URLAlgorithm {
6
- protected _validationErrorCallback: ((message: string) => void) | undefined;
7
- /**
8
- * Default ports for a special URL scheme.
9
- */
10
- protected _defaultPorts: {
11
- [key: string]: number | null;
12
- };
13
- /**
14
- * The C0 control percent-encode set are the C0 controls and all code points
15
- * greater than U+007E (~).
16
- */
17
- protected _c0ControlPercentEncodeSet: RegExp;
18
- /**
19
- * The fragment percent-encode set is the C0 control percent-encode set and
20
- * U+0020 SPACE, U+0022 ("), U+003C (<), U+003E (>), and U+0060 (`).
21
- */
22
- protected _fragmentPercentEncodeSet: RegExp;
23
- /**
24
- * The path percent-encode set is the fragment percent-encode set and
25
- * U+0023 (#), U+003F (?), U+007B ({), and U+007D (}).
26
- */
27
- protected _pathPercentEncodeSet: RegExp;
28
- /**
29
- * The userinfo percent-encode set is the path percent-encode set and
30
- * U+002F (/), U+003A (:), U+003B (;), U+003D (=), U+0040 (@), U+005B ([),
31
- * U+005C (\), U+005D (]), U+005E (^), and U+007C (|).
32
- */
33
- protected _userInfoPercentEncodeSet: RegExp;
34
- /**
35
- * The URL code points are ASCII alphanumeric, U+0021 (!), U+0024 ($),
36
- * U+0026 (&), U+0027 ('), U+0028 LEFT PARENTHESIS, U+0029 RIGHT PARENTHESIS,
37
- * U+002A (*), U+002B (+), U+002C (,), U+002D (-), U+002E (.), U+002F (/),
38
- * U+003A (:), U+003B (;), U+003D (=), U+003F (?), U+0040 (@), U+005F (_),
39
- * U+007E (~), and code points in the range U+00A0 to U+10FFFD, inclusive,
40
- * excluding surrogates and noncharacters.
41
- */
42
- protected _urlCodePoints: RegExp;
43
- /**
44
- * A forbidden host code point is U+0000 NULL, U+0009 TAB, U+000A LF,
45
- * U+000D CR, U+0020 SPACE, U+0023 (#), U+0025 (%), U+002F (/), U+003A (:),
46
- * U+003F (?), U+0040 (@), U+005B ([), U+005C (\), or U+005D (]).
47
- */
48
- protected _forbiddenHostCodePoint: RegExp;
49
- /**
50
- * Initializes a new `URLAlgorithm`.
51
- *
52
- * @param validationErrorCallback - a callback function to be called when a
53
- * validation error occurs
54
- */
55
- constructor(validationErrorCallback?: ((message: string) => void));
56
- /**
57
- * Generates a validation error.
58
- *
59
- * @param message - error message
60
- */
61
- validationError(message: string): void;
62
- /**
63
- * Creates a new URL.
64
- */
65
- newURL(): URLRecord;
66
- /**
67
- * Determines if the scheme is a special scheme.
68
- *
69
- * @param scheme - a scheme
70
- */
71
- isSpecialScheme(scheme: string): boolean;
72
- /**
73
- * Determines if the URL has a special scheme.
74
- *
75
- * @param url - an URL
76
- */
77
- isSpecial(url: URLRecord): boolean;
78
- /**
79
- * Returns the default port for a special scheme.
80
- *
81
- * @param scheme - a scheme
82
- */
83
- defaultPort(scheme: string): number | null;
84
- /**
85
- * Determines if the URL has credentials.
86
- *
87
- * @param url - an URL
88
- */
89
- includesCredentials(url: URLRecord): boolean;
90
- /**
91
- * Determines if an URL cannot have credentials.
92
- *
93
- * @param url - an URL
94
- */
95
- cannotHaveAUsernamePasswordPort(url: URLRecord): boolean;
96
- /**
97
- * Serializes an URL into a string.
98
- *
99
- * @param url - an URL
100
- */
101
- urlSerializer(url: URLRecord, excludeFragmentFlag?: boolean): string;
102
- /**
103
- * Serializes a host into a string.
104
- *
105
- * @param host - a host
106
- */
107
- hostSerializer(host: Host): string;
108
- /**
109
- * Serializes an IPv4 address into a string.
110
- *
111
- * @param address - an IPv4 address
112
- */
113
- iPv4Serializer(address: number): string;
114
- /**
115
- * Serializes an IPv6 address into a string.
116
- *
117
- * @param address - an IPv6 address represented as a list of eight numbers
118
- */
119
- iPv6Serializer(address: number[]): string;
120
- /**
121
- * Parses an URL string.
122
- *
123
- * @param input - input string
124
- * @param baseURL - base URL
125
- * @param encodingOverride - encoding override
126
- */
127
- urlParser(input: string, baseURL?: URLRecord, encodingOverride?: string): URLRecord | null;
128
- /**
129
- * Parses an URL string.
130
- *
131
- * @param input - input string
132
- * @param baseURL - base URL
133
- * @param encodingOverride - encoding override
134
- */
135
- basicURLParser(input: string, baseURL?: URLRecord | null, encodingOverride?: string, url?: URLRecord, stateOverride?: ParserState): URLRecord | null;
136
- /**
137
- * Sets a URL's username.
138
- *
139
- * @param url - a URL
140
- * @param username - username string
141
- */
142
- setTheUsername(url: URLRecord, username: string): void;
143
- /**
144
- * Sets a URL's password.
145
- *
146
- * @param url - a URL
147
- * @param username - password string
148
- */
149
- setThePassword(url: URLRecord, password: string): void;
150
- /**
151
- * Determines if the string represents a single dot path.
152
- *
153
- * @param str - a string
154
- */
155
- isSingleDotPathSegment(str: string): boolean;
156
- /**
157
- * Determines if the string represents a double dot path.
158
- *
159
- * @param str - a string
160
- */
161
- isDoubleDotPathSegment(str: string): boolean;
162
- /**
163
- * Shorten's URL's path.
164
- *
165
- * @param url - an URL
166
- */
167
- shorten(url: URLRecord): void;
168
- /**
169
- * Determines if a string is a normalized Windows drive letter.
170
- *
171
- * @param str - a string
172
- */
173
- isNormalizedWindowsDriveLetter(str: string): boolean;
174
- /**
175
- * Determines if a string is a Windows drive letter.
176
- *
177
- * @param str - a string
178
- */
179
- isWindowsDriveLetter(str: string): boolean;
180
- /**
181
- * Determines if a string starts with a Windows drive letter.
182
- *
183
- * @param str - a string
184
- */
185
- startsWithAWindowsDriveLetter(str: string): boolean;
186
- /**
187
- * Parses a host string.
188
- *
189
- * @param input - input string
190
- * @param isNotSpecial - `true` if the source URL is not special; otherwise
191
- * `false`.
192
- */
193
- hostParser(input: string, isNotSpecial?: boolean): string | number | number[] | null;
194
- /**
195
- * Parses a string containing an IP v4 address.
196
- *
197
- * @param input - input string
198
- * @param isNotSpecial - `true` if the source URL is not special; otherwise
199
- * `false`.
200
- */
201
- iPv4NumberParser(input: string, validationErrorFlag?: {
202
- value: boolean;
203
- }): number | null;
204
- /**
205
- * Parses a string containing an IP v4 address.
206
- *
207
- * @param input - input string
208
- */
209
- iPv4Parser(input: string): string | number | null;
210
- /**
211
- * Parses a string containing an IP v6 address.
212
- *
213
- * @param input - input string
214
- */
215
- iPv6Parser(input: string): number[] | null;
216
- /**
217
- * Parses an opaque host string.
218
- *
219
- * @param input - a string
220
- */
221
- opaqueHostParser(input: string): string | null;
222
- /**
223
- * Resolves a Blob URL from the user agent's Blob URL store.
224
- * This function is not implemented.
225
- * See: https://w3c.github.io/FileAPI/#blob-url-resolve
226
- *
227
- * @param url - an url
228
- */
229
- resolveABlobURL(url: URLRecord): any;
230
- /**
231
- * Percent encodes a byte.
232
- *
233
- * @param value - a byte
234
- */
235
- percentEncode(value: number): string;
236
- /**
237
- * Percent decodes a byte sequence input.
238
- *
239
- * @param input - a byte sequence
240
- */
241
- percentDecode(input: Uint8Array): Uint8Array;
242
- /**
243
- * String percent decodes a string.
244
- *
245
- * @param input - a string
246
- */
247
- stringPercentDecode(input: string): Uint8Array;
248
- /**
249
- * UTF-8 percent encodes a code point, using a percent encode set.
250
- *
251
- * @param codePoint - a code point
252
- * @param percentEncodeSet - a percent encode set
253
- */
254
- utf8PercentEncode(codePoint: string, percentEncodeSet: RegExp): string;
255
- /**
256
- * Determines if two hosts are considered equal.
257
- *
258
- * @param hostA - a host
259
- * @param hostB - a host
260
- */
261
- hostEquals(hostA: Host, hostB: Host): boolean;
262
- /**
263
- * Determines if two URLs are considered equal.
264
- *
265
- * @param urlA - a URL
266
- * @param urlB - a URL
267
- * @param excludeFragmentsFlag - whether to ignore fragments while comparing
268
- */
269
- urlEquals(urlA: URLRecord, urlB: URLRecord, excludeFragmentsFlag?: boolean): boolean;
270
- /**
271
- * Parses an `application/x-www-form-urlencoded` string.
272
- *
273
- * @param input - a string
274
- */
275
- urlEncodedStringParser(input: string): [string, string][];
276
- /**
277
- * Parses `application/x-www-form-urlencoded` bytes.
278
- *
279
- * @param input - a byte sequence
280
- */
281
- urlEncodedParser(input: Uint8Array): [string, string][];
282
- /**
283
- * Serializes `application/x-www-form-urlencoded` bytes.
284
- *
285
- * @param input - a byte sequence
286
- */
287
- urlEncodedByteSerializer(input: Uint8Array): string;
288
- /**
289
- * Serializes `application/x-www-form-urlencoded` tuples.
290
- *
291
- * @param input - input tuple of name/value pairs
292
- * @param encodingOverride: encoding override
293
- */
294
- urlEncodedSerializer(tuples: [string, string][], encodingOverride?: string): string;
295
- /**
296
- * Returns a URL's origin.
297
- *
298
- * @param url - a URL
299
- */
300
- origin(url: URLRecord): Origin;
301
- /**
302
- * Converts a domain string to ASCII.
303
- *
304
- * @param domain - a domain string
305
- */
306
- domainToASCII(domain: string, beStrict?: boolean): string | null;
307
- /**
308
- * Converts a domain string to Unicode.
309
- *
310
- * @param domain - a domain string
311
- */
312
- domainToUnicode(domain: string, beStrict?: boolean): string;
313
- /**
314
- * Serializes an origin.
315
- * This function is from the HTML spec:
316
- * https://html.spec.whatwg.org/#ascii-serialisation-of-an-origin
317
- *
318
- * @param origin - an origin
319
- */
320
- asciiSerializationOfAnOrigin(origin: Origin): string;
321
- }
1
+ import { URLRecord, ParserState, Host, Origin } from "./interfaces";
2
+ /**
3
+ * Sets the callback function for validation errors.
4
+ *
5
+ * @param validationErrorCallback - a callback function to be called when a
6
+ * validation error occurs
7
+ */
8
+ export declare function setValidationErrorCallback(validationErrorCallback?: ((message: string) => void)): void;
9
+ /**
10
+ * Creates a new URL.
11
+ */
12
+ export declare function newURL(): URLRecord;
13
+ /**
14
+ * Determines if the scheme is a special scheme.
15
+ *
16
+ * @param scheme - a scheme
17
+ */
18
+ export declare function isSpecialScheme(scheme: string): boolean;
19
+ /**
20
+ * Determines if the URL has a special scheme.
21
+ *
22
+ * @param url - an URL
23
+ */
24
+ export declare function isSpecial(url: URLRecord): boolean;
25
+ /**
26
+ * Returns the default port for a special scheme.
27
+ *
28
+ * @param scheme - a scheme
29
+ */
30
+ export declare function defaultPort(scheme: string): number | null;
31
+ /**
32
+ * Determines if the URL has credentials.
33
+ *
34
+ * @param url - an URL
35
+ */
36
+ export declare function includesCredentials(url: URLRecord): boolean;
37
+ /**
38
+ * Determines if an URL cannot have credentials.
39
+ *
40
+ * @param url - an URL
41
+ */
42
+ export declare function cannotHaveAUsernamePasswordPort(url: URLRecord): boolean;
43
+ /**
44
+ * Serializes an URL into a string.
45
+ *
46
+ * @param url - an URL
47
+ */
48
+ export declare function urlSerializer(url: URLRecord, excludeFragmentFlag?: boolean): string;
49
+ /**
50
+ * Serializes a host into a string.
51
+ *
52
+ * @param host - a host
53
+ */
54
+ export declare function hostSerializer(host: Host): string;
55
+ /**
56
+ * Serializes an IPv4 address into a string.
57
+ *
58
+ * @param address - an IPv4 address
59
+ */
60
+ export declare function iPv4Serializer(address: number): string;
61
+ /**
62
+ * Serializes an IPv6 address into a string.
63
+ *
64
+ * @param address - an IPv6 address represented as a list of eight numbers
65
+ */
66
+ export declare function iPv6Serializer(address: number[]): string;
67
+ /**
68
+ * Parses an URL string.
69
+ *
70
+ * @param input - input string
71
+ * @param baseURL - base URL
72
+ * @param encodingOverride - encoding override
73
+ */
74
+ export declare function urlParser(input: string, baseURL?: URLRecord, encodingOverride?: string): URLRecord | null;
75
+ /**
76
+ * Parses an URL string.
77
+ *
78
+ * @param input - input string
79
+ * @param baseURL - base URL
80
+ * @param encodingOverride - encoding override
81
+ */
82
+ export declare function basicURLParser(input: string, baseURL?: URLRecord | null, encodingOverride?: string, url?: URLRecord, stateOverride?: ParserState): URLRecord | null;
83
+ /**
84
+ * Sets a URL's username.
85
+ *
86
+ * @param url - a URL
87
+ * @param username - username string
88
+ */
89
+ export declare function setTheUsername(url: URLRecord, username: string): void;
90
+ /**
91
+ * Sets a URL's password.
92
+ *
93
+ * @param url - a URL
94
+ * @param username - password string
95
+ */
96
+ export declare function setThePassword(url: URLRecord, password: string): void;
97
+ /**
98
+ * Determines if the string represents a single dot path.
99
+ *
100
+ * @param str - a string
101
+ */
102
+ export declare function isSingleDotPathSegment(str: string): boolean;
103
+ /**
104
+ * Determines if the string represents a double dot path.
105
+ *
106
+ * @param str - a string
107
+ */
108
+ export declare function isDoubleDotPathSegment(str: string): boolean;
109
+ /**
110
+ * Shorten's URL's path.
111
+ *
112
+ * @param url - an URL
113
+ */
114
+ export declare function shorten(url: URLRecord): void;
115
+ /**
116
+ * Determines if a string is a normalized Windows drive letter.
117
+ *
118
+ * @param str - a string
119
+ */
120
+ export declare function isNormalizedWindowsDriveLetter(str: string): boolean;
121
+ /**
122
+ * Determines if a string is a Windows drive letter.
123
+ *
124
+ * @param str - a string
125
+ */
126
+ export declare function isWindowsDriveLetter(str: string): boolean;
127
+ /**
128
+ * Determines if a string starts with a Windows drive letter.
129
+ *
130
+ * @param str - a string
131
+ */
132
+ export declare function startsWithAWindowsDriveLetter(str: string): boolean;
133
+ /**
134
+ * Parses a host string.
135
+ *
136
+ * @param input - input string
137
+ * @param isNotSpecial - `true` if the source URL is not special; otherwise
138
+ * `false`.
139
+ */
140
+ export declare function hostParser(input: string, isNotSpecial?: boolean): string | number | number[] | null;
141
+ /**
142
+ * Parses a string containing an IP v4 address.
143
+ *
144
+ * @param input - input string
145
+ * @param isNotSpecial - `true` if the source URL is not special; otherwise
146
+ * `false`.
147
+ */
148
+ export declare function iPv4NumberParser(input: string, validationErrorFlag?: {
149
+ value: boolean;
150
+ }): number | null;
151
+ /**
152
+ * Parses a string containing an IP v4 address.
153
+ *
154
+ * @param input - input string
155
+ */
156
+ export declare function iPv4Parser(input: string): string | number | null;
157
+ /**
158
+ * Parses a string containing an IP v6 address.
159
+ *
160
+ * @param input - input string
161
+ */
162
+ export declare function iPv6Parser(input: string): number[] | null;
163
+ /**
164
+ * Parses an opaque host string.
165
+ *
166
+ * @param input - a string
167
+ */
168
+ export declare function opaqueHostParser(input: string): string | null;
169
+ /**
170
+ * Resolves a Blob URL from the user agent's Blob URL store.
171
+ * function is not implemented.
172
+ * See: https://w3c.github.io/FileAPI/#blob-url-resolve
173
+ *
174
+ * @param url - an url
175
+ */
176
+ export declare function resolveABlobURL(url: URLRecord): any;
177
+ /**
178
+ * Percent encodes a byte.
179
+ *
180
+ * @param value - a byte
181
+ */
182
+ export declare function percentEncode(value: number): string;
183
+ /**
184
+ * Percent decodes a byte sequence input.
185
+ *
186
+ * @param input - a byte sequence
187
+ */
188
+ export declare function percentDecode(input: Uint8Array): Uint8Array;
189
+ /**
190
+ * String percent decodes a string.
191
+ *
192
+ * @param input - a string
193
+ */
194
+ export declare function stringPercentDecode(input: string): Uint8Array;
195
+ /**
196
+ * UTF-8 percent encodes a code point, using a percent encode set.
197
+ *
198
+ * @param codePoint - a code point
199
+ * @param percentEncodeSet - a percent encode set
200
+ */
201
+ export declare function utf8PercentEncode(codePoint: string, percentEncodeSet: RegExp): string;
202
+ /**
203
+ * Determines if two hosts are considered equal.
204
+ *
205
+ * @param hostA - a host
206
+ * @param hostB - a host
207
+ */
208
+ export declare function hostEquals(hostA: Host, hostB: Host): boolean;
209
+ /**
210
+ * Determines if two URLs are considered equal.
211
+ *
212
+ * @param urlA - a URL
213
+ * @param urlB - a URL
214
+ * @param excludeFragmentsFlag - whether to ignore fragments while comparing
215
+ */
216
+ export declare function urlEquals(urlA: URLRecord, urlB: URLRecord, excludeFragmentsFlag?: boolean): boolean;
217
+ /**
218
+ * Parses an `application/x-www-form-urlencoded` string.
219
+ *
220
+ * @param input - a string
221
+ */
222
+ export declare function urlEncodedStringParser(input: string): [string, string][];
223
+ /**
224
+ * Parses `application/x-www-form-urlencoded` bytes.
225
+ *
226
+ * @param input - a byte sequence
227
+ */
228
+ export declare function urlEncodedParser(input: Uint8Array): [string, string][];
229
+ /**
230
+ * Serializes `application/x-www-form-urlencoded` bytes.
231
+ *
232
+ * @param input - a byte sequence
233
+ */
234
+ export declare function urlEncodedByteSerializer(input: Uint8Array): string;
235
+ /**
236
+ * Serializes `application/x-www-form-urlencoded` tuples.
237
+ *
238
+ * @param input - input tuple of name/value pairs
239
+ * @param encodingOverride: encoding override
240
+ */
241
+ export declare function urlEncodedSerializer(tuples: [string, string][], encodingOverride?: string): string;
242
+ /**
243
+ * Returns a URL's origin.
244
+ *
245
+ * @param url - a URL
246
+ */
247
+ export declare function origin(url: URLRecord): Origin;
248
+ /**
249
+ * Converts a domain string to ASCII.
250
+ *
251
+ * @param domain - a domain string
252
+ */
253
+ export declare function domainToASCII(domain: string, beStrict?: boolean): string | null;
254
+ /**
255
+ * Converts a domain string to Unicode.
256
+ *
257
+ * @param domain - a domain string
258
+ */
259
+ export declare function domainToUnicode(domain: string, beStrict?: boolean): string;
260
+ /**
261
+ * Serializes an origin.
262
+ * function is from the HTML spec:
263
+ * https://html.spec.whatwg.org/#ascii-serialisation-of-an-origin
264
+ *
265
+ * @param origin - an origin
266
+ */
267
+ export declare function asciiSerializationOfAnOrigin(origin: Origin): string;