@types/node 18.19.22 → 18.19.23

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