@types/node 18.11.5 → 20.2.5
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 +2 -2
- node/assert.d.ts +86 -75
- node/async_hooks.d.ts +66 -37
- node/buffer.d.ts +193 -100
- node/child_process.d.ts +82 -56
- node/cluster.d.ts +12 -12
- node/console.d.ts +5 -5
- node/crypto.d.ts +233 -235
- node/dgram.d.ts +15 -15
- node/diagnostics_channel.d.ts +59 -21
- node/dns/promises.d.ts +50 -6
- node/dns.d.ts +26 -17
- node/domain.d.ts +4 -4
- node/events.d.ts +111 -65
- node/fs/promises.d.ts +99 -47
- node/fs.d.ts +244 -73
- node/globals.d.ts +6 -3
- node/http.d.ts +265 -148
- node/http2.d.ts +42 -47
- node/https.d.ts +53 -153
- node/index.d.ts +2 -1
- node/inspector.d.ts +10 -3
- node/module.d.ts +6 -4
- node/net.d.ts +32 -15
- node/os.d.ts +27 -16
- node/package.json +9 -4
- node/path.d.ts +4 -4
- node/perf_hooks.d.ts +28 -15
- node/process.d.ts +49 -46
- node/punycode.d.ts +1 -1
- node/querystring.d.ts +5 -5
- node/readline/promises.d.ts +65 -63
- node/readline.d.ts +32 -159
- node/repl.d.ts +20 -20
- node/stream/consumers.d.ts +1 -1
- node/stream.d.ts +950 -869
- node/string_decoder.d.ts +6 -6
- node/test.d.ts +877 -139
- node/timers/promises.d.ts +26 -1
- node/timers.d.ts +125 -4
- node/tls.d.ts +120 -29
- node/trace_events.d.ts +20 -9
- node/ts4.8/assert.d.ts +86 -75
- node/ts4.8/async_hooks.d.ts +66 -37
- node/ts4.8/buffer.d.ts +193 -101
- node/ts4.8/child_process.d.ts +82 -56
- node/ts4.8/cluster.d.ts +12 -12
- node/ts4.8/console.d.ts +5 -5
- node/ts4.8/crypto.d.ts +230 -233
- node/ts4.8/dgram.d.ts +15 -15
- node/ts4.8/diagnostics_channel.d.ts +59 -21
- node/ts4.8/dns/promises.d.ts +50 -6
- node/ts4.8/dns.d.ts +26 -17
- node/ts4.8/domain.d.ts +4 -4
- node/ts4.8/events.d.ts +111 -65
- node/ts4.8/fs/promises.d.ts +97 -46
- node/ts4.8/fs.d.ts +244 -73
- node/ts4.8/globals.d.ts +21 -12
- node/ts4.8/http.d.ts +265 -148
- node/ts4.8/http2.d.ts +42 -47
- node/ts4.8/https.d.ts +53 -153
- node/ts4.8/inspector.d.ts +10 -3
- node/ts4.8/module.d.ts +6 -4
- node/ts4.8/net.d.ts +33 -16
- node/ts4.8/os.d.ts +27 -16
- node/ts4.8/path.d.ts +4 -4
- node/ts4.8/perf_hooks.d.ts +28 -15
- node/ts4.8/process.d.ts +49 -46
- node/ts4.8/punycode.d.ts +1 -1
- node/ts4.8/querystring.d.ts +5 -5
- node/ts4.8/readline/promises.d.ts +65 -63
- node/ts4.8/readline.d.ts +32 -159
- node/ts4.8/repl.d.ts +20 -20
- node/ts4.8/stream/consumers.d.ts +1 -1
- node/ts4.8/stream.d.ts +192 -140
- node/ts4.8/string_decoder.d.ts +6 -6
- node/ts4.8/test.d.ts +877 -139
- node/ts4.8/timers/promises.d.ts +26 -1
- node/ts4.8/timers.d.ts +125 -4
- node/ts4.8/tls.d.ts +120 -29
- node/ts4.8/trace_events.d.ts +20 -9
- node/ts4.8/tty.d.ts +4 -5
- node/ts4.8/url.d.ts +46 -42
- node/ts4.8/util.d.ts +325 -123
- node/ts4.8/v8.d.ts +253 -14
- node/ts4.8/vm.d.ts +417 -32
- node/ts4.8/wasi.d.ts +13 -19
- node/ts4.8/worker_threads.d.ts +38 -34
- node/ts4.8/zlib.d.ts +11 -11
- node/tty.d.ts +4 -5
- node/url.d.ts +46 -42
- node/util.d.ts +325 -123
- node/v8.d.ts +253 -14
- node/vm.d.ts +417 -32
- node/wasi.d.ts +13 -19
- node/worker_threads.d.ts +38 -34
- node/zlib.d.ts +11 -11
node/ts4.8/util.d.ts
CHANGED
|
@@ -1,33 +1,49 @@
|
|
|
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.2.0/lib/util.js)
|
|
10
10
|
*/
|
|
11
11
|
declare module 'util' {
|
|
12
12
|
import * as types from 'node:util/types';
|
|
13
13
|
export interface InspectOptions {
|
|
14
14
|
/**
|
|
15
|
-
* If
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* setter are going to be inspected. This might cause side effects depending on
|
|
19
|
-
* the getter function.
|
|
20
|
-
* @default `false`
|
|
15
|
+
* If `true`, object's non-enumerable symbols and properties are included in the formatted result.
|
|
16
|
+
* `WeakMap` and `WeakSet` entries are also included as well as user defined prototype properties (excluding method properties).
|
|
17
|
+
* @default false
|
|
21
18
|
*/
|
|
22
|
-
getters?: 'get' | 'set' | boolean | undefined;
|
|
23
19
|
showHidden?: boolean | undefined;
|
|
24
20
|
/**
|
|
21
|
+
* Specifies the number of times to recurse while formatting object.
|
|
22
|
+
* This is useful for inspecting large objects.
|
|
23
|
+
* To recurse up to the maximum call stack size pass `Infinity` or `null`.
|
|
25
24
|
* @default 2
|
|
26
25
|
*/
|
|
27
26
|
depth?: number | null | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* If `true`, the output is styled with ANSI color codes. Colors are customizable.
|
|
29
|
+
*/
|
|
28
30
|
colors?: boolean | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* If `false`, `[util.inspect.custom](depth, opts, inspect)` functions are not invoked.
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
29
35
|
customInspect?: boolean | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* If `true`, `Proxy` inspection includes the target and handler objects.
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
30
40
|
showProxy?: boolean | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Specifies the maximum number of `Array`, `TypedArray`, `WeakMap`, and `WeakSet` elements
|
|
43
|
+
* to include when formatting. Set to `null` or `Infinity` to show all elements.
|
|
44
|
+
* Set to `0` or negative to show no elements.
|
|
45
|
+
* @default 100
|
|
46
|
+
*/
|
|
31
47
|
maxArrayLength?: number | null | undefined;
|
|
32
48
|
/**
|
|
33
49
|
* Specifies the maximum number of characters to
|
|
@@ -36,6 +52,12 @@ declare module 'util' {
|
|
|
36
52
|
* @default 10000
|
|
37
53
|
*/
|
|
38
54
|
maxStringLength?: number | null | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* The length at which input values are split across multiple lines.
|
|
57
|
+
* Set to `Infinity` to format the input as a single line
|
|
58
|
+
* (in combination with `compact` set to `true` or any number >= `1`).
|
|
59
|
+
* @default 80
|
|
60
|
+
*/
|
|
39
61
|
breakLength?: number | undefined;
|
|
40
62
|
/**
|
|
41
63
|
* Setting this to `false` causes each object key
|
|
@@ -45,13 +67,33 @@ declare module 'util' {
|
|
|
45
67
|
* `breakLength`. Short array elements are also grouped together. Note that no
|
|
46
68
|
* text will be reduced below 16 characters, no matter the `breakLength` size.
|
|
47
69
|
* For more information, see the example below.
|
|
48
|
-
* @default
|
|
70
|
+
* @default true
|
|
49
71
|
*/
|
|
50
72
|
compact?: boolean | number | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* If set to `true` or a function, all properties of an object, and `Set` and `Map`
|
|
75
|
+
* entries are sorted in the resulting string.
|
|
76
|
+
* If set to `true` the default sort is used.
|
|
77
|
+
* If set to a function, it is used as a compare function.
|
|
78
|
+
*/
|
|
51
79
|
sorted?: boolean | ((a: string, b: string) => number) | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* If set to `true`, getters are going to be
|
|
82
|
+
* inspected as well. If set to `'get'` only getters without setter are going
|
|
83
|
+
* to be inspected. If set to `'set'` only getters having a corresponding
|
|
84
|
+
* setter are going to be inspected. This might cause side effects depending on
|
|
85
|
+
* the getter function.
|
|
86
|
+
* @default false
|
|
87
|
+
*/
|
|
88
|
+
getters?: 'get' | 'set' | boolean | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* If set to `true`, an underscore is used to separate every three digits in all bigints and numbers.
|
|
91
|
+
* @default false
|
|
92
|
+
*/
|
|
93
|
+
numericSeparator?: boolean | undefined;
|
|
52
94
|
}
|
|
53
95
|
export type Style = 'special' | 'number' | 'bigint' | 'boolean' | 'undefined' | 'null' | 'string' | 'symbol' | 'date' | 'regexp' | 'module';
|
|
54
|
-
export type CustomInspectFunction = (depth: number, options: InspectOptionsStylized) =>
|
|
96
|
+
export type CustomInspectFunction = (depth: number, options: InspectOptionsStylized) => any; // TODO: , inspect: inspect
|
|
55
97
|
export interface InspectOptionsStylized extends InspectOptions {
|
|
56
98
|
stylize(text: string, styleType: Style): string;
|
|
57
99
|
}
|
|
@@ -147,7 +189,7 @@ declare module 'util' {
|
|
|
147
189
|
* timestamp.
|
|
148
190
|
*
|
|
149
191
|
* ```js
|
|
150
|
-
* const util = require('util');
|
|
192
|
+
* const util = require('node:util');
|
|
151
193
|
*
|
|
152
194
|
* util.log('Timestamped message.');
|
|
153
195
|
* ```
|
|
@@ -166,12 +208,12 @@ declare module 'util' {
|
|
|
166
208
|
* Creates and returns an `AbortController` instance whose `AbortSignal` is marked
|
|
167
209
|
* as transferable and can be used with `structuredClone()` or `postMessage()`.
|
|
168
210
|
* @since v18.11.0
|
|
211
|
+
* @experimental
|
|
169
212
|
* @returns A transferable AbortController
|
|
170
213
|
*/
|
|
171
214
|
export function transferableAbortController(): AbortController;
|
|
172
215
|
/**
|
|
173
|
-
* Marks the given
|
|
174
|
-
* `structuredClone()` and `postMessage()`.
|
|
216
|
+
* Marks the given `AbortSignal` as transferable so that it can be used with`structuredClone()` and `postMessage()`.
|
|
175
217
|
*
|
|
176
218
|
* ```js
|
|
177
219
|
* const signal = transferableAbortSignal(AbortSignal.timeout(100));
|
|
@@ -179,10 +221,35 @@ declare module 'util' {
|
|
|
179
221
|
* channel.port2.postMessage(signal, [signal]);
|
|
180
222
|
* ```
|
|
181
223
|
* @since v18.11.0
|
|
224
|
+
* @experimental
|
|
182
225
|
* @param signal The AbortSignal
|
|
183
226
|
* @returns The same AbortSignal
|
|
184
227
|
*/
|
|
185
228
|
export function transferableAbortSignal(signal: AbortSignal): AbortSignal;
|
|
229
|
+
/**
|
|
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.
|
|
251
|
+
*/
|
|
252
|
+
export function aborted(signal: AbortSignal, resource: any): Promise<void>;
|
|
186
253
|
/**
|
|
187
254
|
* The `util.inspect()` method returns a string representation of `object` that is
|
|
188
255
|
* intended for debugging. The output of `util.inspect` may change at any time
|
|
@@ -209,7 +276,7 @@ declare module 'util' {
|
|
|
209
276
|
* Circular references point to their anchor by using a reference index:
|
|
210
277
|
*
|
|
211
278
|
* ```js
|
|
212
|
-
* const { inspect } = require('util');
|
|
279
|
+
* const { inspect } = require('node:util');
|
|
213
280
|
*
|
|
214
281
|
* const obj = {};
|
|
215
282
|
* obj.a = [obj];
|
|
@@ -227,7 +294,7 @@ declare module 'util' {
|
|
|
227
294
|
* The following example inspects all properties of the `util` object:
|
|
228
295
|
*
|
|
229
296
|
* ```js
|
|
230
|
-
* const util = require('util');
|
|
297
|
+
* const util = require('node:util');
|
|
231
298
|
*
|
|
232
299
|
* console.log(util.inspect(util, { showHidden: true, depth: null }));
|
|
233
300
|
* ```
|
|
@@ -235,7 +302,7 @@ declare module 'util' {
|
|
|
235
302
|
* The following example highlights the effect of the `compact` option:
|
|
236
303
|
*
|
|
237
304
|
* ```js
|
|
238
|
-
* const util = require('util');
|
|
305
|
+
* const util = require('node:util');
|
|
239
306
|
*
|
|
240
307
|
* const o = {
|
|
241
308
|
* a: [1, 2, [[
|
|
@@ -243,7 +310,7 @@ declare module 'util' {
|
|
|
243
310
|
* 'eiusmod \ntempor incididunt ut labore et dolore magna aliqua.',
|
|
244
311
|
* 'test',
|
|
245
312
|
* 'foo']], 4],
|
|
246
|
-
* b: new Map([['za', 1], ['zb', 'test']])
|
|
313
|
+
* b: new Map([['za', 1], ['zb', 'test']]),
|
|
247
314
|
* };
|
|
248
315
|
* console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));
|
|
249
316
|
*
|
|
@@ -292,7 +359,7 @@ declare module 'util' {
|
|
|
292
359
|
* with no remaining strong references may be garbage collected at any time.
|
|
293
360
|
*
|
|
294
361
|
* ```js
|
|
295
|
-
* const { inspect } = require('util');
|
|
362
|
+
* const { inspect } = require('node:util');
|
|
296
363
|
*
|
|
297
364
|
* const obj = { a: 1 };
|
|
298
365
|
* const obj2 = { b: 2 };
|
|
@@ -306,13 +373,13 @@ declare module 'util' {
|
|
|
306
373
|
* impact the result of `util.inspect()`.
|
|
307
374
|
*
|
|
308
375
|
* ```js
|
|
309
|
-
* const { inspect } = require('util');
|
|
310
|
-
* const assert = require('assert');
|
|
376
|
+
* const { inspect } = require('node:util');
|
|
377
|
+
* const assert = require('node:assert');
|
|
311
378
|
*
|
|
312
379
|
* const o1 = {
|
|
313
380
|
* b: [2, 3, 1],
|
|
314
381
|
* a: '`a` comes before `b`',
|
|
315
|
-
* c: new Set([2, 3, 1])
|
|
382
|
+
* c: new Set([2, 3, 1]),
|
|
316
383
|
* };
|
|
317
384
|
* console.log(inspect(o1, { sorted: true }));
|
|
318
385
|
* // { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set(3) { 1, 2, 3 } }
|
|
@@ -322,11 +389,11 @@ declare module 'util' {
|
|
|
322
389
|
* const o2 = {
|
|
323
390
|
* c: new Set([2, 1, 3]),
|
|
324
391
|
* a: '`a` comes before `b`',
|
|
325
|
-
* b: [2, 3, 1]
|
|
392
|
+
* b: [2, 3, 1],
|
|
326
393
|
* };
|
|
327
394
|
* assert.strict.equal(
|
|
328
395
|
* inspect(o1, { sorted: true }),
|
|
329
|
-
* inspect(o2, { sorted: true })
|
|
396
|
+
* inspect(o2, { sorted: true }),
|
|
330
397
|
* );
|
|
331
398
|
* ```
|
|
332
399
|
*
|
|
@@ -334,7 +401,7 @@ declare module 'util' {
|
|
|
334
401
|
* numbers.
|
|
335
402
|
*
|
|
336
403
|
* ```js
|
|
337
|
-
* const { inspect } = require('util');
|
|
404
|
+
* const { inspect } = require('node:util');
|
|
338
405
|
*
|
|
339
406
|
* const thousand = 1_000;
|
|
340
407
|
* const million = 1_000_000;
|
|
@@ -346,7 +413,7 @@ declare module 'util' {
|
|
|
346
413
|
* ```
|
|
347
414
|
*
|
|
348
415
|
* `util.inspect()` is a synchronous method intended for debugging. Its maximum
|
|
349
|
-
* output length is approximately 128
|
|
416
|
+
* output length is approximately 128 MiB. Inputs that result in longer output will
|
|
350
417
|
* be truncated.
|
|
351
418
|
* @since v0.3.0
|
|
352
419
|
* @param object Any JavaScript primitive or `Object`.
|
|
@@ -375,7 +442,7 @@ declare module 'util' {
|
|
|
375
442
|
* Returns `true` if the given `object` is an `Array`. Otherwise, returns `false`.
|
|
376
443
|
*
|
|
377
444
|
* ```js
|
|
378
|
-
* const util = require('util');
|
|
445
|
+
* const util = require('node:util');
|
|
379
446
|
*
|
|
380
447
|
* util.isArray([]);
|
|
381
448
|
* // Returns: true
|
|
@@ -392,7 +459,7 @@ declare module 'util' {
|
|
|
392
459
|
* Returns `true` if the given `object` is a `RegExp`. Otherwise, returns `false`.
|
|
393
460
|
*
|
|
394
461
|
* ```js
|
|
395
|
-
* const util = require('util');
|
|
462
|
+
* const util = require('node:util');
|
|
396
463
|
*
|
|
397
464
|
* util.isRegExp(/some regexp/);
|
|
398
465
|
* // Returns: true
|
|
@@ -409,7 +476,7 @@ declare module 'util' {
|
|
|
409
476
|
* Returns `true` if the given `object` is a `Date`. Otherwise, returns `false`.
|
|
410
477
|
*
|
|
411
478
|
* ```js
|
|
412
|
-
* const util = require('util');
|
|
479
|
+
* const util = require('node:util');
|
|
413
480
|
*
|
|
414
481
|
* util.isDate(new Date());
|
|
415
482
|
* // Returns: true
|
|
@@ -426,7 +493,7 @@ declare module 'util' {
|
|
|
426
493
|
* Returns `true` if the given `object` is an `Error`. Otherwise, returns`false`.
|
|
427
494
|
*
|
|
428
495
|
* ```js
|
|
429
|
-
* const util = require('util');
|
|
496
|
+
* const util = require('node:util');
|
|
430
497
|
*
|
|
431
498
|
* util.isError(new Error());
|
|
432
499
|
* // Returns: true
|
|
@@ -440,7 +507,7 @@ declare module 'util' {
|
|
|
440
507
|
* possible to obtain an incorrect result when the `object` argument manipulates`@@toStringTag`.
|
|
441
508
|
*
|
|
442
509
|
* ```js
|
|
443
|
-
* const util = require('util');
|
|
510
|
+
* const util = require('node:util');
|
|
444
511
|
* const obj = { name: 'Error', message: 'an error occurred' };
|
|
445
512
|
*
|
|
446
513
|
* util.isError(obj);
|
|
@@ -465,8 +532,8 @@ declare module 'util' {
|
|
|
465
532
|
* through the `constructor.super_` property.
|
|
466
533
|
*
|
|
467
534
|
* ```js
|
|
468
|
-
* const util = require('util');
|
|
469
|
-
* const EventEmitter = require('events');
|
|
535
|
+
* const util = require('node:util');
|
|
536
|
+
* const EventEmitter = require('node:events');
|
|
470
537
|
*
|
|
471
538
|
* function MyStream() {
|
|
472
539
|
* EventEmitter.call(this);
|
|
@@ -492,7 +559,7 @@ declare module 'util' {
|
|
|
492
559
|
* ES6 example using `class` and `extends`:
|
|
493
560
|
*
|
|
494
561
|
* ```js
|
|
495
|
-
* const EventEmitter = require('events');
|
|
562
|
+
* const EventEmitter = require('node:events');
|
|
496
563
|
*
|
|
497
564
|
* class MyStream extends EventEmitter {
|
|
498
565
|
* write(data) {
|
|
@@ -508,7 +575,7 @@ declare module 'util' {
|
|
|
508
575
|
* stream.write('With ES6');
|
|
509
576
|
* ```
|
|
510
577
|
* @since v0.3.0
|
|
511
|
-
* @
|
|
578
|
+
* @legacy Use ES2015 class syntax and `extends` keyword instead.
|
|
512
579
|
*/
|
|
513
580
|
export function inherits(constructor: unknown, superConstructor: unknown): void;
|
|
514
581
|
export type DebugLoggerFunction = (msg: string, ...param: unknown[]) => void;
|
|
@@ -521,7 +588,7 @@ declare module 'util' {
|
|
|
521
588
|
* environment variable, then the returned function operates similar to `console.error()`. If not, then the returned function is a no-op.
|
|
522
589
|
*
|
|
523
590
|
* ```js
|
|
524
|
-
* const util = require('util');
|
|
591
|
+
* const util = require('node:util');
|
|
525
592
|
* const debuglog = util.debuglog('foo');
|
|
526
593
|
*
|
|
527
594
|
* debuglog('hello from foo [%d]', 123);
|
|
@@ -540,7 +607,7 @@ declare module 'util' {
|
|
|
540
607
|
* The `section` supports wildcard also:
|
|
541
608
|
*
|
|
542
609
|
* ```js
|
|
543
|
-
* const util = require('util');
|
|
610
|
+
* const util = require('node:util');
|
|
544
611
|
* const debuglog = util.debuglog('foo-bar');
|
|
545
612
|
*
|
|
546
613
|
* debuglog('hi there, it\'s foo-bar [%d]', 2333);
|
|
@@ -560,7 +627,7 @@ declare module 'util' {
|
|
|
560
627
|
* unnecessary wrapping.
|
|
561
628
|
*
|
|
562
629
|
* ```js
|
|
563
|
-
* const util = require('util');
|
|
630
|
+
* const util = require('node:util');
|
|
564
631
|
* let debuglog = util.debuglog('internals', (debug) => {
|
|
565
632
|
* // Replace with a logging function that optimizes out
|
|
566
633
|
* // testing if the section is enabled
|
|
@@ -578,7 +645,7 @@ declare module 'util' {
|
|
|
578
645
|
* Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`.
|
|
579
646
|
*
|
|
580
647
|
* ```js
|
|
581
|
-
* const util = require('util');
|
|
648
|
+
* const util = require('node:util');
|
|
582
649
|
*
|
|
583
650
|
* util.isBoolean(1);
|
|
584
651
|
* // Returns: false
|
|
@@ -595,7 +662,7 @@ declare module 'util' {
|
|
|
595
662
|
* Returns `true` if the given `object` is a `Buffer`. Otherwise, returns `false`.
|
|
596
663
|
*
|
|
597
664
|
* ```js
|
|
598
|
-
* const util = require('util');
|
|
665
|
+
* const util = require('node:util');
|
|
599
666
|
*
|
|
600
667
|
* util.isBuffer({ length: 0 });
|
|
601
668
|
* // Returns: false
|
|
@@ -612,7 +679,7 @@ declare module 'util' {
|
|
|
612
679
|
* Returns `true` if the given `object` is a `Function`. Otherwise, returns`false`.
|
|
613
680
|
*
|
|
614
681
|
* ```js
|
|
615
|
-
* const util = require('util');
|
|
682
|
+
* const util = require('node:util');
|
|
616
683
|
*
|
|
617
684
|
* function Foo() {}
|
|
618
685
|
* const Bar = () => {};
|
|
@@ -632,7 +699,7 @@ declare module 'util' {
|
|
|
632
699
|
* Returns `true` if the given `object` is strictly `null`. Otherwise, returns`false`.
|
|
633
700
|
*
|
|
634
701
|
* ```js
|
|
635
|
-
* const util = require('util');
|
|
702
|
+
* const util = require('node:util');
|
|
636
703
|
*
|
|
637
704
|
* util.isNull(0);
|
|
638
705
|
* // Returns: false
|
|
@@ -650,7 +717,7 @@ declare module 'util' {
|
|
|
650
717
|
* returns `false`.
|
|
651
718
|
*
|
|
652
719
|
* ```js
|
|
653
|
-
* const util = require('util');
|
|
720
|
+
* const util = require('node:util');
|
|
654
721
|
*
|
|
655
722
|
* util.isNullOrUndefined(0);
|
|
656
723
|
* // Returns: false
|
|
@@ -667,7 +734,7 @@ declare module 'util' {
|
|
|
667
734
|
* Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`.
|
|
668
735
|
*
|
|
669
736
|
* ```js
|
|
670
|
-
* const util = require('util');
|
|
737
|
+
* const util = require('node:util');
|
|
671
738
|
*
|
|
672
739
|
* util.isNumber(false);
|
|
673
740
|
* // Returns: false
|
|
@@ -687,7 +754,7 @@ declare module 'util' {
|
|
|
687
754
|
* Otherwise, returns `false`.
|
|
688
755
|
*
|
|
689
756
|
* ```js
|
|
690
|
-
* const util = require('util');
|
|
757
|
+
* const util = require('node:util');
|
|
691
758
|
*
|
|
692
759
|
* util.isObject(5);
|
|
693
760
|
* // Returns: false
|
|
@@ -699,14 +766,14 @@ declare module 'util' {
|
|
|
699
766
|
* // Returns: false
|
|
700
767
|
* ```
|
|
701
768
|
* @since v0.11.5
|
|
702
|
-
* @deprecated Since v4.0.0 -
|
|
769
|
+
* @deprecated Since v4.0.0 - Use `value !== null && typeof value === 'object'` instead.
|
|
703
770
|
*/
|
|
704
771
|
export function isObject(object: unknown): boolean;
|
|
705
772
|
/**
|
|
706
773
|
* Returns `true` if the given `object` is a primitive type. Otherwise, returns`false`.
|
|
707
774
|
*
|
|
708
775
|
* ```js
|
|
709
|
-
* const util = require('util');
|
|
776
|
+
* const util = require('node:util');
|
|
710
777
|
*
|
|
711
778
|
* util.isPrimitive(5);
|
|
712
779
|
* // Returns: true
|
|
@@ -735,7 +802,7 @@ declare module 'util' {
|
|
|
735
802
|
* Returns `true` if the given `object` is a `string`. Otherwise, returns `false`.
|
|
736
803
|
*
|
|
737
804
|
* ```js
|
|
738
|
-
* const util = require('util');
|
|
805
|
+
* const util = require('node:util');
|
|
739
806
|
*
|
|
740
807
|
* util.isString('');
|
|
741
808
|
* // Returns: true
|
|
@@ -754,7 +821,7 @@ declare module 'util' {
|
|
|
754
821
|
* Returns `true` if the given `object` is a `Symbol`. Otherwise, returns `false`.
|
|
755
822
|
*
|
|
756
823
|
* ```js
|
|
757
|
-
* const util = require('util');
|
|
824
|
+
* const util = require('node:util');
|
|
758
825
|
*
|
|
759
826
|
* util.isSymbol(5);
|
|
760
827
|
* // Returns: false
|
|
@@ -771,7 +838,7 @@ declare module 'util' {
|
|
|
771
838
|
* Returns `true` if the given `object` is `undefined`. Otherwise, returns `false`.
|
|
772
839
|
*
|
|
773
840
|
* ```js
|
|
774
|
-
* const util = require('util');
|
|
841
|
+
* const util = require('node:util');
|
|
775
842
|
*
|
|
776
843
|
* const foo = undefined;
|
|
777
844
|
* util.isUndefined(5);
|
|
@@ -790,7 +857,7 @@ declare module 'util' {
|
|
|
790
857
|
* such a way that it is marked as deprecated.
|
|
791
858
|
*
|
|
792
859
|
* ```js
|
|
793
|
-
* const util = require('util');
|
|
860
|
+
* const util = require('node:util');
|
|
794
861
|
*
|
|
795
862
|
* exports.obsoleteFunction = util.deprecate(() => {
|
|
796
863
|
* // Do something here.
|
|
@@ -806,7 +873,7 @@ declare module 'util' {
|
|
|
806
873
|
* the warning will be emitted only once for that `code`.
|
|
807
874
|
*
|
|
808
875
|
* ```js
|
|
809
|
-
* const util = require('util');
|
|
876
|
+
* const util = require('node:util');
|
|
810
877
|
*
|
|
811
878
|
* const fn1 = util.deprecate(someFunction, someMessage, 'DEP0001');
|
|
812
879
|
* const fn2 = util.deprecate(someOtherFunction, someOtherMessage, 'DEP0001');
|
|
@@ -860,7 +927,7 @@ declare module 'util' {
|
|
|
860
927
|
* first argument will be the rejection reason (or `null` if the `Promise`resolved), and the second argument will be the resolved value.
|
|
861
928
|
*
|
|
862
929
|
* ```js
|
|
863
|
-
* const util = require('util');
|
|
930
|
+
* const util = require('node:util');
|
|
864
931
|
*
|
|
865
932
|
* async function fn() {
|
|
866
933
|
* return 'hello world';
|
|
@@ -899,7 +966,7 @@ declare module 'util' {
|
|
|
899
966
|
* });
|
|
900
967
|
* ```
|
|
901
968
|
* @since v8.2.0
|
|
902
|
-
* @param
|
|
969
|
+
* @param fn An `async` function
|
|
903
970
|
* @return a callback style function
|
|
904
971
|
*/
|
|
905
972
|
export function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
|
|
@@ -943,8 +1010,8 @@ declare module 'util' {
|
|
|
943
1010
|
* that returns promises.
|
|
944
1011
|
*
|
|
945
1012
|
* ```js
|
|
946
|
-
* const util = require('util');
|
|
947
|
-
* const fs = require('fs');
|
|
1013
|
+
* const util = require('node:util');
|
|
1014
|
+
* const fs = require('node:fs');
|
|
948
1015
|
*
|
|
949
1016
|
* const stat = util.promisify(fs.stat);
|
|
950
1017
|
* stat('.').then((stats) => {
|
|
@@ -957,8 +1024,8 @@ declare module 'util' {
|
|
|
957
1024
|
* Or, equivalently using `async function`s:
|
|
958
1025
|
*
|
|
959
1026
|
* ```js
|
|
960
|
-
* const util = require('util');
|
|
961
|
-
* const fs = require('fs');
|
|
1027
|
+
* const util = require('node:util');
|
|
1028
|
+
* const fs = require('node:fs');
|
|
962
1029
|
*
|
|
963
1030
|
* const stat = util.promisify(fs.stat);
|
|
964
1031
|
*
|
|
@@ -979,7 +1046,7 @@ declare module 'util' {
|
|
|
979
1046
|
* work as expected unless handled specially:
|
|
980
1047
|
*
|
|
981
1048
|
* ```js
|
|
982
|
-
* const util = require('util');
|
|
1049
|
+
* const util = require('node:util');
|
|
983
1050
|
*
|
|
984
1051
|
* class Foo {
|
|
985
1052
|
* constructor() {
|
|
@@ -1068,7 +1135,7 @@ declare module 'util' {
|
|
|
1068
1135
|
* internally and emitted after the next call to `textDecoder.decode()`.
|
|
1069
1136
|
*
|
|
1070
1137
|
* If `textDecoder.fatal` is `true`, decoding errors that occur will result in a`TypeError` being thrown.
|
|
1071
|
-
* @param input An `ArrayBuffer`, `DataView
|
|
1138
|
+
* @param input An `ArrayBuffer`, `DataView`, or `TypedArray` instance containing the encoded data.
|
|
1072
1139
|
*/
|
|
1073
1140
|
decode(
|
|
1074
1141
|
input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
|
|
@@ -1128,7 +1195,6 @@ declare module 'util' {
|
|
|
1128
1195
|
*/
|
|
1129
1196
|
encodeInto(src: string, dest: Uint8Array): EncodeIntoResult;
|
|
1130
1197
|
}
|
|
1131
|
-
|
|
1132
1198
|
import { TextDecoder as _TextDecoder, TextEncoder as _TextEncoder } from 'util';
|
|
1133
1199
|
global {
|
|
1134
1200
|
/**
|
|
@@ -1136,19 +1202,18 @@ declare module 'util' {
|
|
|
1136
1202
|
* https://nodejs.org/api/globals.html#textdecoder
|
|
1137
1203
|
* @since v11.0.0
|
|
1138
1204
|
*/
|
|
1139
|
-
|
|
1205
|
+
var TextDecoder: typeof globalThis extends {
|
|
1140
1206
|
onmessage: any;
|
|
1141
1207
|
TextDecoder: infer TextDecoder;
|
|
1142
1208
|
}
|
|
1143
1209
|
? TextDecoder
|
|
1144
1210
|
: typeof _TextDecoder;
|
|
1145
|
-
|
|
1146
1211
|
/**
|
|
1147
1212
|
* `TextEncoder` class is a global reference for `require('util').TextEncoder`
|
|
1148
1213
|
* https://nodejs.org/api/globals.html#textencoder
|
|
1149
1214
|
* @since v11.0.0
|
|
1150
1215
|
*/
|
|
1151
|
-
|
|
1216
|
+
var TextEncoder: typeof globalThis extends {
|
|
1152
1217
|
onmessage: any;
|
|
1153
1218
|
TextEncoder: infer TextEncoder;
|
|
1154
1219
|
}
|
|
@@ -1158,70 +1223,87 @@ declare module 'util' {
|
|
|
1158
1223
|
|
|
1159
1224
|
//// parseArgs
|
|
1160
1225
|
/**
|
|
1161
|
-
* Provides a
|
|
1162
|
-
* specification for the expected arguments
|
|
1163
|
-
* with the parsed
|
|
1164
|
-
*
|
|
1165
|
-
*
|
|
1166
|
-
*
|
|
1167
|
-
*
|
|
1168
|
-
*
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1171
|
-
*
|
|
1172
|
-
*
|
|
1173
|
-
*
|
|
1174
|
-
*
|
|
1175
|
-
*
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1184
|
-
*
|
|
1185
|
-
*
|
|
1186
|
-
*
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
* for extending the built-in behavior, from adding additional checks through
|
|
1190
|
-
* to reprocessing the tokens in different ways.
|
|
1191
|
-
* **Default:** `false`.
|
|
1192
|
-
*
|
|
1193
|
-
* @returns The parsed command line arguments:
|
|
1194
|
-
*
|
|
1195
|
-
* - `values` A mapping of parsed option names with their string
|
|
1196
|
-
* or boolean values.
|
|
1197
|
-
* - `positionals` Positional arguments.
|
|
1198
|
-
* - `tokens` Detailed parse information (only if `tokens` was specified).
|
|
1199
|
-
*
|
|
1200
|
-
*/
|
|
1201
|
-
export function parseArgs<T extends ParseArgsConfig>(config: T): ParsedResults<T>;
|
|
1202
|
-
|
|
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:
|
|
1252
|
+
*/
|
|
1253
|
+
export function parseArgs<T extends ParseArgsConfig>(config?: T): ParsedResults<T>;
|
|
1203
1254
|
interface ParseArgsOptionConfig {
|
|
1255
|
+
/**
|
|
1256
|
+
* Type of argument.
|
|
1257
|
+
*/
|
|
1204
1258
|
type: 'string' | 'boolean';
|
|
1205
|
-
short?: string;
|
|
1206
|
-
multiple?: boolean;
|
|
1207
1259
|
/**
|
|
1260
|
+
* Whether this option can be provided multiple times.
|
|
1261
|
+
* If `true`, all values will be collected in an array.
|
|
1262
|
+
* If `false`, values for the option are last-wins.
|
|
1263
|
+
* @default false.
|
|
1264
|
+
*/
|
|
1265
|
+
multiple?: boolean | undefined;
|
|
1266
|
+
/**
|
|
1267
|
+
* A single character alias for the option.
|
|
1268
|
+
*/
|
|
1269
|
+
short?: string | undefined;
|
|
1270
|
+
/**
|
|
1271
|
+
* The default option value when it is not set by args.
|
|
1272
|
+
* It must be of the same type as the the `type` property.
|
|
1273
|
+
* When `multiple` is `true`, it must be an array.
|
|
1208
1274
|
* @since v18.11.0
|
|
1209
1275
|
*/
|
|
1210
|
-
default?: string | boolean | string[] | boolean[];
|
|
1276
|
+
default?: string | boolean | string[] | boolean[] | undefined;
|
|
1211
1277
|
}
|
|
1212
|
-
|
|
1213
1278
|
interface ParseArgsOptionsConfig {
|
|
1214
1279
|
[longOption: string]: ParseArgsOptionConfig;
|
|
1215
1280
|
}
|
|
1216
|
-
|
|
1217
1281
|
export interface ParseArgsConfig {
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1282
|
+
/**
|
|
1283
|
+
* Array of argument strings.
|
|
1284
|
+
*/
|
|
1285
|
+
args?: string[] | undefined;
|
|
1286
|
+
/**
|
|
1287
|
+
* Used to describe arguments known to the parser.
|
|
1288
|
+
*/
|
|
1289
|
+
options?: ParseArgsOptionsConfig | undefined;
|
|
1290
|
+
/**
|
|
1291
|
+
* Should an error be thrown when unknown arguments are encountered,
|
|
1292
|
+
* or when arguments are passed that do not match the `type` configured in `options`.
|
|
1293
|
+
* @default true
|
|
1294
|
+
*/
|
|
1295
|
+
strict?: boolean | undefined;
|
|
1296
|
+
/**
|
|
1297
|
+
* Whether this command accepts positional arguments.
|
|
1298
|
+
*/
|
|
1299
|
+
allowPositionals?: boolean | undefined;
|
|
1300
|
+
/**
|
|
1301
|
+
* Return the parsed tokens. This is useful for extending the built-in behavior,
|
|
1302
|
+
* from adding additional checks through to reprocessing the tokens in different ways.
|
|
1303
|
+
* @default false
|
|
1304
|
+
*/
|
|
1305
|
+
tokens?: boolean | undefined;
|
|
1223
1306
|
}
|
|
1224
|
-
|
|
1225
1307
|
/*
|
|
1226
1308
|
IfDefaultsTrue and IfDefaultsFalse are helpers to handle default values for missing boolean properties.
|
|
1227
1309
|
TypeScript does not have exact types for objects: https://github.com/microsoft/TypeScript/issues/12936
|
|
@@ -1345,11 +1427,103 @@ declare module 'util' {
|
|
|
1345
1427
|
// So we can't rely on the `"not definitely present" implies "definitely not present"` assumption mentioned above.
|
|
1346
1428
|
type ParsedResults<T extends ParseArgsConfig> = ParseArgsConfig extends T
|
|
1347
1429
|
? {
|
|
1348
|
-
values: {
|
|
1430
|
+
values: {
|
|
1431
|
+
[longOption: string]: undefined | string | boolean | Array<string | boolean>;
|
|
1432
|
+
};
|
|
1349
1433
|
positionals: string[];
|
|
1350
1434
|
tokens?: Token[];
|
|
1351
1435
|
}
|
|
1352
1436
|
: PreciseParsedResults<T>;
|
|
1437
|
+
|
|
1438
|
+
/**
|
|
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
|
|
1450
|
+
*/
|
|
1451
|
+
export class MIMEType {
|
|
1452
|
+
/**
|
|
1453
|
+
* Creates a new MIMEType object by parsing the input.
|
|
1454
|
+
*
|
|
1455
|
+
* A `TypeError` will be thrown if the `input` is not a valid MIME.
|
|
1456
|
+
* Note that an effort will be made to coerce the given values into strings.
|
|
1457
|
+
* @param input The input MIME to parse.
|
|
1458
|
+
*/
|
|
1459
|
+
constructor(input: string | { toString: () => string });
|
|
1460
|
+
|
|
1461
|
+
/**
|
|
1462
|
+
* Gets and sets the type portion of the MIME.
|
|
1463
|
+
*/
|
|
1464
|
+
type: string;
|
|
1465
|
+
/**
|
|
1466
|
+
* Gets and sets the subtype portion of the MIME.
|
|
1467
|
+
*/
|
|
1468
|
+
subtype: string;
|
|
1469
|
+
/**
|
|
1470
|
+
* Gets the essence of the MIME.
|
|
1471
|
+
*
|
|
1472
|
+
* Use `mime.type` or `mime.subtype` to alter the MIME.
|
|
1473
|
+
*/
|
|
1474
|
+
readonly essence: string;
|
|
1475
|
+
/**
|
|
1476
|
+
* Gets the `MIMEParams` object representing the parameters of the MIME.
|
|
1477
|
+
*/
|
|
1478
|
+
readonly params: MIMEParams;
|
|
1479
|
+
/**
|
|
1480
|
+
* Returns the serialized MIME.
|
|
1481
|
+
*
|
|
1482
|
+
* Because of the need for standard compliance, this method
|
|
1483
|
+
* does not allow users to customize the serialization process of the MIME.
|
|
1484
|
+
*/
|
|
1485
|
+
toString(): string;
|
|
1486
|
+
}
|
|
1487
|
+
/**
|
|
1488
|
+
* @since v18.13.0
|
|
1489
|
+
*/
|
|
1490
|
+
export class MIMEParams {
|
|
1491
|
+
/**
|
|
1492
|
+
* Remove all name-value pairs whose name is `name`.
|
|
1493
|
+
*/
|
|
1494
|
+
delete(name: string): void;
|
|
1495
|
+
/**
|
|
1496
|
+
* Returns an iterator over each of the name-value pairs in the parameters.
|
|
1497
|
+
*/
|
|
1498
|
+
entries(): IterableIterator<[string, string]>;
|
|
1499
|
+
/**
|
|
1500
|
+
* Returns the value of the first name-value pair whose name is `name`.
|
|
1501
|
+
* If there are no such pairs, `null` is returned.
|
|
1502
|
+
*/
|
|
1503
|
+
get(name: string): string | null;
|
|
1504
|
+
/**
|
|
1505
|
+
* Returns `true` if there is at least one name-value pair whose name is `name`.
|
|
1506
|
+
*/
|
|
1507
|
+
has(name: string): boolean;
|
|
1508
|
+
/**
|
|
1509
|
+
* Returns an iterator over the names of each name-value pair.
|
|
1510
|
+
*/
|
|
1511
|
+
keys(): IterableIterator<string>;
|
|
1512
|
+
/**
|
|
1513
|
+
* Sets the value in the `MIMEParams` object associated with `name` to `value`.
|
|
1514
|
+
* If there are any pre-existing name-value pairs whose names are `name`,
|
|
1515
|
+
* set the first such pair's value to `value`.
|
|
1516
|
+
*/
|
|
1517
|
+
set(name: string, value: string): void;
|
|
1518
|
+
/**
|
|
1519
|
+
* Returns an iterator over the values of each name-value pair.
|
|
1520
|
+
*/
|
|
1521
|
+
values(): IterableIterator<string>;
|
|
1522
|
+
/**
|
|
1523
|
+
* Returns an iterator over each of the name-value pairs in the parameters.
|
|
1524
|
+
*/
|
|
1525
|
+
[Symbol.iterator]: typeof MIMEParams.prototype.entries;
|
|
1526
|
+
}
|
|
1353
1527
|
}
|
|
1354
1528
|
declare module 'util/types' {
|
|
1355
1529
|
export * from 'util/types';
|
|
@@ -1647,12 +1821,40 @@ declare module 'util/types' {
|
|
|
1647
1821
|
*/
|
|
1648
1822
|
function isModuleNamespaceObject(value: unknown): boolean;
|
|
1649
1823
|
/**
|
|
1650
|
-
* 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:
|
|
1651
1853
|
*
|
|
1652
1854
|
* ```js
|
|
1653
|
-
*
|
|
1654
|
-
* util.types.isNativeError(
|
|
1655
|
-
*
|
|
1855
|
+
* const myError = { __proto__: Error.prototype };
|
|
1856
|
+
* console.log(util.types.isNativeError(myError)); // false
|
|
1857
|
+
* console.log(myError instanceof Error); // true
|
|
1656
1858
|
* ```
|
|
1657
1859
|
* @since v10.0.0
|
|
1658
1860
|
*/
|