@types/node 18.16.3 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- node/README.md +1 -1
- node/assert.d.ts +68 -73
- node/async_hooks.d.ts +62 -42
- node/buffer.d.ts +123 -95
- node/child_process.d.ts +50 -54
- node/cluster.d.ts +12 -12
- node/console.d.ts +5 -5
- node/crypto.d.ts +209 -220
- node/dgram.d.ts +15 -15
- node/diagnostics_channel.d.ts +25 -26
- node/dns/promises.d.ts +6 -6
- node/dns.d.ts +16 -16
- node/domain.d.ts +3 -3
- node/events.d.ts +60 -60
- node/fs/promises.d.ts +74 -48
- node/fs.d.ts +91 -81
- node/http.d.ts +147 -144
- node/http2.d.ts +42 -46
- node/https.d.ts +52 -153
- node/index.d.ts +1 -1
- node/inspector.d.ts +10 -3
- node/module.d.ts +5 -4
- node/net.d.ts +21 -18
- node/os.d.ts +22 -18
- node/package.json +2 -2
- node/path.d.ts +4 -4
- node/perf_hooks.d.ts +28 -15
- node/process.d.ts +43 -46
- node/punycode.d.ts +1 -1
- node/querystring.d.ts +5 -5
- node/readline/promises.d.ts +6 -4
- node/readline.d.ts +15 -15
- node/repl.d.ts +9 -9
- node/stream/consumers.d.ts +1 -1
- node/stream.d.ts +74 -136
- node/string_decoder.d.ts +6 -6
- node/test.d.ts +0 -76
- node/timers/promises.d.ts +3 -3
- node/timers.d.ts +2 -2
- node/tls.d.ts +22 -15
- node/trace_events.d.ts +20 -9
- node/ts4.8/assert.d.ts +68 -73
- node/ts4.8/async_hooks.d.ts +59 -31
- node/ts4.8/buffer.d.ts +123 -95
- node/ts4.8/child_process.d.ts +50 -54
- node/ts4.8/cluster.d.ts +12 -12
- node/ts4.8/console.d.ts +5 -5
- node/ts4.8/crypto.d.ts +209 -220
- node/ts4.8/dgram.d.ts +15 -15
- node/ts4.8/diagnostics_channel.d.ts +25 -26
- node/ts4.8/dns/promises.d.ts +6 -6
- node/ts4.8/dns.d.ts +16 -16
- node/ts4.8/domain.d.ts +3 -3
- node/ts4.8/events.d.ts +60 -60
- node/ts4.8/fs/promises.d.ts +72 -45
- node/ts4.8/fs.d.ts +81 -67
- node/ts4.8/http.d.ts +133 -126
- node/ts4.8/http2.d.ts +42 -46
- node/ts4.8/https.d.ts +52 -153
- node/ts4.8/inspector.d.ts +10 -3
- node/ts4.8/module.d.ts +5 -4
- node/ts4.8/net.d.ts +21 -18
- node/ts4.8/os.d.ts +22 -18
- node/ts4.8/path.d.ts +4 -4
- node/ts4.8/perf_hooks.d.ts +28 -15
- node/ts4.8/process.d.ts +43 -46
- node/ts4.8/punycode.d.ts +1 -1
- node/ts4.8/querystring.d.ts +5 -5
- node/ts4.8/readline/promises.d.ts +6 -4
- node/ts4.8/readline.d.ts +15 -15
- node/ts4.8/repl.d.ts +9 -9
- node/ts4.8/stream/consumers.d.ts +1 -1
- node/ts4.8/stream.d.ts +77 -139
- node/ts4.8/string_decoder.d.ts +6 -6
- node/ts4.8/test.d.ts +0 -75
- node/ts4.8/timers/promises.d.ts +3 -3
- node/ts4.8/timers.d.ts +2 -2
- node/ts4.8/tls.d.ts +22 -15
- node/ts4.8/trace_events.d.ts +20 -9
- node/ts4.8/tty.d.ts +4 -5
- node/ts4.8/url.d.ts +26 -36
- node/ts4.8/util.d.ts +143 -116
- node/ts4.8/v8.d.ts +107 -16
- node/ts4.8/vm.d.ts +292 -42
- node/ts4.8/wasi.d.ts +8 -14
- node/ts4.8/worker_threads.d.ts +32 -34
- node/ts4.8/zlib.d.ts +11 -11
- node/tty.d.ts +4 -5
- node/url.d.ts +26 -36
- node/util.d.ts +146 -111
- node/v8.d.ts +110 -16
- node/vm.d.ts +292 -42
- node/wasi.d.ts +8 -14
- node/worker_threads.d.ts +32 -34
- node/zlib.d.ts +11 -11
node/events.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* the `eventEmitter.emit()` method is used to trigger the event.
|
|
23
23
|
*
|
|
24
24
|
* ```js
|
|
25
|
-
*
|
|
25
|
+
* import { EventEmitter } from 'node:events';
|
|
26
26
|
*
|
|
27
27
|
* class MyEmitter extends EventEmitter {}
|
|
28
28
|
*
|
|
@@ -32,13 +32,12 @@
|
|
|
32
32
|
* });
|
|
33
33
|
* myEmitter.emit('event');
|
|
34
34
|
* ```
|
|
35
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
35
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.0.0/lib/events.js)
|
|
36
36
|
*/
|
|
37
37
|
declare module 'events' {
|
|
38
38
|
// NOTE: This class is in the docs but is **not actually exported** by Node.
|
|
39
39
|
// If https://github.com/nodejs/node/issues/39903 gets resolved and Node
|
|
40
40
|
// actually starts exporting the class, uncomment below.
|
|
41
|
-
|
|
42
41
|
// import { EventListener, EventListenerObject } from '__dom-events';
|
|
43
42
|
// /** The NodeEventTarget is a Node.js-specific extension to EventTarget that emulates a subset of the EventEmitter API. */
|
|
44
43
|
// interface NodeEventTarget extends EventTarget {
|
|
@@ -69,7 +68,6 @@ declare module 'events' {
|
|
|
69
68
|
// */
|
|
70
69
|
// removeListener(type: string, listener: EventListener | EventListenerObject): this;
|
|
71
70
|
// }
|
|
72
|
-
|
|
73
71
|
interface EventEmitterOptions {
|
|
74
72
|
/**
|
|
75
73
|
* Enables automatic capturing of promise rejection.
|
|
@@ -95,10 +93,10 @@ declare module 'events' {
|
|
|
95
93
|
}
|
|
96
94
|
interface EventEmitter extends NodeJS.EventEmitter {}
|
|
97
95
|
/**
|
|
98
|
-
* The `EventEmitter` class is defined and exposed by the `events` module:
|
|
96
|
+
* The `EventEmitter` class is defined and exposed by the `node:events` module:
|
|
99
97
|
*
|
|
100
98
|
* ```js
|
|
101
|
-
*
|
|
99
|
+
* import { EventEmitter } from 'node:events';
|
|
102
100
|
* ```
|
|
103
101
|
*
|
|
104
102
|
* All `EventEmitter`s emit the event `'newListener'` when new listeners are
|
|
@@ -119,31 +117,28 @@ declare module 'events' {
|
|
|
119
117
|
* semantics and does not listen to the `'error'` event.
|
|
120
118
|
*
|
|
121
119
|
* ```js
|
|
122
|
-
*
|
|
120
|
+
* import { once, EventEmitter } from 'node:events';
|
|
121
|
+
* import process from 'node:process';
|
|
123
122
|
*
|
|
124
|
-
*
|
|
125
|
-
* const ee = new EventEmitter();
|
|
123
|
+
* const ee = new EventEmitter();
|
|
126
124
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
125
|
+
* process.nextTick(() => {
|
|
126
|
+
* ee.emit('myevent', 42);
|
|
127
|
+
* });
|
|
130
128
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
129
|
+
* const [value] = await once(ee, 'myevent');
|
|
130
|
+
* console.log(value);
|
|
133
131
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
132
|
+
* const err = new Error('kaboom');
|
|
133
|
+
* process.nextTick(() => {
|
|
134
|
+
* ee.emit('error', err);
|
|
135
|
+
* });
|
|
138
136
|
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* }
|
|
137
|
+
* try {
|
|
138
|
+
* await once(ee, 'myevent');
|
|
139
|
+
* } catch (err) {
|
|
140
|
+
* console.error('error happened', err);
|
|
144
141
|
* }
|
|
145
|
-
*
|
|
146
|
-
* run();
|
|
147
142
|
* ```
|
|
148
143
|
*
|
|
149
144
|
* The special handling of the `'error'` event is only used when `events.once()`is used to wait for another event. If `events.once()` is used to wait for the
|
|
@@ -151,13 +146,13 @@ declare module 'events' {
|
|
|
151
146
|
* special handling:
|
|
152
147
|
*
|
|
153
148
|
* ```js
|
|
154
|
-
*
|
|
149
|
+
* import { EventEmitter, once } from 'node:events';
|
|
155
150
|
*
|
|
156
151
|
* const ee = new EventEmitter();
|
|
157
152
|
*
|
|
158
153
|
* once(ee, 'error')
|
|
159
154
|
* .then(([err]) => console.log('ok', err.message))
|
|
160
|
-
* .catch((err) => console.
|
|
155
|
+
* .catch((err) => console.error('error', err.message));
|
|
161
156
|
*
|
|
162
157
|
* ee.emit('error', new Error('boom'));
|
|
163
158
|
*
|
|
@@ -167,7 +162,7 @@ declare module 'events' {
|
|
|
167
162
|
* An `AbortSignal` can be used to cancel waiting for the event:
|
|
168
163
|
*
|
|
169
164
|
* ```js
|
|
170
|
-
*
|
|
165
|
+
* import { EventEmitter, once } from 'node:events';
|
|
171
166
|
*
|
|
172
167
|
* const ee = new EventEmitter();
|
|
173
168
|
* const ac = new AbortController();
|
|
@@ -195,25 +190,24 @@ declare module 'events' {
|
|
|
195
190
|
static once(emitter: _DOMEventTarget, eventName: string, options?: StaticEventEmitterOptions): Promise<any[]>;
|
|
196
191
|
/**
|
|
197
192
|
* ```js
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* (async () => {
|
|
201
|
-
* const ee = new EventEmitter();
|
|
193
|
+
* import { on, EventEmitter } from 'node:events';
|
|
194
|
+
* import process from 'node:process';
|
|
202
195
|
*
|
|
203
|
-
*
|
|
204
|
-
* process.nextTick(() => {
|
|
205
|
-
* ee.emit('foo', 'bar');
|
|
206
|
-
* ee.emit('foo', 42);
|
|
207
|
-
* });
|
|
196
|
+
* const ee = new EventEmitter();
|
|
208
197
|
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
198
|
+
* // Emit later on
|
|
199
|
+
* process.nextTick(() => {
|
|
200
|
+
* ee.emit('foo', 'bar');
|
|
201
|
+
* ee.emit('foo', 42);
|
|
202
|
+
* });
|
|
203
|
+
*
|
|
204
|
+
* for await (const event of on(ee, 'foo')) {
|
|
205
|
+
* // The execution of this inner block is synchronous and it
|
|
206
|
+
* // processes one event at a time (even with await). Do not use
|
|
207
|
+
* // if concurrent execution is required.
|
|
208
|
+
* console.log(event); // prints ['bar'] [42]
|
|
209
|
+
* }
|
|
210
|
+
* // Unreachable here
|
|
217
211
|
* ```
|
|
218
212
|
*
|
|
219
213
|
* Returns an `AsyncIterator` that iterates `eventName` events. It will throw
|
|
@@ -224,7 +218,9 @@ declare module 'events' {
|
|
|
224
218
|
* An `AbortSignal` can be used to cancel waiting on events:
|
|
225
219
|
*
|
|
226
220
|
* ```js
|
|
227
|
-
*
|
|
221
|
+
* import { on, EventEmitter } from 'node:events';
|
|
222
|
+
* import process from 'node:process';
|
|
223
|
+
*
|
|
228
224
|
* const ac = new AbortController();
|
|
229
225
|
*
|
|
230
226
|
* (async () => {
|
|
@@ -256,7 +252,8 @@ declare module 'events' {
|
|
|
256
252
|
* A class method that returns the number of listeners for the given `eventName`registered on the given `emitter`.
|
|
257
253
|
*
|
|
258
254
|
* ```js
|
|
259
|
-
*
|
|
255
|
+
* import { EventEmitter, listenerCount } from 'node:events';
|
|
256
|
+
*
|
|
260
257
|
* const myEmitter = new EventEmitter();
|
|
261
258
|
* myEmitter.on('event', () => {});
|
|
262
259
|
* myEmitter.on('event', () => {});
|
|
@@ -279,19 +276,19 @@ declare module 'events' {
|
|
|
279
276
|
* event target. This is useful for debugging and diagnostic purposes.
|
|
280
277
|
*
|
|
281
278
|
* ```js
|
|
282
|
-
*
|
|
279
|
+
* import { getEventListeners, EventEmitter } from 'node:events';
|
|
283
280
|
*
|
|
284
281
|
* {
|
|
285
282
|
* const ee = new EventEmitter();
|
|
286
283
|
* const listener = () => console.log('Events are fun');
|
|
287
284
|
* ee.on('foo', listener);
|
|
288
|
-
* getEventListeners(ee, 'foo'); // [listener]
|
|
285
|
+
* console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
|
|
289
286
|
* }
|
|
290
287
|
* {
|
|
291
288
|
* const et = new EventTarget();
|
|
292
289
|
* const listener = () => console.log('Events are fun');
|
|
293
290
|
* et.addEventListener('foo', listener);
|
|
294
|
-
* getEventListeners(et, 'foo'); // [listener]
|
|
291
|
+
* console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
|
|
295
292
|
* }
|
|
296
293
|
* ```
|
|
297
294
|
* @since v15.2.0, v14.17.0
|
|
@@ -299,10 +296,7 @@ declare module 'events' {
|
|
|
299
296
|
static getEventListeners(emitter: _DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
|
|
300
297
|
/**
|
|
301
298
|
* ```js
|
|
302
|
-
*
|
|
303
|
-
* setMaxListeners,
|
|
304
|
-
* EventEmitter
|
|
305
|
-
* } = require('events');
|
|
299
|
+
* import { setMaxListeners, EventEmitter } from 'node:events';
|
|
306
300
|
*
|
|
307
301
|
* const target = new EventTarget();
|
|
308
302
|
* const emitter = new EventEmitter();
|
|
@@ -370,6 +364,7 @@ declare module 'events' {
|
|
|
370
364
|
* event listener to the beginning of the listeners array.
|
|
371
365
|
*
|
|
372
366
|
* ```js
|
|
367
|
+
* import { EventEmitter } from 'node:events';
|
|
373
368
|
* const myEE = new EventEmitter();
|
|
374
369
|
* myEE.on('foo', () => console.log('a'));
|
|
375
370
|
* myEE.prependListener('foo', () => console.log('b'));
|
|
@@ -399,6 +394,7 @@ declare module 'events' {
|
|
|
399
394
|
* event listener to the beginning of the listeners array.
|
|
400
395
|
*
|
|
401
396
|
* ```js
|
|
397
|
+
* import { EventEmitter } from 'node:events';
|
|
402
398
|
* const myEE = new EventEmitter();
|
|
403
399
|
* myEE.once('foo', () => console.log('a'));
|
|
404
400
|
* myEE.prependOnceListener('foo', () => console.log('b'));
|
|
@@ -434,6 +430,8 @@ declare module 'events' {
|
|
|
434
430
|
* will not remove them from`emit()` in progress. Subsequent events behave as expected.
|
|
435
431
|
*
|
|
436
432
|
* ```js
|
|
433
|
+
* import { EventEmitter } from 'node:events';
|
|
434
|
+
* class MyEmitter extends EventEmitter {}
|
|
437
435
|
* const myEmitter = new MyEmitter();
|
|
438
436
|
*
|
|
439
437
|
* const callbackA = () => {
|
|
@@ -474,6 +472,7 @@ declare module 'events' {
|
|
|
474
472
|
* recently added instance. In the example the `once('ping')`listener is removed:
|
|
475
473
|
*
|
|
476
474
|
* ```js
|
|
475
|
+
* import { EventEmitter } from 'node:events';
|
|
477
476
|
* const ee = new EventEmitter();
|
|
478
477
|
*
|
|
479
478
|
* function pong() {
|
|
@@ -542,6 +541,7 @@ declare module 'events' {
|
|
|
542
541
|
* including any wrappers (such as those created by `.once()`).
|
|
543
542
|
*
|
|
544
543
|
* ```js
|
|
544
|
+
* import { EventEmitter } from 'node:events';
|
|
545
545
|
* const emitter = new EventEmitter();
|
|
546
546
|
* emitter.once('log', () => console.log('log once'));
|
|
547
547
|
*
|
|
@@ -574,7 +574,7 @@ declare module 'events' {
|
|
|
574
574
|
* Returns `true` if the event had listeners, `false` otherwise.
|
|
575
575
|
*
|
|
576
576
|
* ```js
|
|
577
|
-
*
|
|
577
|
+
* import { EventEmitter } from 'node:events';
|
|
578
578
|
* const myEmitter = new EventEmitter();
|
|
579
579
|
*
|
|
580
580
|
* // First listener
|
|
@@ -609,10 +609,9 @@ declare module 'events' {
|
|
|
609
609
|
*/
|
|
610
610
|
emit(eventName: string | symbol, ...args: any[]): boolean;
|
|
611
611
|
/**
|
|
612
|
-
* Returns the number of listeners listening
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
* is found in the list of the listeners of the event.
|
|
612
|
+
* Returns the number of listeners listening for the event named `eventName`.
|
|
613
|
+
* If `listener` is provided, it will return how many times the listener is found
|
|
614
|
+
* in the list of the listeners of the event.
|
|
616
615
|
* @since v3.2.0
|
|
617
616
|
* @param eventName The name of the event being listened for
|
|
618
617
|
* @param listener The event handler function
|
|
@@ -657,7 +656,8 @@ declare module 'events' {
|
|
|
657
656
|
* listeners. The values in the array are strings or `Symbol`s.
|
|
658
657
|
*
|
|
659
658
|
* ```js
|
|
660
|
-
*
|
|
659
|
+
* import { EventEmitter } from 'node:events';
|
|
660
|
+
*
|
|
661
661
|
* const myEE = new EventEmitter();
|
|
662
662
|
* myEE.on('foo', () => {});
|
|
663
663
|
* myEE.on('bar', () => {});
|
node/fs/promises.d.ts
CHANGED
|
@@ -41,7 +41,6 @@ declare module 'fs/promises' {
|
|
|
41
41
|
WriteVResult,
|
|
42
42
|
} from 'node:fs';
|
|
43
43
|
import { Interface as ReadlineInterface } from 'node:readline';
|
|
44
|
-
|
|
45
44
|
interface FileChangeInfo<T extends string | Buffer> {
|
|
46
45
|
eventType: WatchEventType;
|
|
47
46
|
filename: T;
|
|
@@ -115,8 +114,8 @@ declare module 'fs/promises' {
|
|
|
115
114
|
*/
|
|
116
115
|
chmod(mode: Mode): Promise<void>;
|
|
117
116
|
/**
|
|
118
|
-
* Unlike the 16
|
|
119
|
-
* returned by this method has a default `highWaterMark` of 64
|
|
117
|
+
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
|
|
118
|
+
* returned by this method has a default `highWaterMark` of 64 KiB.
|
|
120
119
|
*
|
|
121
120
|
* `options` can include `start` and `end` values to read a range of bytes from
|
|
122
121
|
* the file instead of the entire file. Both `start` and `end` are inclusive and
|
|
@@ -134,7 +133,7 @@ declare module 'fs/promises' {
|
|
|
134
133
|
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
|
135
134
|
*
|
|
136
135
|
* ```js
|
|
137
|
-
* import { open } from 'fs/promises';
|
|
136
|
+
* import { open } from 'node:fs/promises';
|
|
138
137
|
*
|
|
139
138
|
* const fd = await open('/dev/input/event0');
|
|
140
139
|
* // Create a stream from some character device.
|
|
@@ -160,7 +159,7 @@ declare module 'fs/promises' {
|
|
|
160
159
|
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
|
161
160
|
*
|
|
162
161
|
* ```js
|
|
163
|
-
* import { open } from 'fs/promises';
|
|
162
|
+
* import { open } from 'node:fs/promises';
|
|
164
163
|
*
|
|
165
164
|
* const fd = await open('sample.txt');
|
|
166
165
|
* fd.createReadStream({ start: 90, end: 99 });
|
|
@@ -199,7 +198,7 @@ declare module 'fs/promises' {
|
|
|
199
198
|
* device. The specific implementation is operating system and device specific.
|
|
200
199
|
* Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail.
|
|
201
200
|
* @since v10.0.0
|
|
202
|
-
* @return
|
|
201
|
+
* @return Fulfills with `undefined` upon success.
|
|
203
202
|
*/
|
|
204
203
|
sync(): Promise<void>;
|
|
205
204
|
/**
|
|
@@ -220,11 +219,13 @@ declare module 'fs/promises' {
|
|
|
220
219
|
/**
|
|
221
220
|
* Returns a `ReadableStream` that may be used to read the files data.
|
|
222
221
|
*
|
|
223
|
-
* An error will be thrown if this method is called more than once or is called
|
|
224
|
-
* or closing.
|
|
222
|
+
* An error will be thrown if this method is called more than once or is called
|
|
223
|
+
* after the `FileHandle` is closed or closing.
|
|
225
224
|
*
|
|
226
225
|
* ```js
|
|
227
|
-
* import {
|
|
226
|
+
* import {
|
|
227
|
+
* open,
|
|
228
|
+
* } from 'node:fs/promises';
|
|
228
229
|
*
|
|
229
230
|
* const file = await open('./some/file/to/read');
|
|
230
231
|
*
|
|
@@ -234,8 +235,8 @@ declare module 'fs/promises' {
|
|
|
234
235
|
* await file.close();
|
|
235
236
|
* ```
|
|
236
237
|
*
|
|
237
|
-
* While the `ReadableStream` will read the file to completion, it will not
|
|
238
|
-
*
|
|
238
|
+
* While the `ReadableStream` will read the file to completion, it will not
|
|
239
|
+
* close the `FileHandle` automatically. User code must still call the`fileHandle.close()` method.
|
|
239
240
|
* @since v17.0.0
|
|
240
241
|
* @experimental
|
|
241
242
|
*/
|
|
@@ -289,7 +290,8 @@ declare module 'fs/promises' {
|
|
|
289
290
|
| null
|
|
290
291
|
): Promise<string | Buffer>;
|
|
291
292
|
/**
|
|
292
|
-
* Convenience method to create a `readline` interface and stream over the file.
|
|
293
|
+
* Convenience method to create a `readline` interface and stream over the file.
|
|
294
|
+
* See `filehandle.createReadStream()` for the options.
|
|
293
295
|
*
|
|
294
296
|
* ```js
|
|
295
297
|
* import { open } from 'node:fs/promises';
|
|
@@ -300,9 +302,7 @@ declare module 'fs/promises' {
|
|
|
300
302
|
* console.log(line);
|
|
301
303
|
* }
|
|
302
304
|
* ```
|
|
303
|
-
*
|
|
304
305
|
* @since v18.11.0
|
|
305
|
-
* @param options See `filehandle.createReadStream()` for the options.
|
|
306
306
|
*/
|
|
307
307
|
readLines(options?: CreateReadStreamOptions): ReadlineInterface;
|
|
308
308
|
/**
|
|
@@ -329,7 +329,7 @@ declare module 'fs/promises' {
|
|
|
329
329
|
* The following example retains only the first four bytes of the file:
|
|
330
330
|
*
|
|
331
331
|
* ```js
|
|
332
|
-
* import { open } from 'fs/promises';
|
|
332
|
+
* import { open } from 'node:fs/promises';
|
|
333
333
|
*
|
|
334
334
|
* let filehandle = null;
|
|
335
335
|
* try {
|
|
@@ -356,7 +356,7 @@ declare module 'fs/promises' {
|
|
|
356
356
|
utimes(atime: TimeLike, mtime: TimeLike): Promise<void>;
|
|
357
357
|
/**
|
|
358
358
|
* Asynchronously writes data to a file, replacing the file if it already exists.`data` can be a string, a buffer, an
|
|
359
|
-
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface) or
|
|
359
|
+
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an
|
|
360
360
|
* [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
|
|
361
361
|
* The promise is resolved with no arguments upon success.
|
|
362
362
|
*
|
|
@@ -386,10 +386,10 @@ declare module 'fs/promises' {
|
|
|
386
386
|
* The kernel ignores the position argument and always appends the data to
|
|
387
387
|
* the end of the file.
|
|
388
388
|
* @since v10.0.0
|
|
389
|
-
* @param
|
|
389
|
+
* @param offset The start position from within `buffer` where the data to write begins.
|
|
390
390
|
* @param [length=buffer.byteLength - offset] The number of bytes from `buffer` to write.
|
|
391
|
-
* @param position The offset from the beginning of the file where the data from `buffer` should be written. If `position` is not a `number`, the data will be written at the current
|
|
392
|
-
* See the POSIX pwrite(2) documentation for more detail.
|
|
391
|
+
* @param [position='null'] The offset from the beginning of the file where the data from `buffer` should be written. If `position` is not a `number`, the data will be written at the current
|
|
392
|
+
* position. See the POSIX pwrite(2) documentation for more detail.
|
|
393
393
|
*/
|
|
394
394
|
write<TBuffer extends Uint8Array>(
|
|
395
395
|
buffer: TBuffer,
|
|
@@ -420,14 +420,14 @@ declare module 'fs/promises' {
|
|
|
420
420
|
* The kernel ignores the position argument and always appends the data to
|
|
421
421
|
* the end of the file.
|
|
422
422
|
* @since v12.9.0
|
|
423
|
-
* @param position The offset from the beginning of the file where the data from `buffers` should be written. If `position` is not a `number`, the data will be written at the current
|
|
423
|
+
* @param [position='null'] The offset from the beginning of the file where the data from `buffers` should be written. If `position` is not a `number`, the data will be written at the current
|
|
424
424
|
* position.
|
|
425
425
|
*/
|
|
426
426
|
writev(buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<WriteVResult>;
|
|
427
427
|
/**
|
|
428
428
|
* Read from a file and write to an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s
|
|
429
429
|
* @since v13.13.0, v12.17.0
|
|
430
|
-
* @param position The offset from the beginning of the file where the data should be read from. If `position` is not a `number`, the data will be read from the current position.
|
|
430
|
+
* @param [position='null'] The offset from the beginning of the file where the data should be read from. If `position` is not a `number`, the data will be read from the current position.
|
|
431
431
|
* @return Fulfills upon success an object containing two properties:
|
|
432
432
|
*/
|
|
433
433
|
readv(buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<ReadVResult>;
|
|
@@ -436,7 +436,7 @@ declare module 'fs/promises' {
|
|
|
436
436
|
* complete.
|
|
437
437
|
*
|
|
438
438
|
* ```js
|
|
439
|
-
* import { open } from 'fs/promises';
|
|
439
|
+
* import { open } from 'node:fs/promises';
|
|
440
440
|
*
|
|
441
441
|
* let filehandle;
|
|
442
442
|
* try {
|
|
@@ -450,9 +450,7 @@ declare module 'fs/promises' {
|
|
|
450
450
|
*/
|
|
451
451
|
close(): Promise<void>;
|
|
452
452
|
}
|
|
453
|
-
|
|
454
453
|
const constants: typeof fsConstants;
|
|
455
|
-
|
|
456
454
|
/**
|
|
457
455
|
* Tests a user's permissions for the file or directory specified by `path`.
|
|
458
456
|
* The `mode` argument is an optional integer that specifies the accessibility
|
|
@@ -466,8 +464,7 @@ declare module 'fs/promises' {
|
|
|
466
464
|
* written by the current process.
|
|
467
465
|
*
|
|
468
466
|
* ```js
|
|
469
|
-
* import { access } from 'fs/promises';
|
|
470
|
-
* import { constants } from 'fs';
|
|
467
|
+
* import { access, constants } from 'node:fs/promises';
|
|
471
468
|
*
|
|
472
469
|
* try {
|
|
473
470
|
* await access('/etc/passwd', constants.R_OK | constants.W_OK);
|
|
@@ -496,14 +493,13 @@ declare module 'fs/promises' {
|
|
|
496
493
|
* will be made to remove the destination.
|
|
497
494
|
*
|
|
498
495
|
* ```js
|
|
499
|
-
* import { constants } from 'fs';
|
|
500
|
-
* import { copyFile } from 'fs/promises';
|
|
496
|
+
* import { copyFile, constants } from 'node:fs/promises';
|
|
501
497
|
*
|
|
502
498
|
* try {
|
|
503
499
|
* await copyFile('source.txt', 'destination.txt');
|
|
504
500
|
* console.log('source.txt was copied to destination.txt');
|
|
505
501
|
* } catch {
|
|
506
|
-
* console.
|
|
502
|
+
* console.error('The file could not be copied');
|
|
507
503
|
* }
|
|
508
504
|
*
|
|
509
505
|
* // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
|
|
@@ -511,7 +507,7 @@ declare module 'fs/promises' {
|
|
|
511
507
|
* await copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
|
|
512
508
|
* console.log('source.txt was copied to destination.txt');
|
|
513
509
|
* } catch {
|
|
514
|
-
* console.
|
|
510
|
+
* console.error('The file could not be copied');
|
|
515
511
|
* }
|
|
516
512
|
* ```
|
|
517
513
|
* @since v10.0.0
|
|
@@ -573,6 +569,19 @@ declare module 'fs/promises' {
|
|
|
573
569
|
* and sticky bits), or an object with a `mode` property and a `recursive`property indicating whether parent directories should be created. Calling`fsPromises.mkdir()` when `path` is a directory
|
|
574
570
|
* that exists results in a
|
|
575
571
|
* rejection only when `recursive` is false.
|
|
572
|
+
*
|
|
573
|
+
* ```js
|
|
574
|
+
* import { mkdir } from 'node:fs/promises';
|
|
575
|
+
*
|
|
576
|
+
* try {
|
|
577
|
+
* const projectFolder = new URL('./test/project/', import.meta.url);
|
|
578
|
+
* const createDir = await mkdir(projectFolder, { recursive: true });
|
|
579
|
+
*
|
|
580
|
+
* console.log(`created ${createDir}`);
|
|
581
|
+
* } catch (err) {
|
|
582
|
+
* console.error(err.message);
|
|
583
|
+
* }
|
|
584
|
+
* ```
|
|
576
585
|
* @since v10.0.0
|
|
577
586
|
* @return Upon success, fulfills with `undefined` if `recursive` is `false`, or the first directory path created if `recursive` is `true`.
|
|
578
587
|
*/
|
|
@@ -615,7 +624,7 @@ declare module 'fs/promises' {
|
|
|
615
624
|
* If `options.withFileTypes` is set to `true`, the resolved array will contain `fs.Dirent` objects.
|
|
616
625
|
*
|
|
617
626
|
* ```js
|
|
618
|
-
* import { readdir } from 'fs/promises';
|
|
627
|
+
* import { readdir } from 'node:fs/promises';
|
|
619
628
|
*
|
|
620
629
|
* try {
|
|
621
630
|
* const files = await readdir(path);
|
|
@@ -703,11 +712,13 @@ declare module 'fs/promises' {
|
|
|
703
712
|
/**
|
|
704
713
|
* Creates a symbolic link.
|
|
705
714
|
*
|
|
706
|
-
* The `type` argument is only used on Windows platforms and can be one of `'dir'`,`'file'`, or `'junction'`.
|
|
707
|
-
*
|
|
715
|
+
* The `type` argument is only used on Windows platforms and can be one of `'dir'`,`'file'`, or `'junction'`. If the `type` argument is not a string, Node.js will
|
|
716
|
+
* autodetect `target` type and use `'file'` or `'dir'`. If the `target` does not
|
|
717
|
+
* exist, `'file'` will be used. Windows junction points require the destination
|
|
718
|
+
* path to be absolute. When using `'junction'`, the `target` argument will
|
|
708
719
|
* automatically be normalized to absolute path.
|
|
709
720
|
* @since v10.0.0
|
|
710
|
-
* @param [type='
|
|
721
|
+
* @param [type='null']
|
|
711
722
|
* @return Fulfills with `undefined` upon success.
|
|
712
723
|
*/
|
|
713
724
|
function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
|
|
@@ -749,8 +760,8 @@ declare module 'fs/promises' {
|
|
|
749
760
|
): Promise<BigIntStats>;
|
|
750
761
|
function stat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
|
|
751
762
|
/**
|
|
752
|
-
* @since v18.15.0
|
|
753
|
-
* @return Fulfills with
|
|
763
|
+
* @since v19.6.0, v18.15.0
|
|
764
|
+
* @return Fulfills with the {fs.StatFs} object for the given `path`.
|
|
754
765
|
*/
|
|
755
766
|
function statfs(
|
|
756
767
|
path: PathLike,
|
|
@@ -765,7 +776,6 @@ declare module 'fs/promises' {
|
|
|
765
776
|
}
|
|
766
777
|
): Promise<BigIntStatsFs>;
|
|
767
778
|
function statfs(path: PathLike, opts?: StatFsOptions): Promise<StatsFs | BigIntStatsFs>;
|
|
768
|
-
|
|
769
779
|
/**
|
|
770
780
|
* Creates a new link from the `existingPath` to the `newPath`. See the POSIX [`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail.
|
|
771
781
|
* @since v10.0.0
|
|
@@ -821,7 +831,7 @@ declare module 'fs/promises' {
|
|
|
821
831
|
*
|
|
822
832
|
* * Values can be either numbers representing Unix epoch time, `Date`s, or a
|
|
823
833
|
* numeric string like `'123456789.0'`.
|
|
824
|
-
* * If the value can not be converted to a number, or is `NaN`, `Infinity
|
|
834
|
+
* * If the value can not be converted to a number, or is `NaN`, `Infinity`, or`-Infinity`, an `Error` will be thrown.
|
|
825
835
|
* @since v10.0.0
|
|
826
836
|
* @return Fulfills with `undefined` upon success.
|
|
827
837
|
*/
|
|
@@ -866,10 +876,12 @@ declare module 'fs/promises' {
|
|
|
866
876
|
* object with an `encoding` property specifying the character encoding to use.
|
|
867
877
|
*
|
|
868
878
|
* ```js
|
|
869
|
-
* import { mkdtemp } from 'fs/promises';
|
|
879
|
+
* import { mkdtemp } from 'node:fs/promises';
|
|
880
|
+
* import { join } from 'node:path';
|
|
881
|
+
* import { tmpdir } from 'node:os';
|
|
870
882
|
*
|
|
871
883
|
* try {
|
|
872
|
-
* await mkdtemp(
|
|
884
|
+
* await mkdtemp(join(tmpdir(), 'foo-'));
|
|
873
885
|
* } catch (err) {
|
|
874
886
|
* console.error(err);
|
|
875
887
|
* }
|
|
@@ -878,9 +890,9 @@ declare module 'fs/promises' {
|
|
|
878
890
|
* The `fsPromises.mkdtemp()` method will append the six randomly selected
|
|
879
891
|
* characters directly to the `prefix` string. For instance, given a directory`/tmp`, if the intention is to create a temporary directory _within_`/tmp`, the`prefix` must end with a trailing
|
|
880
892
|
* platform-specific path separator
|
|
881
|
-
* (`require('path').sep`).
|
|
893
|
+
* (`require('node:path').sep`).
|
|
882
894
|
* @since v10.0.0
|
|
883
|
-
* @return Fulfills with a string containing the
|
|
895
|
+
* @return Fulfills with a string containing the file system path of the newly created temporary directory.
|
|
884
896
|
*/
|
|
885
897
|
function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
|
886
898
|
/**
|
|
@@ -897,7 +909,7 @@ declare module 'fs/promises' {
|
|
|
897
909
|
function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
|
|
898
910
|
/**
|
|
899
911
|
* Asynchronously writes data to a file, replacing the file if it already exists.`data` can be a string, a buffer, an
|
|
900
|
-
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface) or
|
|
912
|
+
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an
|
|
901
913
|
* [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
|
|
902
914
|
*
|
|
903
915
|
* The `encoding` option is ignored if `data` is a buffer.
|
|
@@ -920,8 +932,8 @@ declare module 'fs/promises' {
|
|
|
920
932
|
* to be written.
|
|
921
933
|
*
|
|
922
934
|
* ```js
|
|
923
|
-
* import { writeFile } from 'fs/promises';
|
|
924
|
-
* import { Buffer } from 'buffer';
|
|
935
|
+
* import { writeFile } from 'node:fs/promises';
|
|
936
|
+
* import { Buffer } from 'node:buffer';
|
|
925
937
|
*
|
|
926
938
|
* try {
|
|
927
939
|
* const controller = new AbortController();
|
|
@@ -984,11 +996,25 @@ declare module 'fs/promises' {
|
|
|
984
996
|
* with an error. On FreeBSD, a representation of the directory's contents will be
|
|
985
997
|
* returned.
|
|
986
998
|
*
|
|
999
|
+
* An example of reading a `package.json` file located in the same directory of the
|
|
1000
|
+
* running code:
|
|
1001
|
+
*
|
|
1002
|
+
* ```js
|
|
1003
|
+
* import { readFile } from 'node:fs/promises';
|
|
1004
|
+
* try {
|
|
1005
|
+
* const filePath = new URL('./package.json', import.meta.url);
|
|
1006
|
+
* const contents = await readFile(filePath, { encoding: 'utf8' });
|
|
1007
|
+
* console.log(contents);
|
|
1008
|
+
* } catch (err) {
|
|
1009
|
+
* console.error(err.message);
|
|
1010
|
+
* }
|
|
1011
|
+
* ```
|
|
1012
|
+
*
|
|
987
1013
|
* It is possible to abort an ongoing `readFile` using an `AbortSignal`. If a
|
|
988
1014
|
* request is aborted the promise returned is rejected with an `AbortError`:
|
|
989
1015
|
*
|
|
990
1016
|
* ```js
|
|
991
|
-
* import { readFile } from 'fs/promises';
|
|
1017
|
+
* import { readFile } from 'node:fs/promises';
|
|
992
1018
|
*
|
|
993
1019
|
* try {
|
|
994
1020
|
* const controller = new AbortController();
|
|
@@ -1067,7 +1093,7 @@ declare module 'fs/promises' {
|
|
|
1067
1093
|
* Example using async iteration:
|
|
1068
1094
|
*
|
|
1069
1095
|
* ```js
|
|
1070
|
-
* import { opendir } from 'fs/promises';
|
|
1096
|
+
* import { opendir } from 'node:fs/promises';
|
|
1071
1097
|
*
|
|
1072
1098
|
* try {
|
|
1073
1099
|
* const dir = await opendir('./');
|
|
@@ -1088,7 +1114,7 @@ declare module 'fs/promises' {
|
|
|
1088
1114
|
* Returns an async iterator that watches for changes on `filename`, where `filename`is either a file or a directory.
|
|
1089
1115
|
*
|
|
1090
1116
|
* ```js
|
|
1091
|
-
* const { watch } = require('fs/promises');
|
|
1117
|
+
* const { watch } = require('node:fs/promises');
|
|
1092
1118
|
*
|
|
1093
1119
|
* const ac = new AbortController();
|
|
1094
1120
|
* const { signal } = ac;
|