@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/ts4.8/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/ts4.8/fs/promises.d.ts
CHANGED
|
@@ -38,7 +38,6 @@ declare module 'fs/promises' {
|
|
|
38
38
|
WriteVResult,
|
|
39
39
|
} from 'node:fs';
|
|
40
40
|
import { Interface as ReadlineInterface } from 'node:readline';
|
|
41
|
-
|
|
42
41
|
interface FileChangeInfo<T extends string | Buffer> {
|
|
43
42
|
eventType: WatchEventType;
|
|
44
43
|
filename: T;
|
|
@@ -112,8 +111,8 @@ declare module 'fs/promises' {
|
|
|
112
111
|
*/
|
|
113
112
|
chmod(mode: Mode): Promise<void>;
|
|
114
113
|
/**
|
|
115
|
-
* Unlike the 16
|
|
116
|
-
* returned by this method has a default `highWaterMark` of 64
|
|
114
|
+
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
|
|
115
|
+
* returned by this method has a default `highWaterMark` of 64 KiB.
|
|
117
116
|
*
|
|
118
117
|
* `options` can include `start` and `end` values to read a range of bytes from
|
|
119
118
|
* the file instead of the entire file. Both `start` and `end` are inclusive and
|
|
@@ -131,7 +130,7 @@ declare module 'fs/promises' {
|
|
|
131
130
|
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
|
132
131
|
*
|
|
133
132
|
* ```js
|
|
134
|
-
* import { open } from 'fs/promises';
|
|
133
|
+
* import { open } from 'node:fs/promises';
|
|
135
134
|
*
|
|
136
135
|
* const fd = await open('/dev/input/event0');
|
|
137
136
|
* // Create a stream from some character device.
|
|
@@ -157,7 +156,7 @@ declare module 'fs/promises' {
|
|
|
157
156
|
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
|
158
157
|
*
|
|
159
158
|
* ```js
|
|
160
|
-
* import { open } from 'fs/promises';
|
|
159
|
+
* import { open } from 'node:fs/promises';
|
|
161
160
|
*
|
|
162
161
|
* const fd = await open('sample.txt');
|
|
163
162
|
* fd.createReadStream({ start: 90, end: 99 });
|
|
@@ -196,7 +195,7 @@ declare module 'fs/promises' {
|
|
|
196
195
|
* device. The specific implementation is operating system and device specific.
|
|
197
196
|
* Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail.
|
|
198
197
|
* @since v10.0.0
|
|
199
|
-
* @return
|
|
198
|
+
* @return Fulfills with `undefined` upon success.
|
|
200
199
|
*/
|
|
201
200
|
sync(): Promise<void>;
|
|
202
201
|
/**
|
|
@@ -217,11 +216,13 @@ declare module 'fs/promises' {
|
|
|
217
216
|
/**
|
|
218
217
|
* Returns a `ReadableStream` that may be used to read the files data.
|
|
219
218
|
*
|
|
220
|
-
* An error will be thrown if this method is called more than once or is called
|
|
221
|
-
* or closing.
|
|
219
|
+
* An error will be thrown if this method is called more than once or is called
|
|
220
|
+
* after the `FileHandle` is closed or closing.
|
|
222
221
|
*
|
|
223
222
|
* ```js
|
|
224
|
-
* import {
|
|
223
|
+
* import {
|
|
224
|
+
* open,
|
|
225
|
+
* } from 'node:fs/promises';
|
|
225
226
|
*
|
|
226
227
|
* const file = await open('./some/file/to/read');
|
|
227
228
|
*
|
|
@@ -231,8 +232,8 @@ declare module 'fs/promises' {
|
|
|
231
232
|
* await file.close();
|
|
232
233
|
* ```
|
|
233
234
|
*
|
|
234
|
-
* While the `ReadableStream` will read the file to completion, it will not
|
|
235
|
-
*
|
|
235
|
+
* While the `ReadableStream` will read the file to completion, it will not
|
|
236
|
+
* close the `FileHandle` automatically. User code must still call the`fileHandle.close()` method.
|
|
236
237
|
* @since v17.0.0
|
|
237
238
|
* @experimental
|
|
238
239
|
*/
|
|
@@ -286,7 +287,8 @@ declare module 'fs/promises' {
|
|
|
286
287
|
| null
|
|
287
288
|
): Promise<string | Buffer>;
|
|
288
289
|
/**
|
|
289
|
-
* Convenience method to create a `readline` interface and stream over the file.
|
|
290
|
+
* Convenience method to create a `readline` interface and stream over the file.
|
|
291
|
+
* See `filehandle.createReadStream()` for the options.
|
|
290
292
|
*
|
|
291
293
|
* ```js
|
|
292
294
|
* import { open } from 'node:fs/promises';
|
|
@@ -297,9 +299,7 @@ declare module 'fs/promises' {
|
|
|
297
299
|
* console.log(line);
|
|
298
300
|
* }
|
|
299
301
|
* ```
|
|
300
|
-
*
|
|
301
302
|
* @since v18.11.0
|
|
302
|
-
* @param options See `filehandle.createReadStream()` for the options.
|
|
303
303
|
*/
|
|
304
304
|
readLines(options?: CreateReadStreamOptions): ReadlineInterface;
|
|
305
305
|
/**
|
|
@@ -326,7 +326,7 @@ declare module 'fs/promises' {
|
|
|
326
326
|
* The following example retains only the first four bytes of the file:
|
|
327
327
|
*
|
|
328
328
|
* ```js
|
|
329
|
-
* import { open } from 'fs/promises';
|
|
329
|
+
* import { open } from 'node:fs/promises';
|
|
330
330
|
*
|
|
331
331
|
* let filehandle = null;
|
|
332
332
|
* try {
|
|
@@ -353,7 +353,7 @@ declare module 'fs/promises' {
|
|
|
353
353
|
utimes(atime: TimeLike, mtime: TimeLike): Promise<void>;
|
|
354
354
|
/**
|
|
355
355
|
* Asynchronously writes data to a file, replacing the file if it already exists.`data` can be a string, a buffer, an
|
|
356
|
-
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface) or
|
|
356
|
+
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an
|
|
357
357
|
* [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
|
|
358
358
|
* The promise is resolved with no arguments upon success.
|
|
359
359
|
*
|
|
@@ -383,10 +383,10 @@ declare module 'fs/promises' {
|
|
|
383
383
|
* The kernel ignores the position argument and always appends the data to
|
|
384
384
|
* the end of the file.
|
|
385
385
|
* @since v10.0.0
|
|
386
|
-
* @param
|
|
386
|
+
* @param offset The start position from within `buffer` where the data to write begins.
|
|
387
387
|
* @param [length=buffer.byteLength - offset] The number of bytes from `buffer` to write.
|
|
388
|
-
* @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
|
|
389
|
-
* See the POSIX pwrite(2) documentation for more detail.
|
|
388
|
+
* @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
|
|
389
|
+
* position. See the POSIX pwrite(2) documentation for more detail.
|
|
390
390
|
*/
|
|
391
391
|
write<TBuffer extends Uint8Array>(
|
|
392
392
|
buffer: TBuffer,
|
|
@@ -417,14 +417,14 @@ declare module 'fs/promises' {
|
|
|
417
417
|
* The kernel ignores the position argument and always appends the data to
|
|
418
418
|
* the end of the file.
|
|
419
419
|
* @since v12.9.0
|
|
420
|
-
* @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
|
|
420
|
+
* @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
|
|
421
421
|
* position.
|
|
422
422
|
*/
|
|
423
423
|
writev(buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<WriteVResult>;
|
|
424
424
|
/**
|
|
425
425
|
* Read from a file and write to an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s
|
|
426
426
|
* @since v13.13.0, v12.17.0
|
|
427
|
-
* @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.
|
|
427
|
+
* @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.
|
|
428
428
|
* @return Fulfills upon success an object containing two properties:
|
|
429
429
|
*/
|
|
430
430
|
readv(buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<ReadVResult>;
|
|
@@ -433,7 +433,7 @@ declare module 'fs/promises' {
|
|
|
433
433
|
* complete.
|
|
434
434
|
*
|
|
435
435
|
* ```js
|
|
436
|
-
* import { open } from 'fs/promises';
|
|
436
|
+
* import { open } from 'node:fs/promises';
|
|
437
437
|
*
|
|
438
438
|
* let filehandle;
|
|
439
439
|
* try {
|
|
@@ -447,9 +447,7 @@ declare module 'fs/promises' {
|
|
|
447
447
|
*/
|
|
448
448
|
close(): Promise<void>;
|
|
449
449
|
}
|
|
450
|
-
|
|
451
450
|
const constants: typeof fsConstants;
|
|
452
|
-
|
|
453
451
|
/**
|
|
454
452
|
* Tests a user's permissions for the file or directory specified by `path`.
|
|
455
453
|
* The `mode` argument is an optional integer that specifies the accessibility
|
|
@@ -463,8 +461,7 @@ declare module 'fs/promises' {
|
|
|
463
461
|
* written by the current process.
|
|
464
462
|
*
|
|
465
463
|
* ```js
|
|
466
|
-
* import { access } from 'fs/promises';
|
|
467
|
-
* import { constants } from 'fs';
|
|
464
|
+
* import { access, constants } from 'node:fs/promises';
|
|
468
465
|
*
|
|
469
466
|
* try {
|
|
470
467
|
* await access('/etc/passwd', constants.R_OK | constants.W_OK);
|
|
@@ -493,14 +490,13 @@ declare module 'fs/promises' {
|
|
|
493
490
|
* will be made to remove the destination.
|
|
494
491
|
*
|
|
495
492
|
* ```js
|
|
496
|
-
* import { constants } from 'fs';
|
|
497
|
-
* import { copyFile } from 'fs/promises';
|
|
493
|
+
* import { copyFile, constants } from 'node:fs/promises';
|
|
498
494
|
*
|
|
499
495
|
* try {
|
|
500
496
|
* await copyFile('source.txt', 'destination.txt');
|
|
501
497
|
* console.log('source.txt was copied to destination.txt');
|
|
502
498
|
* } catch {
|
|
503
|
-
* console.
|
|
499
|
+
* console.error('The file could not be copied');
|
|
504
500
|
* }
|
|
505
501
|
*
|
|
506
502
|
* // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
|
|
@@ -508,7 +504,7 @@ declare module 'fs/promises' {
|
|
|
508
504
|
* await copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
|
|
509
505
|
* console.log('source.txt was copied to destination.txt');
|
|
510
506
|
* } catch {
|
|
511
|
-
* console.
|
|
507
|
+
* console.error('The file could not be copied');
|
|
512
508
|
* }
|
|
513
509
|
* ```
|
|
514
510
|
* @since v10.0.0
|
|
@@ -570,6 +566,19 @@ declare module 'fs/promises' {
|
|
|
570
566
|
* 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
|
|
571
567
|
* that exists results in a
|
|
572
568
|
* rejection only when `recursive` is false.
|
|
569
|
+
*
|
|
570
|
+
* ```js
|
|
571
|
+
* import { mkdir } from 'node:fs/promises';
|
|
572
|
+
*
|
|
573
|
+
* try {
|
|
574
|
+
* const projectFolder = new URL('./test/project/', import.meta.url);
|
|
575
|
+
* const createDir = await mkdir(projectFolder, { recursive: true });
|
|
576
|
+
*
|
|
577
|
+
* console.log(`created ${createDir}`);
|
|
578
|
+
* } catch (err) {
|
|
579
|
+
* console.error(err.message);
|
|
580
|
+
* }
|
|
581
|
+
* ```
|
|
573
582
|
* @since v10.0.0
|
|
574
583
|
* @return Upon success, fulfills with `undefined` if `recursive` is `false`, or the first directory path created if `recursive` is `true`.
|
|
575
584
|
*/
|
|
@@ -612,7 +621,7 @@ declare module 'fs/promises' {
|
|
|
612
621
|
* If `options.withFileTypes` is set to `true`, the resolved array will contain `fs.Dirent` objects.
|
|
613
622
|
*
|
|
614
623
|
* ```js
|
|
615
|
-
* import { readdir } from 'fs/promises';
|
|
624
|
+
* import { readdir } from 'node:fs/promises';
|
|
616
625
|
*
|
|
617
626
|
* try {
|
|
618
627
|
* const files = await readdir(path);
|
|
@@ -700,11 +709,13 @@ declare module 'fs/promises' {
|
|
|
700
709
|
/**
|
|
701
710
|
* Creates a symbolic link.
|
|
702
711
|
*
|
|
703
|
-
* The `type` argument is only used on Windows platforms and can be one of `'dir'`,`'file'`, or `'junction'`.
|
|
704
|
-
*
|
|
712
|
+
* 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
|
|
713
|
+
* autodetect `target` type and use `'file'` or `'dir'`. If the `target` does not
|
|
714
|
+
* exist, `'file'` will be used. Windows junction points require the destination
|
|
715
|
+
* path to be absolute. When using `'junction'`, the `target` argument will
|
|
705
716
|
* automatically be normalized to absolute path.
|
|
706
717
|
* @since v10.0.0
|
|
707
|
-
* @param [type='
|
|
718
|
+
* @param [type='null']
|
|
708
719
|
* @return Fulfills with `undefined` upon success.
|
|
709
720
|
*/
|
|
710
721
|
function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
|
|
@@ -800,7 +811,7 @@ declare module 'fs/promises' {
|
|
|
800
811
|
*
|
|
801
812
|
* * Values can be either numbers representing Unix epoch time, `Date`s, or a
|
|
802
813
|
* numeric string like `'123456789.0'`.
|
|
803
|
-
* * If the value can not be converted to a number, or is `NaN`, `Infinity
|
|
814
|
+
* * If the value can not be converted to a number, or is `NaN`, `Infinity`, or`-Infinity`, an `Error` will be thrown.
|
|
804
815
|
* @since v10.0.0
|
|
805
816
|
* @return Fulfills with `undefined` upon success.
|
|
806
817
|
*/
|
|
@@ -845,10 +856,12 @@ declare module 'fs/promises' {
|
|
|
845
856
|
* object with an `encoding` property specifying the character encoding to use.
|
|
846
857
|
*
|
|
847
858
|
* ```js
|
|
848
|
-
* import { mkdtemp } from 'fs/promises';
|
|
859
|
+
* import { mkdtemp } from 'node:fs/promises';
|
|
860
|
+
* import { join } from 'node:path';
|
|
861
|
+
* import { tmpdir } from 'node:os';
|
|
849
862
|
*
|
|
850
863
|
* try {
|
|
851
|
-
* await mkdtemp(
|
|
864
|
+
* await mkdtemp(join(tmpdir(), 'foo-'));
|
|
852
865
|
* } catch (err) {
|
|
853
866
|
* console.error(err);
|
|
854
867
|
* }
|
|
@@ -857,9 +870,9 @@ declare module 'fs/promises' {
|
|
|
857
870
|
* The `fsPromises.mkdtemp()` method will append the six randomly selected
|
|
858
871
|
* 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
|
|
859
872
|
* platform-specific path separator
|
|
860
|
-
* (`require('path').sep`).
|
|
873
|
+
* (`require('node:path').sep`).
|
|
861
874
|
* @since v10.0.0
|
|
862
|
-
* @return Fulfills with a string containing the
|
|
875
|
+
* @return Fulfills with a string containing the file system path of the newly created temporary directory.
|
|
863
876
|
*/
|
|
864
877
|
function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
|
865
878
|
/**
|
|
@@ -876,7 +889,7 @@ declare module 'fs/promises' {
|
|
|
876
889
|
function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
|
|
877
890
|
/**
|
|
878
891
|
* Asynchronously writes data to a file, replacing the file if it already exists.`data` can be a string, a buffer, an
|
|
879
|
-
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface) or
|
|
892
|
+
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an
|
|
880
893
|
* [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
|
|
881
894
|
*
|
|
882
895
|
* The `encoding` option is ignored if `data` is a buffer.
|
|
@@ -899,8 +912,8 @@ declare module 'fs/promises' {
|
|
|
899
912
|
* to be written.
|
|
900
913
|
*
|
|
901
914
|
* ```js
|
|
902
|
-
* import { writeFile } from 'fs/promises';
|
|
903
|
-
* import { Buffer } from 'buffer';
|
|
915
|
+
* import { writeFile } from 'node:fs/promises';
|
|
916
|
+
* import { Buffer } from 'node:buffer';
|
|
904
917
|
*
|
|
905
918
|
* try {
|
|
906
919
|
* const controller = new AbortController();
|
|
@@ -963,11 +976,25 @@ declare module 'fs/promises' {
|
|
|
963
976
|
* with an error. On FreeBSD, a representation of the directory's contents will be
|
|
964
977
|
* returned.
|
|
965
978
|
*
|
|
979
|
+
* An example of reading a `package.json` file located in the same directory of the
|
|
980
|
+
* running code:
|
|
981
|
+
*
|
|
982
|
+
* ```js
|
|
983
|
+
* import { readFile } from 'node:fs/promises';
|
|
984
|
+
* try {
|
|
985
|
+
* const filePath = new URL('./package.json', import.meta.url);
|
|
986
|
+
* const contents = await readFile(filePath, { encoding: 'utf8' });
|
|
987
|
+
* console.log(contents);
|
|
988
|
+
* } catch (err) {
|
|
989
|
+
* console.error(err.message);
|
|
990
|
+
* }
|
|
991
|
+
* ```
|
|
992
|
+
*
|
|
966
993
|
* It is possible to abort an ongoing `readFile` using an `AbortSignal`. If a
|
|
967
994
|
* request is aborted the promise returned is rejected with an `AbortError`:
|
|
968
995
|
*
|
|
969
996
|
* ```js
|
|
970
|
-
* import { readFile } from 'fs/promises';
|
|
997
|
+
* import { readFile } from 'node:fs/promises';
|
|
971
998
|
*
|
|
972
999
|
* try {
|
|
973
1000
|
* const controller = new AbortController();
|
|
@@ -1046,7 +1073,7 @@ declare module 'fs/promises' {
|
|
|
1046
1073
|
* Example using async iteration:
|
|
1047
1074
|
*
|
|
1048
1075
|
* ```js
|
|
1049
|
-
* import { opendir } from 'fs/promises';
|
|
1076
|
+
* import { opendir } from 'node:fs/promises';
|
|
1050
1077
|
*
|
|
1051
1078
|
* try {
|
|
1052
1079
|
* const dir = await opendir('./');
|
|
@@ -1067,7 +1094,7 @@ declare module 'fs/promises' {
|
|
|
1067
1094
|
* Returns an async iterator that watches for changes on `filename`, where `filename`is either a file or a directory.
|
|
1068
1095
|
*
|
|
1069
1096
|
* ```js
|
|
1070
|
-
* const { watch } = require('fs/promises');
|
|
1097
|
+
* const { watch } = require('node:fs/promises');
|
|
1071
1098
|
*
|
|
1072
1099
|
* const ac = new AbortController();
|
|
1073
1100
|
* const { signal } = ac;
|