@types/node 18.16.3 → 20.1.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 +71 -75
- node/async_hooks.d.ts +62 -42
- node/buffer.d.ts +127 -99
- 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 +24 -16
- node/domain.d.ts +4 -4
- node/events.d.ts +60 -60
- node/fs/promises.d.ts +78 -48
- node/fs.d.ts +117 -81
- node/http.d.ts +158 -147
- 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 +88 -136
- node/string_decoder.d.ts +6 -6
- node/test.d.ts +423 -186
- node/timers/promises.d.ts +3 -3
- node/timers.d.ts +2 -2
- node/tls.d.ts +24 -16
- node/trace_events.d.ts +20 -9
- node/ts4.8/assert.d.ts +71 -75
- node/ts4.8/async_hooks.d.ts +62 -42
- node/ts4.8/buffer.d.ts +127 -99
- 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 +24 -16
- node/ts4.8/domain.d.ts +4 -4
- node/ts4.8/events.d.ts +60 -60
- node/ts4.8/fs/promises.d.ts +96 -45
- node/ts4.8/fs.d.ts +203 -67
- node/ts4.8/globals.d.ts +29 -28
- node/ts4.8/http.d.ts +198 -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 +24 -21
- 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 +91 -139
- node/ts4.8/string_decoder.d.ts +6 -6
- node/ts4.8/test.d.ts +423 -186
- node/ts4.8/timers/promises.d.ts +3 -3
- node/ts4.8/timers.d.ts +9 -2
- node/ts4.8/tls.d.ts +24 -16
- 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 +110 -16
- node/ts4.8/vm.d.ts +292 -42
- node/ts4.8/wasi.d.ts +13 -19
- 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 +13 -19
- node/worker_threads.d.ts +32 -34
- node/zlib.d.ts +11 -11
node/util.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `util` module supports the needs of Node.js internal APIs. Many of the
|
|
2
|
+
* The `node:util` module supports the needs of Node.js internal APIs. Many of the
|
|
3
3
|
* utilities are useful for application and module developers as well. To access
|
|
4
4
|
* it:
|
|
5
5
|
*
|
|
6
6
|
* ```js
|
|
7
|
-
* const util = require('util');
|
|
7
|
+
* const util = require('node:util');
|
|
8
8
|
* ```
|
|
9
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
9
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.1.0/lib/util.js)
|
|
10
10
|
*/
|
|
11
11
|
declare module 'util' {
|
|
12
12
|
import * as types from 'node:util/types';
|
|
@@ -189,7 +189,7 @@ declare module 'util' {
|
|
|
189
189
|
* timestamp.
|
|
190
190
|
*
|
|
191
191
|
* ```js
|
|
192
|
-
* const util = require('util');
|
|
192
|
+
* const util = require('node:util');
|
|
193
193
|
*
|
|
194
194
|
* util.log('Timestamped message.');
|
|
195
195
|
* ```
|
|
@@ -208,12 +208,12 @@ declare module 'util' {
|
|
|
208
208
|
* Creates and returns an `AbortController` instance whose `AbortSignal` is marked
|
|
209
209
|
* as transferable and can be used with `structuredClone()` or `postMessage()`.
|
|
210
210
|
* @since v18.11.0
|
|
211
|
+
* @experimental
|
|
211
212
|
* @returns A transferable AbortController
|
|
212
213
|
*/
|
|
213
214
|
export function transferableAbortController(): AbortController;
|
|
214
215
|
/**
|
|
215
|
-
* Marks the given
|
|
216
|
-
* `structuredClone()` and `postMessage()`.
|
|
216
|
+
* Marks the given `AbortSignal` as transferable so that it can be used with`structuredClone()` and `postMessage()`.
|
|
217
217
|
*
|
|
218
218
|
* ```js
|
|
219
219
|
* const signal = transferableAbortSignal(AbortSignal.timeout(100));
|
|
@@ -221,14 +221,33 @@ declare module 'util' {
|
|
|
221
221
|
* channel.port2.postMessage(signal, [signal]);
|
|
222
222
|
* ```
|
|
223
223
|
* @since v18.11.0
|
|
224
|
+
* @experimental
|
|
224
225
|
* @param signal The AbortSignal
|
|
225
226
|
* @returns The same AbortSignal
|
|
226
227
|
*/
|
|
227
228
|
export function transferableAbortSignal(signal: AbortSignal): AbortSignal;
|
|
228
229
|
/**
|
|
229
|
-
* Listens to abort event on the provided `signal` and
|
|
230
|
-
*
|
|
231
|
-
*
|
|
230
|
+
* Listens to abort event on the provided `signal` and
|
|
231
|
+
* returns a promise that is fulfilled when the `signal` is
|
|
232
|
+
* aborted. If the passed `resource` is garbage collected before the `signal` is
|
|
233
|
+
* aborted, the returned promise shall remain pending indefinitely.
|
|
234
|
+
*
|
|
235
|
+
* ```js
|
|
236
|
+
* import { aborted } from 'node:util';
|
|
237
|
+
*
|
|
238
|
+
* const dependent = obtainSomethingAbortable();
|
|
239
|
+
*
|
|
240
|
+
* aborted(dependent.signal, dependent).then(() => {
|
|
241
|
+
* // Do something when dependent is aborted.
|
|
242
|
+
* });
|
|
243
|
+
*
|
|
244
|
+
* dependent.on('event', () => {
|
|
245
|
+
* dependent.abort();
|
|
246
|
+
* });
|
|
247
|
+
* ```
|
|
248
|
+
* @since v19.7.0
|
|
249
|
+
* @experimental
|
|
250
|
+
* @param resource Any non-null entity, reference to which is held weakly.
|
|
232
251
|
*/
|
|
233
252
|
export function aborted(signal: AbortSignal, resource: any): Promise<void>;
|
|
234
253
|
/**
|
|
@@ -257,7 +276,7 @@ declare module 'util' {
|
|
|
257
276
|
* Circular references point to their anchor by using a reference index:
|
|
258
277
|
*
|
|
259
278
|
* ```js
|
|
260
|
-
* const { inspect } = require('util');
|
|
279
|
+
* const { inspect } = require('node:util');
|
|
261
280
|
*
|
|
262
281
|
* const obj = {};
|
|
263
282
|
* obj.a = [obj];
|
|
@@ -275,7 +294,7 @@ declare module 'util' {
|
|
|
275
294
|
* The following example inspects all properties of the `util` object:
|
|
276
295
|
*
|
|
277
296
|
* ```js
|
|
278
|
-
* const util = require('util');
|
|
297
|
+
* const util = require('node:util');
|
|
279
298
|
*
|
|
280
299
|
* console.log(util.inspect(util, { showHidden: true, depth: null }));
|
|
281
300
|
* ```
|
|
@@ -283,7 +302,7 @@ declare module 'util' {
|
|
|
283
302
|
* The following example highlights the effect of the `compact` option:
|
|
284
303
|
*
|
|
285
304
|
* ```js
|
|
286
|
-
* const util = require('util');
|
|
305
|
+
* const util = require('node:util');
|
|
287
306
|
*
|
|
288
307
|
* const o = {
|
|
289
308
|
* a: [1, 2, [[
|
|
@@ -291,7 +310,7 @@ declare module 'util' {
|
|
|
291
310
|
* 'eiusmod \ntempor incididunt ut labore et dolore magna aliqua.',
|
|
292
311
|
* 'test',
|
|
293
312
|
* 'foo']], 4],
|
|
294
|
-
* b: new Map([['za', 1], ['zb', 'test']])
|
|
313
|
+
* b: new Map([['za', 1], ['zb', 'test']]),
|
|
295
314
|
* };
|
|
296
315
|
* console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));
|
|
297
316
|
*
|
|
@@ -340,7 +359,7 @@ declare module 'util' {
|
|
|
340
359
|
* with no remaining strong references may be garbage collected at any time.
|
|
341
360
|
*
|
|
342
361
|
* ```js
|
|
343
|
-
* const { inspect } = require('util');
|
|
362
|
+
* const { inspect } = require('node:util');
|
|
344
363
|
*
|
|
345
364
|
* const obj = { a: 1 };
|
|
346
365
|
* const obj2 = { b: 2 };
|
|
@@ -354,13 +373,13 @@ declare module 'util' {
|
|
|
354
373
|
* impact the result of `util.inspect()`.
|
|
355
374
|
*
|
|
356
375
|
* ```js
|
|
357
|
-
* const { inspect } = require('util');
|
|
358
|
-
* const assert = require('assert');
|
|
376
|
+
* const { inspect } = require('node:util');
|
|
377
|
+
* const assert = require('node:assert');
|
|
359
378
|
*
|
|
360
379
|
* const o1 = {
|
|
361
380
|
* b: [2, 3, 1],
|
|
362
381
|
* a: '`a` comes before `b`',
|
|
363
|
-
* c: new Set([2, 3, 1])
|
|
382
|
+
* c: new Set([2, 3, 1]),
|
|
364
383
|
* };
|
|
365
384
|
* console.log(inspect(o1, { sorted: true }));
|
|
366
385
|
* // { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set(3) { 1, 2, 3 } }
|
|
@@ -370,11 +389,11 @@ declare module 'util' {
|
|
|
370
389
|
* const o2 = {
|
|
371
390
|
* c: new Set([2, 1, 3]),
|
|
372
391
|
* a: '`a` comes before `b`',
|
|
373
|
-
* b: [2, 3, 1]
|
|
392
|
+
* b: [2, 3, 1],
|
|
374
393
|
* };
|
|
375
394
|
* assert.strict.equal(
|
|
376
395
|
* inspect(o1, { sorted: true }),
|
|
377
|
-
* inspect(o2, { sorted: true })
|
|
396
|
+
* inspect(o2, { sorted: true }),
|
|
378
397
|
* );
|
|
379
398
|
* ```
|
|
380
399
|
*
|
|
@@ -382,7 +401,7 @@ declare module 'util' {
|
|
|
382
401
|
* numbers.
|
|
383
402
|
*
|
|
384
403
|
* ```js
|
|
385
|
-
* const { inspect } = require('util');
|
|
404
|
+
* const { inspect } = require('node:util');
|
|
386
405
|
*
|
|
387
406
|
* const thousand = 1_000;
|
|
388
407
|
* const million = 1_000_000;
|
|
@@ -394,7 +413,7 @@ declare module 'util' {
|
|
|
394
413
|
* ```
|
|
395
414
|
*
|
|
396
415
|
* `util.inspect()` is a synchronous method intended for debugging. Its maximum
|
|
397
|
-
* output length is approximately 128
|
|
416
|
+
* output length is approximately 128 MiB. Inputs that result in longer output will
|
|
398
417
|
* be truncated.
|
|
399
418
|
* @since v0.3.0
|
|
400
419
|
* @param object Any JavaScript primitive or `Object`.
|
|
@@ -423,7 +442,7 @@ declare module 'util' {
|
|
|
423
442
|
* Returns `true` if the given `object` is an `Array`. Otherwise, returns `false`.
|
|
424
443
|
*
|
|
425
444
|
* ```js
|
|
426
|
-
* const util = require('util');
|
|
445
|
+
* const util = require('node:util');
|
|
427
446
|
*
|
|
428
447
|
* util.isArray([]);
|
|
429
448
|
* // Returns: true
|
|
@@ -440,7 +459,7 @@ declare module 'util' {
|
|
|
440
459
|
* Returns `true` if the given `object` is a `RegExp`. Otherwise, returns `false`.
|
|
441
460
|
*
|
|
442
461
|
* ```js
|
|
443
|
-
* const util = require('util');
|
|
462
|
+
* const util = require('node:util');
|
|
444
463
|
*
|
|
445
464
|
* util.isRegExp(/some regexp/);
|
|
446
465
|
* // Returns: true
|
|
@@ -457,7 +476,7 @@ declare module 'util' {
|
|
|
457
476
|
* Returns `true` if the given `object` is a `Date`. Otherwise, returns `false`.
|
|
458
477
|
*
|
|
459
478
|
* ```js
|
|
460
|
-
* const util = require('util');
|
|
479
|
+
* const util = require('node:util');
|
|
461
480
|
*
|
|
462
481
|
* util.isDate(new Date());
|
|
463
482
|
* // Returns: true
|
|
@@ -474,7 +493,7 @@ declare module 'util' {
|
|
|
474
493
|
* Returns `true` if the given `object` is an `Error`. Otherwise, returns`false`.
|
|
475
494
|
*
|
|
476
495
|
* ```js
|
|
477
|
-
* const util = require('util');
|
|
496
|
+
* const util = require('node:util');
|
|
478
497
|
*
|
|
479
498
|
* util.isError(new Error());
|
|
480
499
|
* // Returns: true
|
|
@@ -488,7 +507,7 @@ declare module 'util' {
|
|
|
488
507
|
* possible to obtain an incorrect result when the `object` argument manipulates`@@toStringTag`.
|
|
489
508
|
*
|
|
490
509
|
* ```js
|
|
491
|
-
* const util = require('util');
|
|
510
|
+
* const util = require('node:util');
|
|
492
511
|
* const obj = { name: 'Error', message: 'an error occurred' };
|
|
493
512
|
*
|
|
494
513
|
* util.isError(obj);
|
|
@@ -513,8 +532,8 @@ declare module 'util' {
|
|
|
513
532
|
* through the `constructor.super_` property.
|
|
514
533
|
*
|
|
515
534
|
* ```js
|
|
516
|
-
* const util = require('util');
|
|
517
|
-
* const EventEmitter = require('events');
|
|
535
|
+
* const util = require('node:util');
|
|
536
|
+
* const EventEmitter = require('node:events');
|
|
518
537
|
*
|
|
519
538
|
* function MyStream() {
|
|
520
539
|
* EventEmitter.call(this);
|
|
@@ -540,7 +559,7 @@ declare module 'util' {
|
|
|
540
559
|
* ES6 example using `class` and `extends`:
|
|
541
560
|
*
|
|
542
561
|
* ```js
|
|
543
|
-
* const EventEmitter = require('events');
|
|
562
|
+
* const EventEmitter = require('node:events');
|
|
544
563
|
*
|
|
545
564
|
* class MyStream extends EventEmitter {
|
|
546
565
|
* write(data) {
|
|
@@ -569,7 +588,7 @@ declare module 'util' {
|
|
|
569
588
|
* environment variable, then the returned function operates similar to `console.error()`. If not, then the returned function is a no-op.
|
|
570
589
|
*
|
|
571
590
|
* ```js
|
|
572
|
-
* const util = require('util');
|
|
591
|
+
* const util = require('node:util');
|
|
573
592
|
* const debuglog = util.debuglog('foo');
|
|
574
593
|
*
|
|
575
594
|
* debuglog('hello from foo [%d]', 123);
|
|
@@ -588,7 +607,7 @@ declare module 'util' {
|
|
|
588
607
|
* The `section` supports wildcard also:
|
|
589
608
|
*
|
|
590
609
|
* ```js
|
|
591
|
-
* const util = require('util');
|
|
610
|
+
* const util = require('node:util');
|
|
592
611
|
* const debuglog = util.debuglog('foo-bar');
|
|
593
612
|
*
|
|
594
613
|
* debuglog('hi there, it\'s foo-bar [%d]', 2333);
|
|
@@ -608,7 +627,7 @@ declare module 'util' {
|
|
|
608
627
|
* unnecessary wrapping.
|
|
609
628
|
*
|
|
610
629
|
* ```js
|
|
611
|
-
* const util = require('util');
|
|
630
|
+
* const util = require('node:util');
|
|
612
631
|
* let debuglog = util.debuglog('internals', (debug) => {
|
|
613
632
|
* // Replace with a logging function that optimizes out
|
|
614
633
|
* // testing if the section is enabled
|
|
@@ -626,7 +645,7 @@ declare module 'util' {
|
|
|
626
645
|
* Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`.
|
|
627
646
|
*
|
|
628
647
|
* ```js
|
|
629
|
-
* const util = require('util');
|
|
648
|
+
* const util = require('node:util');
|
|
630
649
|
*
|
|
631
650
|
* util.isBoolean(1);
|
|
632
651
|
* // Returns: false
|
|
@@ -643,7 +662,7 @@ declare module 'util' {
|
|
|
643
662
|
* Returns `true` if the given `object` is a `Buffer`. Otherwise, returns `false`.
|
|
644
663
|
*
|
|
645
664
|
* ```js
|
|
646
|
-
* const util = require('util');
|
|
665
|
+
* const util = require('node:util');
|
|
647
666
|
*
|
|
648
667
|
* util.isBuffer({ length: 0 });
|
|
649
668
|
* // Returns: false
|
|
@@ -660,7 +679,7 @@ declare module 'util' {
|
|
|
660
679
|
* Returns `true` if the given `object` is a `Function`. Otherwise, returns`false`.
|
|
661
680
|
*
|
|
662
681
|
* ```js
|
|
663
|
-
* const util = require('util');
|
|
682
|
+
* const util = require('node:util');
|
|
664
683
|
*
|
|
665
684
|
* function Foo() {}
|
|
666
685
|
* const Bar = () => {};
|
|
@@ -680,7 +699,7 @@ declare module 'util' {
|
|
|
680
699
|
* Returns `true` if the given `object` is strictly `null`. Otherwise, returns`false`.
|
|
681
700
|
*
|
|
682
701
|
* ```js
|
|
683
|
-
* const util = require('util');
|
|
702
|
+
* const util = require('node:util');
|
|
684
703
|
*
|
|
685
704
|
* util.isNull(0);
|
|
686
705
|
* // Returns: false
|
|
@@ -698,7 +717,7 @@ declare module 'util' {
|
|
|
698
717
|
* returns `false`.
|
|
699
718
|
*
|
|
700
719
|
* ```js
|
|
701
|
-
* const util = require('util');
|
|
720
|
+
* const util = require('node:util');
|
|
702
721
|
*
|
|
703
722
|
* util.isNullOrUndefined(0);
|
|
704
723
|
* // Returns: false
|
|
@@ -715,7 +734,7 @@ declare module 'util' {
|
|
|
715
734
|
* Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`.
|
|
716
735
|
*
|
|
717
736
|
* ```js
|
|
718
|
-
* const util = require('util');
|
|
737
|
+
* const util = require('node:util');
|
|
719
738
|
*
|
|
720
739
|
* util.isNumber(false);
|
|
721
740
|
* // Returns: false
|
|
@@ -735,7 +754,7 @@ declare module 'util' {
|
|
|
735
754
|
* Otherwise, returns `false`.
|
|
736
755
|
*
|
|
737
756
|
* ```js
|
|
738
|
-
* const util = require('util');
|
|
757
|
+
* const util = require('node:util');
|
|
739
758
|
*
|
|
740
759
|
* util.isObject(5);
|
|
741
760
|
* // Returns: false
|
|
@@ -747,14 +766,14 @@ declare module 'util' {
|
|
|
747
766
|
* // Returns: false
|
|
748
767
|
* ```
|
|
749
768
|
* @since v0.11.5
|
|
750
|
-
* @deprecated Since v4.0.0 -
|
|
769
|
+
* @deprecated Since v4.0.0 - Use `value !== null && typeof value === 'object'` instead.
|
|
751
770
|
*/
|
|
752
771
|
export function isObject(object: unknown): boolean;
|
|
753
772
|
/**
|
|
754
773
|
* Returns `true` if the given `object` is a primitive type. Otherwise, returns`false`.
|
|
755
774
|
*
|
|
756
775
|
* ```js
|
|
757
|
-
* const util = require('util');
|
|
776
|
+
* const util = require('node:util');
|
|
758
777
|
*
|
|
759
778
|
* util.isPrimitive(5);
|
|
760
779
|
* // Returns: true
|
|
@@ -783,7 +802,7 @@ declare module 'util' {
|
|
|
783
802
|
* Returns `true` if the given `object` is a `string`. Otherwise, returns `false`.
|
|
784
803
|
*
|
|
785
804
|
* ```js
|
|
786
|
-
* const util = require('util');
|
|
805
|
+
* const util = require('node:util');
|
|
787
806
|
*
|
|
788
807
|
* util.isString('');
|
|
789
808
|
* // Returns: true
|
|
@@ -802,7 +821,7 @@ declare module 'util' {
|
|
|
802
821
|
* Returns `true` if the given `object` is a `Symbol`. Otherwise, returns `false`.
|
|
803
822
|
*
|
|
804
823
|
* ```js
|
|
805
|
-
* const util = require('util');
|
|
824
|
+
* const util = require('node:util');
|
|
806
825
|
*
|
|
807
826
|
* util.isSymbol(5);
|
|
808
827
|
* // Returns: false
|
|
@@ -819,7 +838,7 @@ declare module 'util' {
|
|
|
819
838
|
* Returns `true` if the given `object` is `undefined`. Otherwise, returns `false`.
|
|
820
839
|
*
|
|
821
840
|
* ```js
|
|
822
|
-
* const util = require('util');
|
|
841
|
+
* const util = require('node:util');
|
|
823
842
|
*
|
|
824
843
|
* const foo = undefined;
|
|
825
844
|
* util.isUndefined(5);
|
|
@@ -838,7 +857,7 @@ declare module 'util' {
|
|
|
838
857
|
* such a way that it is marked as deprecated.
|
|
839
858
|
*
|
|
840
859
|
* ```js
|
|
841
|
-
* const util = require('util');
|
|
860
|
+
* const util = require('node:util');
|
|
842
861
|
*
|
|
843
862
|
* exports.obsoleteFunction = util.deprecate(() => {
|
|
844
863
|
* // Do something here.
|
|
@@ -854,7 +873,7 @@ declare module 'util' {
|
|
|
854
873
|
* the warning will be emitted only once for that `code`.
|
|
855
874
|
*
|
|
856
875
|
* ```js
|
|
857
|
-
* const util = require('util');
|
|
876
|
+
* const util = require('node:util');
|
|
858
877
|
*
|
|
859
878
|
* const fn1 = util.deprecate(someFunction, someMessage, 'DEP0001');
|
|
860
879
|
* const fn2 = util.deprecate(someOtherFunction, someOtherMessage, 'DEP0001');
|
|
@@ -908,7 +927,7 @@ declare module 'util' {
|
|
|
908
927
|
* first argument will be the rejection reason (or `null` if the `Promise`resolved), and the second argument will be the resolved value.
|
|
909
928
|
*
|
|
910
929
|
* ```js
|
|
911
|
-
* const util = require('util');
|
|
930
|
+
* const util = require('node:util');
|
|
912
931
|
*
|
|
913
932
|
* async function fn() {
|
|
914
933
|
* return 'hello world';
|
|
@@ -991,8 +1010,8 @@ declare module 'util' {
|
|
|
991
1010
|
* that returns promises.
|
|
992
1011
|
*
|
|
993
1012
|
* ```js
|
|
994
|
-
* const util = require('util');
|
|
995
|
-
* const fs = require('fs');
|
|
1013
|
+
* const util = require('node:util');
|
|
1014
|
+
* const fs = require('node:fs');
|
|
996
1015
|
*
|
|
997
1016
|
* const stat = util.promisify(fs.stat);
|
|
998
1017
|
* stat('.').then((stats) => {
|
|
@@ -1005,8 +1024,8 @@ declare module 'util' {
|
|
|
1005
1024
|
* Or, equivalently using `async function`s:
|
|
1006
1025
|
*
|
|
1007
1026
|
* ```js
|
|
1008
|
-
* const util = require('util');
|
|
1009
|
-
* const fs = require('fs');
|
|
1027
|
+
* const util = require('node:util');
|
|
1028
|
+
* const fs = require('node:fs');
|
|
1010
1029
|
*
|
|
1011
1030
|
* const stat = util.promisify(fs.stat);
|
|
1012
1031
|
*
|
|
@@ -1027,7 +1046,7 @@ declare module 'util' {
|
|
|
1027
1046
|
* work as expected unless handled specially:
|
|
1028
1047
|
*
|
|
1029
1048
|
* ```js
|
|
1030
|
-
* const util = require('util');
|
|
1049
|
+
* const util = require('node:util');
|
|
1031
1050
|
*
|
|
1032
1051
|
* class Foo {
|
|
1033
1052
|
* constructor() {
|
|
@@ -1116,7 +1135,7 @@ declare module 'util' {
|
|
|
1116
1135
|
* internally and emitted after the next call to `textDecoder.decode()`.
|
|
1117
1136
|
*
|
|
1118
1137
|
* If `textDecoder.fatal` is `true`, decoding errors that occur will result in a`TypeError` being thrown.
|
|
1119
|
-
* @param input An `ArrayBuffer`, `DataView
|
|
1138
|
+
* @param input An `ArrayBuffer`, `DataView`, or `TypedArray` instance containing the encoded data.
|
|
1120
1139
|
*/
|
|
1121
1140
|
decode(
|
|
1122
1141
|
input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
|
|
@@ -1176,7 +1195,6 @@ declare module 'util' {
|
|
|
1176
1195
|
*/
|
|
1177
1196
|
encodeInto(src: string, dest: Uint8Array): EncodeIntoResult;
|
|
1178
1197
|
}
|
|
1179
|
-
|
|
1180
1198
|
import { TextDecoder as _TextDecoder, TextEncoder as _TextEncoder } from 'util';
|
|
1181
1199
|
global {
|
|
1182
1200
|
/**
|
|
@@ -1184,19 +1202,18 @@ declare module 'util' {
|
|
|
1184
1202
|
* https://nodejs.org/api/globals.html#textdecoder
|
|
1185
1203
|
* @since v11.0.0
|
|
1186
1204
|
*/
|
|
1187
|
-
|
|
1205
|
+
var TextDecoder: typeof globalThis extends {
|
|
1188
1206
|
onmessage: any;
|
|
1189
1207
|
TextDecoder: infer TextDecoder;
|
|
1190
1208
|
}
|
|
1191
1209
|
? TextDecoder
|
|
1192
1210
|
: typeof _TextDecoder;
|
|
1193
|
-
|
|
1194
1211
|
/**
|
|
1195
1212
|
* `TextEncoder` class is a global reference for `require('util').TextEncoder`
|
|
1196
1213
|
* https://nodejs.org/api/globals.html#textencoder
|
|
1197
1214
|
* @since v11.0.0
|
|
1198
1215
|
*/
|
|
1199
|
-
|
|
1216
|
+
var TextEncoder: typeof globalThis extends {
|
|
1200
1217
|
onmessage: any;
|
|
1201
1218
|
TextEncoder: infer TextEncoder;
|
|
1202
1219
|
}
|
|
@@ -1206,48 +1223,34 @@ declare module 'util' {
|
|
|
1206
1223
|
|
|
1207
1224
|
//// parseArgs
|
|
1208
1225
|
/**
|
|
1209
|
-
* Provides a
|
|
1210
|
-
* specification for the expected arguments
|
|
1211
|
-
* with the parsed
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
*
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1217
|
-
*
|
|
1218
|
-
*
|
|
1219
|
-
*
|
|
1220
|
-
*
|
|
1221
|
-
*
|
|
1222
|
-
*
|
|
1223
|
-
*
|
|
1224
|
-
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1227
|
-
*
|
|
1228
|
-
*
|
|
1229
|
-
*
|
|
1230
|
-
*
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
* **Default:** `false` if `strict` is `true`, otherwise `true`.
|
|
1236
|
-
* - `tokens`: Whether tokens {boolean} Return the parsed tokens. This is useful
|
|
1237
|
-
* for extending the built-in behavior, from adding additional checks through
|
|
1238
|
-
* to reprocessing the tokens in different ways.
|
|
1239
|
-
* **Default:** `false`.
|
|
1240
|
-
*
|
|
1241
|
-
* @returns The parsed command line arguments:
|
|
1242
|
-
*
|
|
1243
|
-
* - `values` A mapping of parsed option names with their string
|
|
1244
|
-
* or boolean values.
|
|
1245
|
-
* - `positionals` Positional arguments.
|
|
1246
|
-
* - `tokens` Detailed parse information (only if `tokens` was specified).
|
|
1247
|
-
*
|
|
1226
|
+
* Provides a higher level API for command-line argument parsing than interacting
|
|
1227
|
+
* with `process.argv` directly. Takes a specification for the expected arguments
|
|
1228
|
+
* and returns a structured object with the parsed options and positionals.
|
|
1229
|
+
*
|
|
1230
|
+
* ```js
|
|
1231
|
+
* import { parseArgs } from 'node:util';
|
|
1232
|
+
* const args = ['-f', '--bar', 'b'];
|
|
1233
|
+
* const options = {
|
|
1234
|
+
* foo: {
|
|
1235
|
+
* type: 'boolean',
|
|
1236
|
+
* short: 'f',
|
|
1237
|
+
* },
|
|
1238
|
+
* bar: {
|
|
1239
|
+
* type: 'string',
|
|
1240
|
+
* },
|
|
1241
|
+
* };
|
|
1242
|
+
* const {
|
|
1243
|
+
* values,
|
|
1244
|
+
* positionals,
|
|
1245
|
+
* } = parseArgs({ args, options });
|
|
1246
|
+
* console.log(values, positionals);
|
|
1247
|
+
* // Prints: [Object: null prototype] { foo: true, bar: 'b' } []
|
|
1248
|
+
* ```
|
|
1249
|
+
* @since v18.3.0, v16.17.0
|
|
1250
|
+
* @param config Used to provide arguments for parsing and to configure the parser. `config` supports the following properties:
|
|
1251
|
+
* @return The parsed command line arguments:
|
|
1248
1252
|
*/
|
|
1249
1253
|
export function parseArgs<T extends ParseArgsConfig>(config?: T): ParsedResults<T>;
|
|
1250
|
-
|
|
1251
1254
|
interface ParseArgsOptionConfig {
|
|
1252
1255
|
/**
|
|
1253
1256
|
* Type of argument.
|
|
@@ -1272,11 +1275,9 @@ declare module 'util' {
|
|
|
1272
1275
|
*/
|
|
1273
1276
|
default?: string | boolean | string[] | boolean[] | undefined;
|
|
1274
1277
|
}
|
|
1275
|
-
|
|
1276
1278
|
interface ParseArgsOptionsConfig {
|
|
1277
1279
|
[longOption: string]: ParseArgsOptionConfig;
|
|
1278
1280
|
}
|
|
1279
|
-
|
|
1280
1281
|
export interface ParseArgsConfig {
|
|
1281
1282
|
/**
|
|
1282
1283
|
* Array of argument strings.
|
|
@@ -1303,7 +1304,6 @@ declare module 'util' {
|
|
|
1303
1304
|
*/
|
|
1304
1305
|
tokens?: boolean | undefined;
|
|
1305
1306
|
}
|
|
1306
|
-
|
|
1307
1307
|
/*
|
|
1308
1308
|
IfDefaultsTrue and IfDefaultsFalse are helpers to handle default values for missing boolean properties.
|
|
1309
1309
|
TypeScript does not have exact types for objects: https://github.com/microsoft/TypeScript/issues/12936
|
|
@@ -1427,14 +1427,26 @@ declare module 'util' {
|
|
|
1427
1427
|
// So we can't rely on the `"not definitely present" implies "definitely not present"` assumption mentioned above.
|
|
1428
1428
|
type ParsedResults<T extends ParseArgsConfig> = ParseArgsConfig extends T
|
|
1429
1429
|
? {
|
|
1430
|
-
values: {
|
|
1430
|
+
values: {
|
|
1431
|
+
[longOption: string]: undefined | string | boolean | Array<string | boolean>;
|
|
1432
|
+
};
|
|
1431
1433
|
positionals: string[];
|
|
1432
1434
|
tokens?: Token[];
|
|
1433
1435
|
}
|
|
1434
1436
|
: PreciseParsedResults<T>;
|
|
1435
1437
|
|
|
1436
1438
|
/**
|
|
1437
|
-
*
|
|
1439
|
+
* An implementation of [the MIMEType class](https://bmeck.github.io/node-proposal-mime-api/).
|
|
1440
|
+
*
|
|
1441
|
+
* In accordance with browser conventions, all properties of `MIMEType` objects
|
|
1442
|
+
* are implemented as getters and setters on the class prototype, rather than as
|
|
1443
|
+
* data properties on the object itself.
|
|
1444
|
+
*
|
|
1445
|
+
* A MIME string is a structured string containing multiple meaningful
|
|
1446
|
+
* components. When parsed, a `MIMEType` object is returned containing
|
|
1447
|
+
* properties for each of these components.
|
|
1448
|
+
* @since v19.1.0, v18.13.0
|
|
1449
|
+
* @experimental
|
|
1438
1450
|
*/
|
|
1439
1451
|
export class MIMEType {
|
|
1440
1452
|
/**
|
|
@@ -1450,24 +1462,20 @@ declare module 'util' {
|
|
|
1450
1462
|
* Gets and sets the type portion of the MIME.
|
|
1451
1463
|
*/
|
|
1452
1464
|
type: string;
|
|
1453
|
-
|
|
1454
1465
|
/**
|
|
1455
1466
|
* Gets and sets the subtype portion of the MIME.
|
|
1456
1467
|
*/
|
|
1457
1468
|
subtype: string;
|
|
1458
|
-
|
|
1459
1469
|
/**
|
|
1460
1470
|
* Gets the essence of the MIME.
|
|
1461
1471
|
*
|
|
1462
1472
|
* Use `mime.type` or `mime.subtype` to alter the MIME.
|
|
1463
1473
|
*/
|
|
1464
1474
|
readonly essence: string;
|
|
1465
|
-
|
|
1466
1475
|
/**
|
|
1467
1476
|
* Gets the `MIMEParams` object representing the parameters of the MIME.
|
|
1468
1477
|
*/
|
|
1469
1478
|
readonly params: MIMEParams;
|
|
1470
|
-
|
|
1471
1479
|
/**
|
|
1472
1480
|
* Returns the serialized MIME.
|
|
1473
1481
|
*
|
|
@@ -1476,7 +1484,6 @@ declare module 'util' {
|
|
|
1476
1484
|
*/
|
|
1477
1485
|
toString(): string;
|
|
1478
1486
|
}
|
|
1479
|
-
|
|
1480
1487
|
/**
|
|
1481
1488
|
* @since v18.13.0
|
|
1482
1489
|
*/
|
|
@@ -1814,12 +1821,40 @@ declare module 'util/types' {
|
|
|
1814
1821
|
*/
|
|
1815
1822
|
function isModuleNamespaceObject(value: unknown): boolean;
|
|
1816
1823
|
/**
|
|
1817
|
-
* Returns `true` if the value
|
|
1824
|
+
* Returns `true` if the value was returned by the constructor of a [built-in `Error` type](https://tc39.es/ecma262/#sec-error-objects).
|
|
1825
|
+
*
|
|
1826
|
+
* ```js
|
|
1827
|
+
* console.log(util.types.isNativeError(new Error())); // true
|
|
1828
|
+
* console.log(util.types.isNativeError(new TypeError())); // true
|
|
1829
|
+
* console.log(util.types.isNativeError(new RangeError())); // true
|
|
1830
|
+
* ```
|
|
1831
|
+
*
|
|
1832
|
+
* Subclasses of the native error types are also native errors:
|
|
1833
|
+
*
|
|
1834
|
+
* ```js
|
|
1835
|
+
* class MyError extends Error {}
|
|
1836
|
+
* console.log(util.types.isNativeError(new MyError())); // true
|
|
1837
|
+
* ```
|
|
1838
|
+
*
|
|
1839
|
+
* A value being `instanceof` a native error class is not equivalent to `isNativeError()`returning `true` for that value. `isNativeError()` returns `true` for errors
|
|
1840
|
+
* which come from a different [realm](https://tc39.es/ecma262/#realm) while `instanceof Error` returns `false`for these errors:
|
|
1841
|
+
*
|
|
1842
|
+
* ```js
|
|
1843
|
+
* const vm = require('node:vm');
|
|
1844
|
+
* const context = vm.createContext({});
|
|
1845
|
+
* const myError = vm.runInContext('new Error()', context);
|
|
1846
|
+
* console.log(util.types.isNativeError(myError)); // true
|
|
1847
|
+
* console.log(myError instanceof Error); // false
|
|
1848
|
+
* ```
|
|
1849
|
+
*
|
|
1850
|
+
* Conversely, `isNativeError()` returns `false` for all objects which were not
|
|
1851
|
+
* returned by the constructor of a native error. That includes values
|
|
1852
|
+
* which are `instanceof` native errors:
|
|
1818
1853
|
*
|
|
1819
1854
|
* ```js
|
|
1820
|
-
*
|
|
1821
|
-
* util.types.isNativeError(
|
|
1822
|
-
*
|
|
1855
|
+
* const myError = { __proto__: Error.prototype };
|
|
1856
|
+
* console.log(util.types.isNativeError(myError)); // false
|
|
1857
|
+
* console.log(myError instanceof Error); // true
|
|
1823
1858
|
* ```
|
|
1824
1859
|
* @since v10.0.0
|
|
1825
1860
|
*/
|