@types/node 24.12.0 → 25.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. node v24.12/README.md → node/README.md +2 -2
  2. node v24.12/assert/strict.d.ts → node/assert/strict.d.ts +5 -11
  3. node v24.12/assert.d.ts → node/assert.d.ts +11 -171
  4. node v24.12/async_hooks.d.ts → node/async_hooks.d.ts +8 -8
  5. node v24.12/buffer.buffer.d.ts → node/buffer.buffer.d.ts +1 -7
  6. node v24.12/buffer.d.ts → node/buffer.d.ts +44 -168
  7. node v24.12/child_process.d.ts → node/child_process.d.ts +21 -64
  8. node/cluster.d.ts +486 -0
  9. node/console.d.ts +151 -0
  10. node v24.12/constants.d.ts → node/constants.d.ts +3 -4
  11. node v24.12/crypto.d.ts → node/crypto.d.ts +287 -1639
  12. node v24.12/dgram.d.ts → node/dgram.d.ts +15 -51
  13. node v24.12/diagnostics_channel.d.ts → node/diagnostics_channel.d.ts +4 -4
  14. node v24.12/dns/promises.d.ts → node/dns/promises.d.ts +3 -3
  15. node v24.12/dns.d.ts → node/dns.d.ts +131 -132
  16. node v24.12/domain.d.ts → node/domain.d.ts +13 -17
  17. node v24.12/events.d.ts → node/events.d.ts +866 -795
  18. node v24.12/fs/promises.d.ts → node/fs/promises.d.ts +7 -8
  19. node v24.12/fs.d.ts → node/fs.d.ts +419 -455
  20. node v24.12/globals.d.ts → node/globals.d.ts +6 -26
  21. node/globals.typedarray.d.ts +101 -0
  22. node v24.12/http.d.ts → node/http.d.ts +310 -276
  23. node v24.12/http2.d.ts → node/http2.d.ts +528 -804
  24. node v24.12/https.d.ts → node/https.d.ts +63 -243
  25. node v24.12/index.d.ts → node/index.d.ts +15 -1
  26. node/inspector/promises.d.ts +41 -0
  27. node v24.12/inspector.d.ts → node/inspector.d.ts +42 -50
  28. node v24.12/inspector.generated.d.ts → node/inspector.generated.d.ts +572 -417
  29. node v24.12/module.d.ts → node/module.d.ts +47 -195
  30. node v24.12/net.d.ts → node/net.d.ts +68 -189
  31. node v24.12/os.d.ts → node/os.d.ts +6 -6
  32. node v24.12/package.json → node/package.json +3 -3
  33. node/path/posix.d.ts +8 -0
  34. node/path/win32.d.ts +8 -0
  35. node/path.d.ts +187 -0
  36. node/perf_hooks.d.ts +643 -0
  37. node v24.12/process.d.ts → node/process.d.ts +219 -127
  38. node v24.12/punycode.d.ts → node/punycode.d.ts +5 -5
  39. node v24.12/querystring.d.ts → node/querystring.d.ts +4 -4
  40. node/quic.d.ts +910 -0
  41. node v24.12/readline/promises.d.ts → node/readline/promises.d.ts +3 -3
  42. node v24.12/readline.d.ts → node/readline.d.ts +68 -120
  43. node v24.12/repl.d.ts → node/repl.d.ts +75 -98
  44. node v24.12/sea.d.ts → node/sea.d.ts +1 -1
  45. node v24.12/sqlite.d.ts → node/sqlite.d.ts +137 -30
  46. node v24.12/stream/consumers.d.ts → node/stream/consumers.d.ts +10 -10
  47. node/stream/promises.d.ts +211 -0
  48. node/stream/web.d.ts +296 -0
  49. node v24.12/stream.d.ts → node/stream.d.ts +565 -478
  50. node v24.12/string_decoder.d.ts → node/string_decoder.d.ts +4 -4
  51. node/test/reporters.d.ts +96 -0
  52. node v24.12/test.d.ts → node/test.d.ts +134 -199
  53. node v24.12/timers/promises.d.ts → node/timers/promises.d.ts +4 -4
  54. node v24.12/timers.d.ts → node/timers.d.ts +4 -130
  55. node v24.12/tls.d.ts → node/tls.d.ts +109 -179
  56. node v24.12/trace_events.d.ts → node/trace_events.d.ts +9 -9
  57. node v24.12/ts5.6/buffer.buffer.d.ts → node/ts5.6/buffer.buffer.d.ts +1 -7
  58. node v24.12/ts5.6/index.d.ts → node/ts5.6/index.d.ts +15 -1
  59. node v24.12/ts5.7/index.d.ts → node/ts5.7/index.d.ts +15 -1
  60. node v24.12/tty.d.ts → node/tty.d.ts +58 -16
  61. node/url.d.ts +541 -0
  62. node/util/types.d.ts +558 -0
  63. node v24.12/util.d.ts → node/util.d.ts +150 -796
  64. node v24.12/v8.d.ts → node/v8.d.ts +31 -21
  65. node v24.12/vm.d.ts → node/vm.d.ts +43 -30
  66. node v24.12/wasi.d.ts → node/wasi.d.ts +4 -4
  67. node v24.12/web-globals/abortcontroller.d.ts → node/web-globals/abortcontroller.d.ts +27 -2
  68. node/web-globals/blob.d.ts +23 -0
  69. node/web-globals/console.d.ts +9 -0
  70. node v24.12/web-globals/crypto.d.ts → node/web-globals/crypto.d.ts +7 -0
  71. node/web-globals/encoding.d.ts +11 -0
  72. node v24.12/web-globals/events.d.ts → node/web-globals/events.d.ts +9 -0
  73. node v24.12/web-globals/fetch.d.ts → node/web-globals/fetch.d.ts +7 -0
  74. node/web-globals/importmeta.d.ts +13 -0
  75. node/web-globals/messaging.d.ts +23 -0
  76. node/web-globals/performance.d.ts +45 -0
  77. node/web-globals/streams.d.ts +115 -0
  78. node/web-globals/timers.d.ts +44 -0
  79. node/web-globals/url.d.ts +24 -0
  80. node v24.12/worker_threads.d.ts → node/worker_threads.d.ts +186 -363
  81. node v24.12/zlib.d.ts → node/zlib.d.ts +8 -71
  82. node v24.12/cluster.d.ts +0 -578
  83. node v24.12/console.d.ts +0 -453
  84. node v24.12/globals.typedarray.d.ts +0 -41
  85. node v24.12/path.d.ts +0 -200
  86. node v24.12/perf_hooks.d.ts +0 -1042
  87. node v24.12/stream/promises.d.ts +0 -90
  88. node v24.12/stream/web.d.ts +0 -573
  89. node v24.12/url.d.ts +0 -1057
  90. node v24.12/web-globals/streams.d.ts +0 -22
  91. {node v24.12 → node}/LICENSE +0 -0
  92. {node v24.12 → node}/compatibility/iterators.d.ts +0 -0
  93. {node v24.12 → node}/ts5.6/compatibility/float16array.d.ts +0 -0
  94. {node v24.12 → node}/ts5.6/globals.typedarray.d.ts +0 -0
  95. {node v24.12 → node}/ts5.7/compatibility/float16array.d.ts +0 -0
  96. {node v24.12 → node}/web-globals/domexception.d.ts +0 -0
  97. {node v24.12 → node}/web-globals/navigator.d.ts +0 -0
  98. {node v24.12 → node}/web-globals/storage.d.ts +0 -0
node/url.d.ts ADDED
@@ -0,0 +1,541 @@
1
+ /**
2
+ * The `node:url` module provides utilities for URL resolution and parsing. It can
3
+ * be accessed using:
4
+ *
5
+ * ```js
6
+ * import url from 'node:url';
7
+ * ```
8
+ * @see [source](https://github.com/nodejs/node/blob/v25.x/lib/url.js)
9
+ */
10
+ declare module "node:url" {
11
+ import { Blob, NonSharedBuffer } 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
+ interface FileUrlToPathOptions {
50
+ /**
51
+ * `true` if the `path` should be return as a windows filepath, `false` for posix, and `undefined` for the system default.
52
+ * @default undefined
53
+ * @since v22.1.0
54
+ */
55
+ windows?: boolean | undefined;
56
+ }
57
+ interface PathToFileUrlOptions {
58
+ /**
59
+ * `true` if the `path` should be return as a windows filepath, `false` for posix, and `undefined` for the system default.
60
+ * @default undefined
61
+ * @since v22.1.0
62
+ */
63
+ windows?: boolean | undefined;
64
+ }
65
+ /**
66
+ * The `url.parse()` method takes a URL string, parses it, and returns a URL
67
+ * object.
68
+ *
69
+ * A `TypeError` is thrown if `urlString` is not a string.
70
+ *
71
+ * A `URIError` is thrown if the `auth` property is present but cannot be decoded.
72
+ *
73
+ * `url.parse()` uses a lenient, non-standard algorithm for parsing URL
74
+ * strings. It is prone to security issues such as [host name spoofing](https://hackerone.com/reports/678487)
75
+ * and incorrect handling of usernames and passwords. Do not use with untrusted
76
+ * input. CVEs are not issued for `url.parse()` vulnerabilities. Use the
77
+ * [WHATWG URL](https://nodejs.org/docs/latest-v25.x/api/url.html#the-whatwg-url-api) API instead, for example:
78
+ *
79
+ * ```js
80
+ * function getURL(req) {
81
+ * const proto = req.headers['x-forwarded-proto'] || 'https';
82
+ * const host = req.headers['x-forwarded-host'] || req.headers.host || 'example.com';
83
+ * return new URL(req.url || '/', `${proto}://${host}`);
84
+ * }
85
+ * ```
86
+ *
87
+ * The example above assumes well-formed headers are forwarded from a reverse
88
+ * proxy to your Node.js server. If you are not using a reverse proxy, you should
89
+ * use the example below:
90
+ *
91
+ * ```js
92
+ * function getURL(req) {
93
+ * return new URL(req.url || '/', 'https://example.com');
94
+ * }
95
+ * ```
96
+ * @since v0.1.25
97
+ * @deprecated Use the WHATWG URL API instead.
98
+ * @param urlString The URL string to parse.
99
+ * @param parseQueryString If `true`, the `query` property will always
100
+ * be set to an object returned by the [`querystring`](https://nodejs.org/docs/latest-v25.x/api/querystring.html) module's `parse()`
101
+ * method. If `false`, the `query` property on the returned URL object will be an
102
+ * unparsed, undecoded string. **Default:** `false`.
103
+ * @param slashesDenoteHost If `true`, the first token after the literal
104
+ * string `//` and preceding the next `/` will be interpreted as the `host`.
105
+ * For instance, given `//foo/bar`, the result would be
106
+ * `{host: 'foo', pathname: '/bar'}` rather than `{pathname: '//foo/bar'}`.
107
+ * **Default:** `false`.
108
+ */
109
+ function parse(
110
+ urlString: string,
111
+ parseQueryString?: false,
112
+ slashesDenoteHost?: boolean,
113
+ ): UrlWithStringQuery;
114
+ function parse(urlString: string, parseQueryString: true, slashesDenoteHost?: boolean): UrlWithParsedQuery;
115
+ function parse(urlString: string, parseQueryString: boolean, slashesDenoteHost?: boolean): Url;
116
+ /**
117
+ * The `url.format()` method returns a formatted URL string derived from `urlObject`.
118
+ *
119
+ * ```js
120
+ * import url from 'node:url';
121
+ * url.format({
122
+ * protocol: 'https',
123
+ * hostname: 'example.com',
124
+ * pathname: '/some/path',
125
+ * query: {
126
+ * page: 1,
127
+ * format: 'json',
128
+ * },
129
+ * });
130
+ *
131
+ * // => 'https://example.com/some/path?page=1&format=json'
132
+ * ```
133
+ *
134
+ * If `urlObject` is not an object or a string, `url.format()` will throw a `TypeError`.
135
+ *
136
+ * The formatting process operates as follows:
137
+ *
138
+ * * A new empty string `result` is created.
139
+ * * If `urlObject.protocol` is a string, it is appended as-is to `result`.
140
+ * * Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an `Error` is thrown.
141
+ * * For all string values of `urlObject.protocol` that _do not end_ with an ASCII
142
+ * colon (`:`) character, the literal string `:` will be appended to `result`.
143
+ * * If either of the following conditions is true, then the literal string `//` will be appended to `result`:
144
+ * * `urlObject.slashes` property is true;
145
+ * * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or `file`;
146
+ * * 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
147
+ * and appended to `result` followed by the literal string `@`.
148
+ * * If the `urlObject.host` property is `undefined` then:
149
+ * * If the `urlObject.hostname` is a string, it is appended to `result`.
150
+ * * Otherwise, if `urlObject.hostname` is not `undefined` and is not a string,
151
+ * an `Error` is thrown.
152
+ * * If the `urlObject.port` property value is truthy, and `urlObject.hostname` is not `undefined`:
153
+ * * The literal string `:` is appended to `result`, and
154
+ * * The value of `urlObject.port` is coerced to a string and appended to `result`.
155
+ * * Otherwise, if the `urlObject.host` property value is truthy, the value of `urlObject.host` is coerced to a string and appended to `result`.
156
+ * * If the `urlObject.pathname` property is a string that is not an empty string:
157
+ * * If the `urlObject.pathname` _does not start_ with an ASCII forward slash
158
+ * (`/`), then the literal string `'/'` is appended to `result`.
159
+ * * The value of `urlObject.pathname` is appended to `result`.
160
+ * * Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an `Error` is thrown.
161
+ * * 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
162
+ * `querystring` module's `stringify()` method passing the value of `urlObject.query`.
163
+ * * Otherwise, if `urlObject.search` is a string:
164
+ * * If the value of `urlObject.search` _does not start_ with the ASCII question
165
+ * mark (`?`) character, the literal string `?` is appended to `result`.
166
+ * * The value of `urlObject.search` is appended to `result`.
167
+ * * Otherwise, if `urlObject.search` is not `undefined` and is not a string, an `Error` is thrown.
168
+ * * If the `urlObject.hash` property is a string:
169
+ * * If the value of `urlObject.hash` _does not start_ with the ASCII hash (`#`)
170
+ * character, the literal string `#` is appended to `result`.
171
+ * * The value of `urlObject.hash` is appended to `result`.
172
+ * * Otherwise, if the `urlObject.hash` property is not `undefined` and is not a
173
+ * string, an `Error` is thrown.
174
+ * * `result` is returned.
175
+ * @since v0.1.25
176
+ * @legacy Use the WHATWG URL API instead.
177
+ * @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()`.
178
+ */
179
+ function format(urlObject: URL, options?: URLFormatOptions): string;
180
+ /**
181
+ * The `url.format()` method returns a formatted URL string derived from `urlObject`.
182
+ *
183
+ * ```js
184
+ * import url from 'node:url';
185
+ * url.format({
186
+ * protocol: 'https',
187
+ * hostname: 'example.com',
188
+ * pathname: '/some/path',
189
+ * query: {
190
+ * page: 1,
191
+ * format: 'json',
192
+ * },
193
+ * });
194
+ *
195
+ * // => 'https://example.com/some/path?page=1&format=json'
196
+ * ```
197
+ *
198
+ * If `urlObject` is not an object or a string, `url.format()` will throw a `TypeError`.
199
+ *
200
+ * The formatting process operates as follows:
201
+ *
202
+ * * A new empty string `result` is created.
203
+ * * If `urlObject.protocol` is a string, it is appended as-is to `result`.
204
+ * * Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an `Error` is thrown.
205
+ * * For all string values of `urlObject.protocol` that _do not end_ with an ASCII
206
+ * colon (`:`) character, the literal string `:` will be appended to `result`.
207
+ * * If either of the following conditions is true, then the literal string `//` will be appended to `result`:
208
+ * * `urlObject.slashes` property is true;
209
+ * * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or `file`;
210
+ * * 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
211
+ * and appended to `result` followed by the literal string `@`.
212
+ * * If the `urlObject.host` property is `undefined` then:
213
+ * * If the `urlObject.hostname` is a string, it is appended to `result`.
214
+ * * Otherwise, if `urlObject.hostname` is not `undefined` and is not a string,
215
+ * an `Error` is thrown.
216
+ * * If the `urlObject.port` property value is truthy, and `urlObject.hostname` is not `undefined`:
217
+ * * The literal string `:` is appended to `result`, and
218
+ * * The value of `urlObject.port` is coerced to a string and appended to `result`.
219
+ * * Otherwise, if the `urlObject.host` property value is truthy, the value of `urlObject.host` is coerced to a string and appended to `result`.
220
+ * * If the `urlObject.pathname` property is a string that is not an empty string:
221
+ * * If the `urlObject.pathname` _does not start_ with an ASCII forward slash
222
+ * (`/`), then the literal string `'/'` is appended to `result`.
223
+ * * The value of `urlObject.pathname` is appended to `result`.
224
+ * * Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an `Error` is thrown.
225
+ * * 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
226
+ * `querystring` module's `stringify()` method passing the value of `urlObject.query`.
227
+ * * Otherwise, if `urlObject.search` is a string:
228
+ * * If the value of `urlObject.search` _does not start_ with the ASCII question
229
+ * mark (`?`) character, the literal string `?` is appended to `result`.
230
+ * * The value of `urlObject.search` is appended to `result`.
231
+ * * Otherwise, if `urlObject.search` is not `undefined` and is not a string, an `Error` is thrown.
232
+ * * If the `urlObject.hash` property is a string:
233
+ * * If the value of `urlObject.hash` _does not start_ with the ASCII hash (`#`)
234
+ * character, the literal string `#` is appended to `result`.
235
+ * * The value of `urlObject.hash` is appended to `result`.
236
+ * * Otherwise, if the `urlObject.hash` property is not `undefined` and is not a
237
+ * string, an `Error` is thrown.
238
+ * * `result` is returned.
239
+ * @since v0.1.25
240
+ * @legacy Use the WHATWG URL API instead.
241
+ * @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()`.
242
+ */
243
+ function format(urlObject: UrlObject | string): string;
244
+ /**
245
+ * The `url.resolve()` method resolves a target URL relative to a base URL in a
246
+ * manner similar to that of a web browser resolving an anchor tag.
247
+ *
248
+ * ```js
249
+ * import url from 'node:url';
250
+ * url.resolve('/one/two/three', 'four'); // '/one/two/four'
251
+ * url.resolve('http://example.com/', '/one'); // 'http://example.com/one'
252
+ * url.resolve('http://example.com/one', '/two'); // 'http://example.com/two'
253
+ * ```
254
+ *
255
+ * To achieve the same result using the WHATWG URL API:
256
+ *
257
+ * ```js
258
+ * function resolve(from, to) {
259
+ * const resolvedUrl = new URL(to, new URL(from, 'resolve://'));
260
+ * if (resolvedUrl.protocol === 'resolve:') {
261
+ * // `from` is a relative URL.
262
+ * const { pathname, search, hash } = resolvedUrl;
263
+ * return pathname + search + hash;
264
+ * }
265
+ * return resolvedUrl.toString();
266
+ * }
267
+ *
268
+ * resolve('/one/two/three', 'four'); // '/one/two/four'
269
+ * resolve('http://example.com/', '/one'); // 'http://example.com/one'
270
+ * resolve('http://example.com/one', '/two'); // 'http://example.com/two'
271
+ * ```
272
+ * @since v0.1.25
273
+ * @legacy Use the WHATWG URL API instead.
274
+ * @param from The base URL to use if `to` is a relative URL.
275
+ * @param to The target URL to resolve.
276
+ */
277
+ function resolve(from: string, to: string): string;
278
+ /**
279
+ * Returns the [Punycode](https://tools.ietf.org/html/rfc5891#section-4.4) ASCII serialization of the `domain`. If `domain` is an
280
+ * invalid domain, the empty string is returned.
281
+ *
282
+ * It performs the inverse operation to {@link domainToUnicode}.
283
+ *
284
+ * ```js
285
+ * import url from 'node:url';
286
+ *
287
+ * console.log(url.domainToASCII('español.com'));
288
+ * // Prints xn--espaol-zwa.com
289
+ * console.log(url.domainToASCII('中文.com'));
290
+ * // Prints xn--fiq228c.com
291
+ * console.log(url.domainToASCII('xn--iñvalid.com'));
292
+ * // Prints an empty string
293
+ * ```
294
+ * @since v7.4.0, v6.13.0
295
+ */
296
+ function domainToASCII(domain: string): string;
297
+ /**
298
+ * Returns the Unicode serialization of the `domain`. If `domain` is an invalid
299
+ * domain, the empty string is returned.
300
+ *
301
+ * It performs the inverse operation to {@link domainToASCII}.
302
+ *
303
+ * ```js
304
+ * import url from 'node:url';
305
+ *
306
+ * console.log(url.domainToUnicode('xn--espaol-zwa.com'));
307
+ * // Prints español.com
308
+ * console.log(url.domainToUnicode('xn--fiq228c.com'));
309
+ * // Prints 中文.com
310
+ * console.log(url.domainToUnicode('xn--iñvalid.com'));
311
+ * // Prints an empty string
312
+ * ```
313
+ * @since v7.4.0, v6.13.0
314
+ */
315
+ function domainToUnicode(domain: string): string;
316
+ /**
317
+ * This function ensures the correct decodings of percent-encoded characters as
318
+ * well as ensuring a cross-platform valid absolute path string.
319
+ *
320
+ * ```js
321
+ * import { fileURLToPath } from 'node:url';
322
+ *
323
+ * const __filename = fileURLToPath(import.meta.url);
324
+ *
325
+ * new URL('file:///C:/path/').pathname; // Incorrect: /C:/path/
326
+ * fileURLToPath('file:///C:/path/'); // Correct: C:\path\ (Windows)
327
+ *
328
+ * new URL('file://nas/foo.txt').pathname; // Incorrect: /foo.txt
329
+ * fileURLToPath('file://nas/foo.txt'); // Correct: \\nas\foo.txt (Windows)
330
+ *
331
+ * new URL('file:///你好.txt').pathname; // Incorrect: /%E4%BD%A0%E5%A5%BD.txt
332
+ * fileURLToPath('file:///你好.txt'); // Correct: /你好.txt (POSIX)
333
+ *
334
+ * new URL('file:///hello world').pathname; // Incorrect: /hello%20world
335
+ * fileURLToPath('file:///hello world'); // Correct: /hello world (POSIX)
336
+ * ```
337
+ *
338
+ * **Security Considerations:**
339
+ *
340
+ * This function decodes percent-encoded characters, including encoded dot-segments
341
+ * (`%2e` as `.` and `%2e%2e` as `..`), and then normalizes the resulting path.
342
+ * This means that encoded directory traversal sequences (such as `%2e%2e`) are
343
+ * decoded and processed as actual path traversal, even though encoded slashes
344
+ * (`%2F`, `%5C`) are correctly rejected.
345
+ *
346
+ * **Applications must not rely on `fileURLToPath()` alone to prevent directory
347
+ * traversal attacks.** Always perform explicit path validation and security checks
348
+ * on the returned path value to ensure it remains within expected boundaries
349
+ * before using it for file system operations.
350
+ * @since v10.12.0
351
+ * @param url The file URL string or URL object to convert to a path.
352
+ * @return The fully-resolved platform-specific Node.js file path.
353
+ */
354
+ function fileURLToPath(url: string | URL, options?: FileUrlToPathOptions): string;
355
+ /**
356
+ * Like `url.fileURLToPath(...)` except that instead of returning a string
357
+ * representation of the path, a `Buffer` is returned. This conversion is
358
+ * helpful when the input URL contains percent-encoded segments that are
359
+ * not valid UTF-8 / Unicode sequences.
360
+ *
361
+ * **Security Considerations:**
362
+ *
363
+ * This function has the same security considerations as `url.fileURLToPath()`.
364
+ * It decodes percent-encoded characters, including encoded dot-segments
365
+ * (`%2e` as `.` and `%2e%2e` as `..`), and normalizes the path. **Applications
366
+ * must not rely on this function alone to prevent directory traversal attacks.**
367
+ * Always perform explicit path validation on the returned buffer value before
368
+ * using it for file system operations.
369
+ * @since v24.3.0
370
+ * @param url The file URL string or URL object to convert to a path.
371
+ * @returns The fully-resolved platform-specific Node.js file path
372
+ * as a `Buffer`.
373
+ */
374
+ function fileURLToPathBuffer(url: string | URL, options?: FileUrlToPathOptions): NonSharedBuffer;
375
+ /**
376
+ * This function ensures that `path` is resolved absolutely, and that the URL
377
+ * control characters are correctly encoded when converting into a File URL.
378
+ *
379
+ * ```js
380
+ * import { pathToFileURL } from 'node:url';
381
+ *
382
+ * new URL('/foo#1', 'file:'); // Incorrect: file:///foo#1
383
+ * pathToFileURL('/foo#1'); // Correct: file:///foo%231 (POSIX)
384
+ *
385
+ * new URL('/some/path%.c', 'file:'); // Incorrect: file:///some/path%.c
386
+ * pathToFileURL('/some/path%.c'); // Correct: file:///some/path%25.c (POSIX)
387
+ * ```
388
+ * @since v10.12.0
389
+ * @param path The path to convert to a File URL.
390
+ * @return The file URL object.
391
+ */
392
+ function pathToFileURL(path: string, options?: PathToFileUrlOptions): URL;
393
+ /**
394
+ * This utility function converts a URL object into an ordinary options object as
395
+ * expected by the `http.request()` and `https.request()` APIs.
396
+ *
397
+ * ```js
398
+ * import { urlToHttpOptions } from 'node:url';
399
+ * const myURL = new URL('https://a:b@測試?abc#foo');
400
+ *
401
+ * console.log(urlToHttpOptions(myURL));
402
+ * /*
403
+ * {
404
+ * protocol: 'https:',
405
+ * hostname: 'xn--g6w251d',
406
+ * hash: '#foo',
407
+ * search: '?abc',
408
+ * pathname: '/',
409
+ * path: '/?abc',
410
+ * href: 'https://a:b@xn--g6w251d/?abc#foo',
411
+ * auth: 'a:b'
412
+ * }
413
+ *
414
+ * ```
415
+ * @since v15.7.0, v14.18.0
416
+ * @param url The `WHATWG URL` object to convert to an options object.
417
+ * @return Options object
418
+ */
419
+ function urlToHttpOptions(url: URL): ClientRequestArgs;
420
+ interface URLFormatOptions {
421
+ /**
422
+ * `true` if the serialized URL string should include the username and password, `false` otherwise.
423
+ * @default true
424
+ */
425
+ auth?: boolean | undefined;
426
+ /**
427
+ * `true` if the serialized URL string should include the fragment, `false` otherwise.
428
+ * @default true
429
+ */
430
+ fragment?: boolean | undefined;
431
+ /**
432
+ * `true` if the serialized URL string should include the search query, `false` otherwise.
433
+ * @default true
434
+ */
435
+ search?: boolean | undefined;
436
+ /**
437
+ * `true` if Unicode characters appearing in the host component of the URL string should be encoded directly as opposed to
438
+ * being Punycode encoded.
439
+ * @default false
440
+ */
441
+ unicode?: boolean | undefined;
442
+ }
443
+ // #region web types
444
+ type URLPatternInput = string | URLPatternInit;
445
+ interface URLPatternComponentResult {
446
+ input: string;
447
+ groups: Record<string, string | undefined>;
448
+ }
449
+ interface URLPatternInit {
450
+ protocol?: string;
451
+ username?: string;
452
+ password?: string;
453
+ hostname?: string;
454
+ port?: string;
455
+ pathname?: string;
456
+ search?: string;
457
+ hash?: string;
458
+ baseURL?: string;
459
+ }
460
+ interface URLPatternOptions {
461
+ ignoreCase?: boolean;
462
+ }
463
+ interface URLPatternResult {
464
+ inputs: URLPatternInput[];
465
+ protocol: URLPatternComponentResult;
466
+ username: URLPatternComponentResult;
467
+ password: URLPatternComponentResult;
468
+ hostname: URLPatternComponentResult;
469
+ port: URLPatternComponentResult;
470
+ pathname: URLPatternComponentResult;
471
+ search: URLPatternComponentResult;
472
+ hash: URLPatternComponentResult;
473
+ }
474
+ interface URL {
475
+ hash: string;
476
+ host: string;
477
+ hostname: string;
478
+ href: string;
479
+ readonly origin: string;
480
+ password: string;
481
+ pathname: string;
482
+ port: string;
483
+ protocol: string;
484
+ search: string;
485
+ readonly searchParams: URLSearchParams;
486
+ username: string;
487
+ toJSON(): string;
488
+ }
489
+ var URL: {
490
+ prototype: URL;
491
+ new(url: string | URL, base?: string | URL): URL;
492
+ canParse(input: string | URL, base?: string | URL): boolean;
493
+ createObjectURL(blob: Blob): string;
494
+ parse(input: string | URL, base?: string | URL): URL | null;
495
+ revokeObjectURL(id: string): void;
496
+ };
497
+ interface URLPattern {
498
+ readonly hasRegExpGroups: boolean;
499
+ readonly hash: string;
500
+ readonly hostname: string;
501
+ readonly password: string;
502
+ readonly pathname: string;
503
+ readonly port: string;
504
+ readonly protocol: string;
505
+ readonly search: string;
506
+ readonly username: string;
507
+ exec(input?: URLPatternInput, baseURL?: string | URL): URLPatternResult | null;
508
+ test(input?: URLPatternInput, baseURL?: string | URL): boolean;
509
+ }
510
+ var URLPattern: {
511
+ prototype: URLPattern;
512
+ new(input: URLPatternInput, baseURL: string | URL, options?: URLPatternOptions): URLPattern;
513
+ new(input?: URLPatternInput, options?: URLPatternOptions): URLPattern;
514
+ };
515
+ interface URLSearchParams {
516
+ readonly size: number;
517
+ append(name: string, value: string): void;
518
+ delete(name: string, value?: string): void;
519
+ get(name: string): string | null;
520
+ getAll(name: string): string[];
521
+ has(name: string, value?: string): boolean;
522
+ set(name: string, value: string): void;
523
+ sort(): void;
524
+ forEach(callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any): void;
525
+ [Symbol.iterator](): URLSearchParamsIterator<[string, string]>;
526
+ entries(): URLSearchParamsIterator<[string, string]>;
527
+ keys(): URLSearchParamsIterator<string>;
528
+ values(): URLSearchParamsIterator<string>;
529
+ }
530
+ var URLSearchParams: {
531
+ prototype: URLSearchParams;
532
+ new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
533
+ };
534
+ interface URLSearchParamsIterator<T> extends NodeJS.Iterator<T, NodeJS.BuiltinIteratorReturn, unknown> {
535
+ [Symbol.iterator](): URLSearchParamsIterator<T>;
536
+ }
537
+ // #endregion
538
+ }
539
+ declare module "url" {
540
+ export * from "node:url";
541
+ }