@types/node 16.3.3 → 16.4.3

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