@types/node 16.4.2 → 16.4.6

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.
node/url.d.ts CHANGED
@@ -1,7 +1,19 @@
1
+ /**
2
+ * The `url` module provides utilities for URL resolution and parsing. It can be
3
+ * accessed using:
4
+ *
5
+ * ```js
6
+ * import url from 'url';
7
+ * ```
8
+ *
9
+ * ```js
10
+ * const url = require('url');
11
+ * ```
12
+ * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/url.js)
13
+ */
1
14
  declare module 'url' {
2
15
  import { ClientRequestArgs } from 'node:http';
3
16
  import { ParsedUrlQuery, ParsedUrlQueryInput } from 'node:querystring';
4
-
5
17
  // Input to `url.format`
6
18
  interface UrlObject {
7
19
  auth?: string | null | undefined;
@@ -16,7 +28,6 @@ declare module 'url' {
16
28
  port?: string | number | null | undefined;
17
29
  query?: string | null | ParsedUrlQueryInput | undefined;
18
30
  }
19
-
20
31
  // Output of `url.parse`
21
32
  interface Url {
22
33
  auth: string | null;
@@ -32,96 +43,795 @@ declare module 'url' {
32
43
  port: string | null;
33
44
  query: string | null | ParsedUrlQuery;
34
45
  }
35
-
36
46
  interface UrlWithParsedQuery extends Url {
37
47
  query: ParsedUrlQuery;
38
48
  }
39
-
40
49
  interface UrlWithStringQuery extends Url {
41
50
  query: string | null;
42
51
  }
43
-
44
- /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
45
- function parse(urlStr: string): UrlWithStringQuery;
46
- /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
47
- function parse(urlStr: string, parseQueryString: false | undefined, slashesDenoteHost?: boolean): UrlWithStringQuery;
48
- /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
49
- function parse(urlStr: string, parseQueryString: true, slashesDenoteHost?: boolean): UrlWithParsedQuery;
50
- /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
51
- function parse(urlStr: string, parseQueryString: boolean, slashesDenoteHost?: boolean): Url;
52
-
53
- function format(URL: URL, options?: URLFormatOptions): string;
54
- /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
52
+ /**
53
+ * The `url.parse()` method takes a URL string, parses it, and returns a URL
54
+ * object.
55
+ *
56
+ * A `TypeError` is thrown if `urlString` is not a string.
57
+ *
58
+ * A `URIError` is thrown if the `auth` property is present but cannot be decoded.
59
+ *
60
+ * Use of the legacy `url.parse()` method is discouraged. Users should
61
+ * use the WHATWG `URL` API. Because the `url.parse()` method uses a
62
+ * lenient, non-standard algorithm for parsing URL strings, security
63
+ * issues can be introduced. Specifically, issues with [host name spoofing](https://hackerone.com/reports/678487) and
64
+ * incorrect handling of usernames and passwords have been identified.
65
+ * @since v0.1.25
66
+ * @deprecated Legacy: Use the WHATWG URL API instead.
67
+ * @param urlString The URL string to parse.
68
+ * @param parseQueryString If `true`, the `query` property will always be set to an object returned by the {@link querystring} module's `parse()` method. If `false`, the `query` property on the
69
+ * returned URL object will be an unparsed, undecoded string.
70
+ * @param slashesDenoteHost If `true`, the first token after the literal string `//` and preceding the next `/` will be interpreted as the `host`. For instance, given `//foo/bar`, the result
71
+ * would be `{host: 'foo', pathname: '/bar'}` rather than `{pathname: '//foo/bar'}`.
72
+ */
73
+ function parse(urlString: string): UrlWithStringQuery;
74
+ function parse(urlString: string, parseQueryString: false | undefined, slashesDenoteHost?: boolean): UrlWithStringQuery;
75
+ function parse(urlString: string, parseQueryString: true, slashesDenoteHost?: boolean): UrlWithParsedQuery;
76
+ function parse(urlString: string, parseQueryString: boolean, slashesDenoteHost?: boolean): Url;
77
+ /**
78
+ * The `url.format()` method returns a formatted URL string derived from`urlObject`.
79
+ *
80
+ * ```js
81
+ * const url = require('url');
82
+ * url.format({
83
+ * protocol: 'https',
84
+ * hostname: 'example.com',
85
+ * pathname: '/some/path',
86
+ * query: {
87
+ * page: 1,
88
+ * format: 'json'
89
+ * }
90
+ * });
91
+ *
92
+ * // => 'https://example.com/some/path?page=1&format=json'
93
+ * ```
94
+ *
95
+ * If `urlObject` is not an object or a string, `url.format()` will throw a `TypeError`.
96
+ *
97
+ * The formatting process operates as follows:
98
+ *
99
+ * * A new empty string `result` is created.
100
+ * * If `urlObject.protocol` is a string, it is appended as-is to `result`.
101
+ * * Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an `Error` is thrown.
102
+ * * For all string values of `urlObject.protocol` that _do not end_ with an ASCII
103
+ * colon (`:`) character, the literal string `:` will be appended to `result`.
104
+ * * If either of the following conditions is true, then the literal string `//`will be appended to `result`:
105
+ * * `urlObject.slashes` property is true;
106
+ * * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or`file`;
107
+ * * If the value of the `urlObject.auth` property is truthy, and either`urlObject.host` or `urlObject.hostname` are not `undefined`, the value of`urlObject.auth` will be coerced into a string
108
+ * and appended to `result`followed by the literal string `@`.
109
+ * * If the `urlObject.host` property is `undefined` then:
110
+ * * If the `urlObject.hostname` is a string, it is appended to `result`.
111
+ * * Otherwise, if `urlObject.hostname` is not `undefined` and is not a string,
112
+ * an `Error` is thrown.
113
+ * * If the `urlObject.port` property value is truthy, and `urlObject.hostname`is not `undefined`:
114
+ * * The literal string `:` is appended to `result`, and
115
+ * * The value of `urlObject.port` is coerced to a string and appended to`result`.
116
+ * * Otherwise, if the `urlObject.host` property value is truthy, the value of`urlObject.host` is coerced to a string and appended to `result`.
117
+ * * If the `urlObject.pathname` property is a string that is not an empty string:
118
+ * * If the `urlObject.pathname`_does not start_ with an ASCII forward slash
119
+ * (`/`), then the literal string `'/'` is appended to `result`.
120
+ * * The value of `urlObject.pathname` is appended to `result`.
121
+ * * Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an `Error` is thrown.
122
+ * * If the `urlObject.search` property is `undefined` and if the `urlObject.query`property is an `Object`, the literal string `?` is appended to `result`followed by the output of calling the
123
+ * `querystring` module's `stringify()`method passing the value of `urlObject.query`.
124
+ * * Otherwise, if `urlObject.search` is a string:
125
+ * * If the value of `urlObject.search`_does not start_ with the ASCII question
126
+ * mark (`?`) character, the literal string `?` is appended to `result`.
127
+ * * The value of `urlObject.search` is appended to `result`.
128
+ * * Otherwise, if `urlObject.search` is not `undefined` and is not a string, an `Error` is thrown.
129
+ * * If the `urlObject.hash` property is a string:
130
+ * * If the value of `urlObject.hash`_does not start_ with the ASCII hash (`#`)
131
+ * character, the literal string `#` is appended to `result`.
132
+ * * The value of `urlObject.hash` is appended to `result`.
133
+ * * Otherwise, if the `urlObject.hash` property is not `undefined` and is not a
134
+ * string, an `Error` is thrown.
135
+ * * `result` is returned.
136
+ * @since v0.1.25
137
+ * @deprecated Legacy: Use the WHATWG URL API instead.
138
+ * @param urlObject A URL object (as returned by `url.parse()` or constructed otherwise). If a string, it is converted to an object by passing it to `url.parse()`.
139
+ */
140
+ function format(urlObject: URL, options?: URLFormatOptions): string;
55
141
  function format(urlObject: UrlObject | string): string;
56
- /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
142
+ /**
143
+ * The `url.resolve()` method resolves a target URL relative to a base URL in a
144
+ * manner similar to that of a Web browser resolving an anchor tag HREF.
145
+ *
146
+ * ```js
147
+ * const url = require('url');
148
+ * url.resolve('/one/two/three', 'four'); // '/one/two/four'
149
+ * url.resolve('http://example.com/', '/one'); // 'http://example.com/one'
150
+ * url.resolve('http://example.com/one', '/two'); // 'http://example.com/two'
151
+ * ```
152
+ *
153
+ * You can achieve the same result using the WHATWG URL API:
154
+ *
155
+ * ```js
156
+ * function resolve(from, to) {
157
+ * const resolvedUrl = new URL(to, new URL(from, 'resolve://'));
158
+ * if (resolvedUrl.protocol === 'resolve:') {
159
+ * // `from` is a relative URL.
160
+ * const { pathname, search, hash } = resolvedUrl;
161
+ * return pathname + search + hash;
162
+ * }
163
+ * return resolvedUrl.toString();
164
+ * }
165
+ *
166
+ * resolve('/one/two/three', 'four'); // '/one/two/four'
167
+ * resolve('http://example.com/', '/one'); // 'http://example.com/one'
168
+ * resolve('http://example.com/one', '/two'); // 'http://example.com/two'
169
+ * ```
170
+ * @since v0.1.25
171
+ * @deprecated Legacy: Use the WHATWG URL API instead.
172
+ * @param from The Base URL being resolved against.
173
+ * @param to The HREF URL being resolved.
174
+ */
57
175
  function resolve(from: string, to: string): string;
58
-
176
+ /**
177
+ * Returns the [Punycode](https://tools.ietf.org/html/rfc5891#section-4.4) ASCII serialization of the `domain`. If `domain` is an
178
+ * invalid domain, the empty string is returned.
179
+ *
180
+ * It performs the inverse operation to {@link domainToUnicode}.
181
+ *
182
+ * This feature is only available if the `node` executable was compiled with `ICU` enabled. If not, the domain names are passed through unchanged.
183
+ *
184
+ * ```js
185
+ * import url from 'url';
186
+ *
187
+ * console.log(url.domainToASCII('español.com'));
188
+ * // Prints xn--espaol-zwa.com
189
+ * console.log(url.domainToASCII('中文.com'));
190
+ * // Prints xn--fiq228c.com
191
+ * console.log(url.domainToASCII('xn--iñvalid.com'));
192
+ * // Prints an empty string
193
+ * ```
194
+ *
195
+ * ```js
196
+ * const url = require('url');
197
+ *
198
+ * console.log(url.domainToASCII('español.com'));
199
+ * // Prints xn--espaol-zwa.com
200
+ * console.log(url.domainToASCII('中文.com'));
201
+ * // Prints xn--fiq228c.com
202
+ * console.log(url.domainToASCII('xn--iñvalid.com'));
203
+ * // Prints an empty string
204
+ * ```
205
+ * @since v7.4.0, v6.13.0
206
+ */
59
207
  function domainToASCII(domain: string): string;
208
+ /**
209
+ * Returns the Unicode serialization of the `domain`. If `domain` is an invalid
210
+ * domain, the empty string is returned.
211
+ *
212
+ * It performs the inverse operation to {@link domainToASCII}.
213
+ *
214
+ * This feature is only available if the `node` executable was compiled with `ICU` enabled. If not, the domain names are passed through unchanged.
215
+ *
216
+ * ```js
217
+ * import url from 'url';
218
+ *
219
+ * console.log(url.domainToUnicode('xn--espaol-zwa.com'));
220
+ * // Prints español.com
221
+ * console.log(url.domainToUnicode('xn--fiq228c.com'));
222
+ * // Prints 中文.com
223
+ * console.log(url.domainToUnicode('xn--iñvalid.com'));
224
+ * // Prints an empty string
225
+ * ```
226
+ *
227
+ * ```js
228
+ * const url = require('url');
229
+ *
230
+ * console.log(url.domainToUnicode('xn--espaol-zwa.com'));
231
+ * // Prints español.com
232
+ * console.log(url.domainToUnicode('xn--fiq228c.com'));
233
+ * // Prints 中文.com
234
+ * console.log(url.domainToUnicode('xn--iñvalid.com'));
235
+ * // Prints an empty string
236
+ * ```
237
+ * @since v7.4.0, v6.13.0
238
+ */
60
239
  function domainToUnicode(domain: string): string;
61
-
62
240
  /**
63
241
  * This function ensures the correct decodings of percent-encoded characters as
64
242
  * well as ensuring a cross-platform valid absolute path string.
243
+ *
244
+ * ```js
245
+ * import { fileURLToPath } from 'url';
246
+ *
247
+ * const __filename = fileURLToPath(import.meta.url);
248
+ *
249
+ * new URL('file:///C:/path/').pathname; // Incorrect: /C:/path/
250
+ * fileURLToPath('file:///C:/path/'); // Correct: C:\path\ (Windows)
251
+ *
252
+ * new URL('file://nas/foo.txt').pathname; // Incorrect: /foo.txt
253
+ * fileURLToPath('file://nas/foo.txt'); // Correct: \\nas\foo.txt (Windows)
254
+ *
255
+ * new URL('file:///你好.txt').pathname; // Incorrect: /%E4%BD%A0%E5%A5%BD.txt
256
+ * fileURLToPath('file:///你好.txt'); // Correct: /你好.txt (POSIX)
257
+ *
258
+ * new URL('file:///hello world').pathname; // Incorrect: /hello%20world
259
+ * fileURLToPath('file:///hello world'); // Correct: /hello world (POSIX)
260
+ * ```
261
+ *
262
+ * ```js
263
+ * const { fileURLToPath } = require('url');
264
+ * new URL('file:///C:/path/').pathname; // Incorrect: /C:/path/
265
+ * fileURLToPath('file:///C:/path/'); // Correct: C:\path\ (Windows)
266
+ *
267
+ * new URL('file://nas/foo.txt').pathname; // Incorrect: /foo.txt
268
+ * fileURLToPath('file://nas/foo.txt'); // Correct: \\nas\foo.txt (Windows)
269
+ *
270
+ * new URL('file:///你好.txt').pathname; // Incorrect: /%E4%BD%A0%E5%A5%BD.txt
271
+ * fileURLToPath('file:///你好.txt'); // Correct: /你好.txt (POSIX)
272
+ *
273
+ * new URL('file:///hello world').pathname; // Incorrect: /hello%20world
274
+ * fileURLToPath('file:///hello world'); // Correct: /hello world (POSIX)
275
+ * ```
276
+ * @since v10.12.0
65
277
  * @param url The file URL string or URL object to convert to a path.
278
+ * @return The fully-resolved platform-specific Node.js file path.
66
279
  */
67
280
  function fileURLToPath(url: string | URL): string;
68
-
69
281
  /**
70
- * This function ensures that path is resolved absolutely, and that the URL
282
+ * This function ensures that `path` is resolved absolutely, and that the URL
71
283
  * control characters are correctly encoded when converting into a File URL.
72
- * @param url The path to convert to a File URL.
284
+ *
285
+ * ```js
286
+ * import { pathToFileURL } from 'url';
287
+ *
288
+ * new URL('/foo#1', 'file:'); // Incorrect: file:///foo#1
289
+ * pathToFileURL('/foo#1'); // Correct: file:///foo%231 (POSIX)
290
+ *
291
+ * new URL('/some/path%.c', 'file:'); // Incorrect: file:///some/path%.c
292
+ * pathToFileURL('/some/path%.c'); // Correct: file:///some/path%25.c (POSIX)
293
+ * ```
294
+ *
295
+ * ```js
296
+ * const { pathToFileURL } = require('url');
297
+ * new URL(__filename); // Incorrect: throws (POSIX)
298
+ * new URL(__filename); // Incorrect: C:\... (Windows)
299
+ * pathToFileURL(__filename); // Correct: file:///... (POSIX)
300
+ * pathToFileURL(__filename); // Correct: file:///C:/... (Windows)
301
+ *
302
+ * new URL('/foo#1', 'file:'); // Incorrect: file:///foo#1
303
+ * pathToFileURL('/foo#1'); // Correct: file:///foo%231 (POSIX)
304
+ *
305
+ * new URL('/some/path%.c', 'file:'); // Incorrect: file:///some/path%.c
306
+ * pathToFileURL('/some/path%.c'); // Correct: file:///some/path%25.c (POSIX)
307
+ * ```
308
+ * @since v10.12.0
309
+ * @param path The path to convert to a File URL.
310
+ * @return The file URL object.
73
311
  */
74
- function pathToFileURL(url: string): URL;
75
-
312
+ function pathToFileURL(path: string): URL;
76
313
  /**
77
314
  * This utility function converts a URL object into an ordinary options object as
78
315
  * expected by the `http.request()` and `https.request()` APIs.
316
+ *
317
+ * ```js
318
+ * import { urlToHttpOptions } from 'url';
319
+ * const myURL = new URL('https://a:b@測試?abc#foo');
320
+ *
321
+ * console.log(urlToHttpOptions(myUrl));
322
+ *
323
+ * {
324
+ * protocol: 'https:',
325
+ * hostname: 'xn--g6w251d',
326
+ * hash: '#foo',
327
+ * search: '?abc',
328
+ * pathname: '/',
329
+ * path: '/?abc',
330
+ * href: 'https://a:b@xn--g6w251d/?abc#foo',
331
+ * auth: 'a:b'
332
+ * }
333
+ *
334
+ * ```
335
+ *
336
+ * ```js
337
+ * const { urlToHttpOptions } = require('url');
338
+ * const myURL = new URL('https://a:b@測試?abc#foo');
339
+ *
340
+ * console.log(urlToHttpOptions(myUrl));
341
+ *
342
+ * {
343
+ * protocol: 'https:',
344
+ * hostname: 'xn--g6w251d',
345
+ * hash: '#foo',
346
+ * search: '?abc',
347
+ * pathname: '/',
348
+ * path: '/?abc',
349
+ * href: 'https://a:b@xn--g6w251d/?abc#foo',
350
+ * auth: 'a:b'
351
+ * }
352
+ *
353
+ * ```
354
+ * @since v15.7.0
355
+ * @param url The `WHATWG URL` object to convert to an options object.
356
+ * @return Options object
79
357
  */
80
358
  function urlToHttpOptions(url: URL): ClientRequestArgs;
81
-
82
359
  interface URLFormatOptions {
83
360
  auth?: boolean | undefined;
84
361
  fragment?: boolean | undefined;
85
362
  search?: boolean | undefined;
86
363
  unicode?: boolean | undefined;
87
364
  }
88
-
365
+ /**
366
+ * Browser-compatible `URL` class, implemented by following the WHATWG URL
367
+ * Standard. [Examples of parsed URLs](https://url.spec.whatwg.org/#example-url-parsing) may be found in the Standard itself.
368
+ * The `URL` class is also available on the global object.
369
+ *
370
+ * In accordance with browser conventions, all properties of `URL` objects
371
+ * are implemented as getters and setters on the class prototype, rather than as
372
+ * data properties on the object itself. Thus, unlike `legacy urlObject` s,
373
+ * using the `delete` keyword on any properties of `URL` objects (e.g. `delete myURL.protocol`, `delete myURL.pathname`, etc) has no effect but will still
374
+ * return `true`.
375
+ * @since v7.0.0, v6.13.0
376
+ */
89
377
  class URL {
90
378
  constructor(input: string, base?: string | URL);
379
+ /**
380
+ * Gets and sets the fragment portion of the URL.
381
+ *
382
+ * ```js
383
+ * const myURL = new URL('https://example.org/foo#bar');
384
+ * console.log(myURL.hash);
385
+ * // Prints #bar
386
+ *
387
+ * myURL.hash = 'baz';
388
+ * console.log(myURL.href);
389
+ * // Prints https://example.org/foo#baz
390
+ * ```
391
+ *
392
+ * Invalid URL characters included in the value assigned to the `hash` property
393
+ * are `percent-encoded`. The selection of which characters to
394
+ * percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
395
+ */
91
396
  hash: string;
397
+ /**
398
+ * Gets and sets the host portion of the URL.
399
+ *
400
+ * ```js
401
+ * const myURL = new URL('https://example.org:81/foo');
402
+ * console.log(myURL.host);
403
+ * // Prints example.org:81
404
+ *
405
+ * myURL.host = 'example.com:82';
406
+ * console.log(myURL.href);
407
+ * // Prints https://example.com:82/foo
408
+ * ```
409
+ *
410
+ * Invalid host values assigned to the `host` property are ignored.
411
+ */
92
412
  host: string;
413
+ /**
414
+ * Gets and sets the host name portion of the URL. The key difference between`url.host` and `url.hostname` is that `url.hostname` does _not_ include the
415
+ * port.
416
+ *
417
+ * ```js
418
+ * const myURL = new URL('https://example.org:81/foo');
419
+ * console.log(myURL.hostname);
420
+ * // Prints example.org
421
+ *
422
+ * // Setting the hostname does not change the port
423
+ * myURL.hostname = 'example.com:82';
424
+ * console.log(myURL.href);
425
+ * // Prints https://example.com:81/foo
426
+ *
427
+ * // Use myURL.host to change the hostname and port
428
+ * myURL.host = 'example.org:82';
429
+ * console.log(myURL.href);
430
+ * // Prints https://example.org:82/foo
431
+ * ```
432
+ *
433
+ * Invalid host name values assigned to the `hostname` property are ignored.
434
+ */
93
435
  hostname: string;
436
+ /**
437
+ * Gets and sets the serialized URL.
438
+ *
439
+ * ```js
440
+ * const myURL = new URL('https://example.org/foo');
441
+ * console.log(myURL.href);
442
+ * // Prints https://example.org/foo
443
+ *
444
+ * myURL.href = 'https://example.com/bar';
445
+ * console.log(myURL.href);
446
+ * // Prints https://example.com/bar
447
+ * ```
448
+ *
449
+ * Getting the value of the `href` property is equivalent to calling {@link toString}.
450
+ *
451
+ * Setting the value of this property to a new value is equivalent to creating a
452
+ * new `URL` object using `new URL(value)`. Each of the `URL`object's properties will be modified.
453
+ *
454
+ * If the value assigned to the `href` property is not a valid URL, a `TypeError`will be thrown.
455
+ */
94
456
  href: string;
457
+ /**
458
+ * Gets the read-only serialization of the URL's origin.
459
+ *
460
+ * ```js
461
+ * const myURL = new URL('https://example.org/foo/bar?baz');
462
+ * console.log(myURL.origin);
463
+ * // Prints https://example.org
464
+ * ```
465
+ *
466
+ * ```js
467
+ * const idnURL = new URL('https://測試');
468
+ * console.log(idnURL.origin);
469
+ * // Prints https://xn--g6w251d
470
+ *
471
+ * console.log(idnURL.hostname);
472
+ * // Prints xn--g6w251d
473
+ * ```
474
+ */
95
475
  readonly origin: string;
476
+ /**
477
+ * Gets and sets the password portion of the URL.
478
+ *
479
+ * ```js
480
+ * const myURL = new URL('https://abc:xyz@example.com');
481
+ * console.log(myURL.password);
482
+ * // Prints xyz
483
+ *
484
+ * myURL.password = '123';
485
+ * console.log(myURL.href);
486
+ * // Prints https://abc:123@example.com
487
+ * ```
488
+ *
489
+ * Invalid URL characters included in the value assigned to the `password` property
490
+ * are `percent-encoded`. The selection of which characters to
491
+ * percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
492
+ */
96
493
  password: string;
494
+ /**
495
+ * Gets and sets the path portion of the URL.
496
+ *
497
+ * ```js
498
+ * const myURL = new URL('https://example.org/abc/xyz?123');
499
+ * console.log(myURL.pathname);
500
+ * // Prints /abc/xyz
501
+ *
502
+ * myURL.pathname = '/abcdef';
503
+ * console.log(myURL.href);
504
+ * // Prints https://example.org/abcdef?123
505
+ * ```
506
+ *
507
+ * Invalid URL characters included in the value assigned to the `pathname`property are `percent-encoded`. The selection of which characters
508
+ * to percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
509
+ */
97
510
  pathname: string;
511
+ /**
512
+ * Gets and sets the port portion of the URL.
513
+ *
514
+ * The port value may be a number or a string containing a number in the range`0` to `65535` (inclusive). Setting the value to the default port of the`URL` objects given `protocol` will
515
+ * result in the `port` value becoming
516
+ * the empty string (`''`).
517
+ *
518
+ * The port value can be an empty string in which case the port depends on
519
+ * the protocol/scheme:
520
+ *
521
+ * <omitted>
522
+ *
523
+ * Upon assigning a value to the port, the value will first be converted to a
524
+ * string using `.toString()`.
525
+ *
526
+ * If that string is invalid but it begins with a number, the leading number is
527
+ * assigned to `port`.
528
+ * If the number lies outside the range denoted above, it is ignored.
529
+ *
530
+ * ```js
531
+ * const myURL = new URL('https://example.org:8888');
532
+ * console.log(myURL.port);
533
+ * // Prints 8888
534
+ *
535
+ * // Default ports are automatically transformed to the empty string
536
+ * // (HTTPS protocol's default port is 443)
537
+ * myURL.port = '443';
538
+ * console.log(myURL.port);
539
+ * // Prints the empty string
540
+ * console.log(myURL.href);
541
+ * // Prints https://example.org/
542
+ *
543
+ * myURL.port = 1234;
544
+ * console.log(myURL.port);
545
+ * // Prints 1234
546
+ * console.log(myURL.href);
547
+ * // Prints https://example.org:1234/
548
+ *
549
+ * // Completely invalid port strings are ignored
550
+ * myURL.port = 'abcd';
551
+ * console.log(myURL.port);
552
+ * // Prints 1234
553
+ *
554
+ * // Leading numbers are treated as a port number
555
+ * myURL.port = '5678abcd';
556
+ * console.log(myURL.port);
557
+ * // Prints 5678
558
+ *
559
+ * // Non-integers are truncated
560
+ * myURL.port = 1234.5678;
561
+ * console.log(myURL.port);
562
+ * // Prints 1234
563
+ *
564
+ * // Out-of-range numbers which are not represented in scientific notation
565
+ * // will be ignored.
566
+ * myURL.port = 1e10; // 10000000000, will be range-checked as described below
567
+ * console.log(myURL.port);
568
+ * // Prints 1234
569
+ * ```
570
+ *
571
+ * Numbers which contain a decimal point,
572
+ * such as floating-point numbers or numbers in scientific notation,
573
+ * are not an exception to this rule.
574
+ * Leading numbers up to the decimal point will be set as the URL's port,
575
+ * assuming they are valid:
576
+ *
577
+ * ```js
578
+ * myURL.port = 4.567e21;
579
+ * console.log(myURL.port);
580
+ * // Prints 4 (because it is the leading number in the string '4.567e21')
581
+ * ```
582
+ */
98
583
  port: string;
584
+ /**
585
+ * Gets and sets the protocol portion of the URL.
586
+ *
587
+ * ```js
588
+ * const myURL = new URL('https://example.org');
589
+ * console.log(myURL.protocol);
590
+ * // Prints https:
591
+ *
592
+ * myURL.protocol = 'ftp';
593
+ * console.log(myURL.href);
594
+ * // Prints ftp://example.org/
595
+ * ```
596
+ *
597
+ * Invalid URL protocol values assigned to the `protocol` property are ignored.
598
+ */
99
599
  protocol: string;
600
+ /**
601
+ * Gets and sets the serialized query portion of the URL.
602
+ *
603
+ * ```js
604
+ * const myURL = new URL('https://example.org/abc?123');
605
+ * console.log(myURL.search);
606
+ * // Prints ?123
607
+ *
608
+ * myURL.search = 'abc=xyz';
609
+ * console.log(myURL.href);
610
+ * // Prints https://example.org/abc?abc=xyz
611
+ * ```
612
+ *
613
+ * Any invalid URL characters appearing in the value assigned the `search`property will be `percent-encoded`. The selection of which
614
+ * characters to percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
615
+ */
100
616
  search: string;
617
+ /**
618
+ * Gets the `URLSearchParams` object representing the query parameters of the
619
+ * URL. This property is read-only but the `URLSearchParams` object it provides
620
+ * can be used to mutate the URL instance; to replace the entirety of query
621
+ * parameters of the URL, use the {@link search} setter. See `URLSearchParams` documentation for details.
622
+ *
623
+ * Use care when using `.searchParams` to modify the `URL` because,
624
+ * per the WHATWG specification, the `URLSearchParams` object uses
625
+ * different rules to determine which characters to percent-encode. For
626
+ * instance, the `URL` object will not percent encode the ASCII tilde (`~`)
627
+ * character, while `URLSearchParams` will always encode it:
628
+ *
629
+ * ```js
630
+ * const myUrl = new URL('https://example.org/abc?foo=~bar');
631
+ *
632
+ * console.log(myUrl.search); // prints ?foo=~bar
633
+ *
634
+ * // Modify the URL via searchParams...
635
+ * myUrl.searchParams.sort();
636
+ *
637
+ * console.log(myUrl.search); // prints ?foo=%7Ebar
638
+ * ```
639
+ */
101
640
  readonly searchParams: URLSearchParams;
641
+ /**
642
+ * Gets and sets the username portion of the URL.
643
+ *
644
+ * ```js
645
+ * const myURL = new URL('https://abc:xyz@example.com');
646
+ * console.log(myURL.username);
647
+ * // Prints abc
648
+ *
649
+ * myURL.username = '123';
650
+ * console.log(myURL.href);
651
+ * // Prints https://123:xyz@example.com/
652
+ * ```
653
+ *
654
+ * Any invalid URL characters appearing in the value assigned the `username`property will be `percent-encoded`. The selection of which
655
+ * characters to percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
656
+ */
102
657
  username: string;
658
+ /**
659
+ * The `toString()` method on the `URL` object returns the serialized URL. The
660
+ * value returned is equivalent to that of {@link href} and {@link toJSON}.
661
+ */
103
662
  toString(): string;
663
+ /**
664
+ * The `toJSON()` method on the `URL` object returns the serialized URL. The
665
+ * value returned is equivalent to that of {@link href} and {@link toString}.
666
+ *
667
+ * This method is automatically called when an `URL` object is serialized
668
+ * with [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).
669
+ *
670
+ * ```js
671
+ * const myURLs = [
672
+ * new URL('https://www.example.com'),
673
+ * new URL('https://test.example.org'),
674
+ * ];
675
+ * console.log(JSON.stringify(myURLs));
676
+ * // Prints ["https://www.example.com/","https://test.example.org/"]
677
+ * ```
678
+ */
104
679
  toJSON(): string;
105
680
  }
106
-
681
+ /**
682
+ * The `URLSearchParams` API provides read and write access to the query of a`URL`. The `URLSearchParams` class can also be used standalone with one of the
683
+ * four following constructors.
684
+ * The `URLSearchParams` class is also available on the global object.
685
+ *
686
+ * The WHATWG `URLSearchParams` interface and the `querystring` module have
687
+ * similar purpose, but the purpose of the `querystring` module is more
688
+ * general, as it allows the customization of delimiter characters (`&#x26;` and `=`).
689
+ * On the other hand, this API is designed purely for URL query strings.
690
+ *
691
+ * ```js
692
+ * const myURL = new URL('https://example.org/?abc=123');
693
+ * console.log(myURL.searchParams.get('abc'));
694
+ * // Prints 123
695
+ *
696
+ * myURL.searchParams.append('abc', 'xyz');
697
+ * console.log(myURL.href);
698
+ * // Prints https://example.org/?abc=123&#x26;abc=xyz
699
+ *
700
+ * myURL.searchParams.delete('abc');
701
+ * myURL.searchParams.set('a', 'b');
702
+ * console.log(myURL.href);
703
+ * // Prints https://example.org/?a=b
704
+ *
705
+ * const newSearchParams = new URLSearchParams(myURL.searchParams);
706
+ * // The above is equivalent to
707
+ * // const newSearchParams = new URLSearchParams(myURL.search);
708
+ *
709
+ * newSearchParams.append('a', 'c');
710
+ * console.log(myURL.href);
711
+ * // Prints https://example.org/?a=b
712
+ * console.log(newSearchParams.toString());
713
+ * // Prints a=b&#x26;a=c
714
+ *
715
+ * // newSearchParams.toString() is implicitly called
716
+ * myURL.search = newSearchParams;
717
+ * console.log(myURL.href);
718
+ * // Prints https://example.org/?a=b&#x26;a=c
719
+ * newSearchParams.delete('a');
720
+ * console.log(myURL.href);
721
+ * // Prints https://example.org/?a=b&#x26;a=c
722
+ * ```
723
+ * @since v7.5.0, v6.13.0
724
+ */
107
725
  class URLSearchParams implements Iterable<[string, string]> {
108
726
  constructor(init?: URLSearchParams | string | NodeJS.Dict<string | ReadonlyArray<string>> | Iterable<[string, string]> | ReadonlyArray<[string, string]>);
727
+ /**
728
+ * Append a new name-value pair to the query string.
729
+ */
109
730
  append(name: string, value: string): void;
731
+ /**
732
+ * Remove all name-value pairs whose name is `name`.
733
+ */
110
734
  delete(name: string): void;
735
+ /**
736
+ * Returns an ES6 `Iterator` over each of the name-value pairs in the query.
737
+ * Each item of the iterator is a JavaScript `Array`. The first item of the `Array`is the `name`, the second item of the `Array` is the `value`.
738
+ *
739
+ * Alias for {@link earchParams[@@iterator]}.
740
+ */
111
741
  entries(): IterableIterator<[string, string]>;
112
- forEach(callback: (value: string, name: string, searchParams: this) => void): void;
742
+ /**
743
+ * Iterates over each name-value pair in the query and invokes the given function.
744
+ *
745
+ * ```js
746
+ * const myURL = new URL('https://example.org/?a=b&#x26;c=d');
747
+ * myURL.searchParams.forEach((value, name, searchParams) => {
748
+ * console.log(name, value, myURL.searchParams === searchParams);
749
+ * });
750
+ * // Prints:
751
+ * // a b true
752
+ * // c d true
753
+ * ```
754
+ * @param fn Invoked for each name-value pair in the query
755
+ * @param thisArg To be used as `this` value for when `fn` is called
756
+ */
757
+ forEach<TThis = this>(callback: (this: TThis, value: string, name: string, searchParams: this) => void, thisArg?: TThis): void;
758
+ /**
759
+ * Returns the value of the first name-value pair whose name is `name`. If there
760
+ * are no such pairs, `null` is returned.
761
+ * @return or `null` if there is no name-value pair with the given `name`.
762
+ */
113
763
  get(name: string): string | null;
764
+ /**
765
+ * Returns the values of all name-value pairs whose name is `name`. If there are
766
+ * no such pairs, an empty array is returned.
767
+ */
114
768
  getAll(name: string): string[];
769
+ /**
770
+ * Returns `true` if there is at least one name-value pair whose name is `name`.
771
+ */
115
772
  has(name: string): boolean;
773
+ /**
774
+ * Returns an ES6 `Iterator` over the names of each name-value pair.
775
+ *
776
+ * ```js
777
+ * const params = new URLSearchParams('foo=bar&#x26;foo=baz');
778
+ * for (const name of params.keys()) {
779
+ * console.log(name);
780
+ * }
781
+ * // Prints:
782
+ * // foo
783
+ * // foo
784
+ * ```
785
+ */
116
786
  keys(): IterableIterator<string>;
787
+ /**
788
+ * Sets the value in the `URLSearchParams` object associated with `name` to`value`. If there are any pre-existing name-value pairs whose names are `name`,
789
+ * set the first such pair's value to `value` and remove all others. If not,
790
+ * append the name-value pair to the query string.
791
+ *
792
+ * ```js
793
+ * const params = new URLSearchParams();
794
+ * params.append('foo', 'bar');
795
+ * params.append('foo', 'baz');
796
+ * params.append('abc', 'def');
797
+ * console.log(params.toString());
798
+ * // Prints foo=bar&#x26;foo=baz&#x26;abc=def
799
+ *
800
+ * params.set('foo', 'def');
801
+ * params.set('xyz', 'opq');
802
+ * console.log(params.toString());
803
+ * // Prints foo=def&#x26;abc=def&#x26;xyz=opq
804
+ * ```
805
+ */
117
806
  set(name: string, value: string): void;
807
+ /**
808
+ * Sort all existing name-value pairs in-place by their names. Sorting is done
809
+ * with a [stable sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability), so relative order between name-value pairs
810
+ * with the same name is preserved.
811
+ *
812
+ * This method can be used, in particular, to increase cache hits.
813
+ *
814
+ * ```js
815
+ * const params = new URLSearchParams('query[]=abc&#x26;type=search&#x26;query[]=123');
816
+ * params.sort();
817
+ * console.log(params.toString());
818
+ * // Prints query%5B%5D=abc&#x26;query%5B%5D=123&#x26;type=search
819
+ * ```
820
+ * @since v7.7.0, v6.13.0
821
+ */
118
822
  sort(): void;
823
+ /**
824
+ * Returns the search parameters serialized as a string, with characters
825
+ * percent-encoded where necessary.
826
+ */
119
827
  toString(): string;
828
+ /**
829
+ * Returns an ES6 `Iterator` over the values of each name-value pair.
830
+ */
120
831
  values(): IterableIterator<string>;
121
832
  [Symbol.iterator](): IterableIterator<[string, string]>;
122
833
  }
123
834
  }
124
-
125
835
  declare module 'node:url' {
126
836
  export * from 'url';
127
837
  }