@types/node 18.7.17 → 18.7.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. node/README.md +1 -1
  2. node/globals.d.ts +1 -0
  3. node/index.d.ts +1 -1
  4. node/package.json +9 -2
  5. node/path.d.ts +2 -2
  6. node/ts4.8/assert/strict.d.ts +8 -0
  7. node/ts4.8/assert.d.ts +911 -0
  8. node/ts4.8/async_hooks.d.ts +501 -0
  9. node/ts4.8/buffer.d.ts +2238 -0
  10. node/ts4.8/child_process.d.ts +1369 -0
  11. node/ts4.8/cluster.d.ts +410 -0
  12. node/ts4.8/console.d.ts +412 -0
  13. node/ts4.8/constants.d.ts +18 -0
  14. node/ts4.8/crypto.d.ts +3961 -0
  15. node/ts4.8/dgram.d.ts +545 -0
  16. node/ts4.8/diagnostics_channel.d.ts +153 -0
  17. node/ts4.8/dns/promises.d.ts +370 -0
  18. node/ts4.8/dns.d.ts +659 -0
  19. node/ts4.8/domain.d.ts +170 -0
  20. node/ts4.8/events.d.ts +641 -0
  21. node/ts4.8/fs/promises.d.ts +1120 -0
  22. node/ts4.8/fs.d.ts +3872 -0
  23. node/ts4.8/globals.d.ts +294 -0
  24. node/ts4.8/globals.global.d.ts +1 -0
  25. node/ts4.8/http.d.ts +1553 -0
  26. node/ts4.8/http2.d.ts +2106 -0
  27. node/ts4.8/https.d.ts +541 -0
  28. node/ts4.8/index.d.ts +87 -0
  29. node/ts4.8/inspector.d.ts +2741 -0
  30. node/ts4.8/module.d.ts +114 -0
  31. node/ts4.8/net.d.ts +838 -0
  32. node/ts4.8/os.d.ts +465 -0
  33. node/ts4.8/path.d.ts +191 -0
  34. node/ts4.8/perf_hooks.d.ts +610 -0
  35. node/ts4.8/process.d.ts +1482 -0
  36. node/ts4.8/punycode.d.ts +117 -0
  37. node/ts4.8/querystring.d.ts +131 -0
  38. node/ts4.8/readline/promises.d.ts +143 -0
  39. node/ts4.8/readline.d.ts +653 -0
  40. node/ts4.8/repl.d.ts +424 -0
  41. node/ts4.8/stream/consumers.d.ts +24 -0
  42. node/ts4.8/stream/promises.d.ts +42 -0
  43. node/ts4.8/stream/web.d.ts +330 -0
  44. node/ts4.8/stream.d.ts +1339 -0
  45. node/ts4.8/string_decoder.d.ts +67 -0
  46. node/ts4.8/test.d.ts +190 -0
  47. node/ts4.8/timers/promises.d.ts +68 -0
  48. node/ts4.8/timers.d.ts +94 -0
  49. node/ts4.8/tls.d.ts +1028 -0
  50. node/ts4.8/trace_events.d.ts +171 -0
  51. node/ts4.8/tty.d.ts +206 -0
  52. node/ts4.8/url.d.ts +897 -0
  53. node/ts4.8/util.d.ts +1792 -0
  54. node/ts4.8/v8.d.ts +396 -0
  55. node/ts4.8/vm.d.ts +509 -0
  56. node/ts4.8/wasi.d.ts +158 -0
  57. node/ts4.8/worker_threads.d.ts +646 -0
  58. node/ts4.8/zlib.d.ts +517 -0
node/ts4.8/util.d.ts ADDED
@@ -0,0 +1,1792 @@
1
+ /**
2
+ * The `util` module supports the needs of Node.js internal APIs. Many of the
3
+ * utilities are useful for application and module developers as well. To access
4
+ * it:
5
+ *
6
+ * ```js
7
+ * const util = require('util');
8
+ * ```
9
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/util.js)
10
+ */
11
+ declare module 'util' {
12
+ import * as types from 'node:util/types';
13
+ export interface InspectOptions {
14
+ /**
15
+ * If set to `true`, getters are going to be
16
+ * inspected as well. If set to `'get'` only getters without setter are going
17
+ * to be inspected. If set to `'set'` only getters having a corresponding
18
+ * setter are going to be inspected. This might cause side effects depending on
19
+ * the getter function.
20
+ * @default `false`
21
+ */
22
+ getters?: 'get' | 'set' | boolean | undefined;
23
+ showHidden?: boolean | undefined;
24
+ /**
25
+ * @default 2
26
+ */
27
+ depth?: number | null | undefined;
28
+ colors?: boolean | undefined;
29
+ customInspect?: boolean | undefined;
30
+ showProxy?: boolean | undefined;
31
+ maxArrayLength?: number | null | undefined;
32
+ /**
33
+ * Specifies the maximum number of characters to
34
+ * include when formatting. Set to `null` or `Infinity` to show all elements.
35
+ * Set to `0` or negative to show no characters.
36
+ * @default 10000
37
+ */
38
+ maxStringLength?: number | null | undefined;
39
+ breakLength?: number | undefined;
40
+ /**
41
+ * Setting this to `false` causes each object key
42
+ * to be displayed on a new line. It will also add new lines to text that is
43
+ * longer than `breakLength`. If set to a number, the most `n` inner elements
44
+ * are united on a single line as long as all properties fit into
45
+ * `breakLength`. Short array elements are also grouped together. Note that no
46
+ * text will be reduced below 16 characters, no matter the `breakLength` size.
47
+ * For more information, see the example below.
48
+ * @default `true`
49
+ */
50
+ compact?: boolean | number | undefined;
51
+ sorted?: boolean | ((a: string, b: string) => number) | undefined;
52
+ }
53
+ export type Style = 'special' | 'number' | 'bigint' | 'boolean' | 'undefined' | 'null' | 'string' | 'symbol' | 'date' | 'regexp' | 'module';
54
+ export type CustomInspectFunction = (depth: number, options: InspectOptionsStylized) => string;
55
+ export interface InspectOptionsStylized extends InspectOptions {
56
+ stylize(text: string, styleType: Style): string;
57
+ }
58
+ /**
59
+ * The `util.format()` method returns a formatted string using the first argument
60
+ * as a `printf`\-like format string which can contain zero or more format
61
+ * specifiers. Each specifier is replaced with the converted value from the
62
+ * corresponding argument. Supported specifiers are:
63
+ *
64
+ * If a specifier does not have a corresponding argument, it is not replaced:
65
+ *
66
+ * ```js
67
+ * util.format('%s:%s', 'foo');
68
+ * // Returns: 'foo:%s'
69
+ * ```
70
+ *
71
+ * Values that are not part of the format string are formatted using`util.inspect()` if their type is not `string`.
72
+ *
73
+ * If there are more arguments passed to the `util.format()` method than the
74
+ * number of specifiers, the extra arguments are concatenated to the returned
75
+ * string, separated by spaces:
76
+ *
77
+ * ```js
78
+ * util.format('%s:%s', 'foo', 'bar', 'baz');
79
+ * // Returns: 'foo:bar baz'
80
+ * ```
81
+ *
82
+ * If the first argument does not contain a valid format specifier, `util.format()`returns a string that is the concatenation of all arguments separated by spaces:
83
+ *
84
+ * ```js
85
+ * util.format(1, 2, 3);
86
+ * // Returns: '1 2 3'
87
+ * ```
88
+ *
89
+ * If only one argument is passed to `util.format()`, it is returned as it is
90
+ * without any formatting:
91
+ *
92
+ * ```js
93
+ * util.format('%% %s');
94
+ * // Returns: '%% %s'
95
+ * ```
96
+ *
97
+ * `util.format()` is a synchronous method that is intended as a debugging tool.
98
+ * Some input values can have a significant performance overhead that can block the
99
+ * event loop. Use this function with care and never in a hot code path.
100
+ * @since v0.5.3
101
+ * @param format A `printf`-like format string.
102
+ */
103
+ export function format(format?: any, ...param: any[]): string;
104
+ /**
105
+ * This function is identical to {@link format}, except in that it takes
106
+ * an `inspectOptions` argument which specifies options that are passed along to {@link inspect}.
107
+ *
108
+ * ```js
109
+ * util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 });
110
+ * // Returns 'See object { foo: 42 }', where `42` is colored as a number
111
+ * // when printed to a terminal.
112
+ * ```
113
+ * @since v10.0.0
114
+ */
115
+ export function formatWithOptions(inspectOptions: InspectOptions, format?: any, ...param: any[]): string;
116
+ /**
117
+ * Returns the string name for a numeric error code that comes from a Node.js API.
118
+ * The mapping between error codes and error names is platform-dependent.
119
+ * See `Common System Errors` for the names of common errors.
120
+ *
121
+ * ```js
122
+ * fs.access('file/that/does/not/exist', (err) => {
123
+ * const name = util.getSystemErrorName(err.errno);
124
+ * console.error(name); // ENOENT
125
+ * });
126
+ * ```
127
+ * @since v9.7.0
128
+ */
129
+ export function getSystemErrorName(err: number): string;
130
+ /**
131
+ * Returns a Map of all system error codes available from the Node.js API.
132
+ * The mapping between error codes and error names is platform-dependent.
133
+ * See `Common System Errors` for the names of common errors.
134
+ *
135
+ * ```js
136
+ * fs.access('file/that/does/not/exist', (err) => {
137
+ * const errorMap = util.getSystemErrorMap();
138
+ * const name = errorMap.get(err.errno);
139
+ * console.error(name); // ENOENT
140
+ * });
141
+ * ```
142
+ * @since v16.0.0, v14.17.0
143
+ */
144
+ export function getSystemErrorMap(): Map<number, [string, string]>;
145
+ /**
146
+ * The `util.log()` method prints the given `string` to `stdout` with an included
147
+ * timestamp.
148
+ *
149
+ * ```js
150
+ * const util = require('util');
151
+ *
152
+ * util.log('Timestamped message.');
153
+ * ```
154
+ * @since v0.3.0
155
+ * @deprecated Since v6.0.0 - Use a third party module instead.
156
+ */
157
+ export function log(string: string): void;
158
+ /**
159
+ * Returns the `string` after replacing any surrogate code points
160
+ * (or equivalently, any unpaired surrogate code units) with the
161
+ * Unicode "replacement character" U+FFFD.
162
+ * @since v16.8.0, v14.18.0
163
+ */
164
+ export function toUSVString(string: string): string;
165
+ /**
166
+ * The `util.inspect()` method returns a string representation of `object` that is
167
+ * intended for debugging. The output of `util.inspect` may change at any time
168
+ * and should not be depended upon programmatically. Additional `options` may be
169
+ * passed that alter the result.`util.inspect()` will use the constructor's name and/or `@@toStringTag` to make
170
+ * an identifiable tag for an inspected value.
171
+ *
172
+ * ```js
173
+ * class Foo {
174
+ * get [Symbol.toStringTag]() {
175
+ * return 'bar';
176
+ * }
177
+ * }
178
+ *
179
+ * class Bar {}
180
+ *
181
+ * const baz = Object.create(null, { [Symbol.toStringTag]: { value: 'foo' } });
182
+ *
183
+ * util.inspect(new Foo()); // 'Foo [bar] {}'
184
+ * util.inspect(new Bar()); // 'Bar {}'
185
+ * util.inspect(baz); // '[foo] {}'
186
+ * ```
187
+ *
188
+ * Circular references point to their anchor by using a reference index:
189
+ *
190
+ * ```js
191
+ * const { inspect } = require('util');
192
+ *
193
+ * const obj = {};
194
+ * obj.a = [obj];
195
+ * obj.b = {};
196
+ * obj.b.inner = obj.b;
197
+ * obj.b.obj = obj;
198
+ *
199
+ * console.log(inspect(obj));
200
+ * // <ref *1> {
201
+ * // a: [ [Circular *1] ],
202
+ * // b: <ref *2> { inner: [Circular *2], obj: [Circular *1] }
203
+ * // }
204
+ * ```
205
+ *
206
+ * The following example inspects all properties of the `util` object:
207
+ *
208
+ * ```js
209
+ * const util = require('util');
210
+ *
211
+ * console.log(util.inspect(util, { showHidden: true, depth: null }));
212
+ * ```
213
+ *
214
+ * The following example highlights the effect of the `compact` option:
215
+ *
216
+ * ```js
217
+ * const util = require('util');
218
+ *
219
+ * const o = {
220
+ * a: [1, 2, [[
221
+ * 'Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit, sed do ' +
222
+ * 'eiusmod \ntempor incididunt ut labore et dolore magna aliqua.',
223
+ * 'test',
224
+ * 'foo']], 4],
225
+ * b: new Map([['za', 1], ['zb', 'test']])
226
+ * };
227
+ * console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));
228
+ *
229
+ * // { a:
230
+ * // [ 1,
231
+ * // 2,
232
+ * // [ [ 'Lorem ipsum dolor sit amet,\nconsectetur [...]', // A long line
233
+ * // 'test',
234
+ * // 'foo' ] ],
235
+ * // 4 ],
236
+ * // b: Map(2) { 'za' => 1, 'zb' => 'test' } }
237
+ *
238
+ * // Setting `compact` to false or an integer creates more reader friendly output.
239
+ * console.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 }));
240
+ *
241
+ * // {
242
+ * // a: [
243
+ * // 1,
244
+ * // 2,
245
+ * // [
246
+ * // [
247
+ * // 'Lorem ipsum dolor sit amet,\n' +
248
+ * // 'consectetur adipiscing elit, sed do eiusmod \n' +
249
+ * // 'tempor incididunt ut labore et dolore magna aliqua.',
250
+ * // 'test',
251
+ * // 'foo'
252
+ * // ]
253
+ * // ],
254
+ * // 4
255
+ * // ],
256
+ * // b: Map(2) {
257
+ * // 'za' => 1,
258
+ * // 'zb' => 'test'
259
+ * // }
260
+ * // }
261
+ *
262
+ * // Setting `breakLength` to e.g. 150 will print the "Lorem ipsum" text in a
263
+ * // single line.
264
+ * ```
265
+ *
266
+ * The `showHidden` option allows [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) and
267
+ * [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) entries to be
268
+ * inspected. If there are more entries than `maxArrayLength`, there is no
269
+ * guarantee which entries are displayed. That means retrieving the same [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) entries twice may
270
+ * result in different output. Furthermore, entries
271
+ * with no remaining strong references may be garbage collected at any time.
272
+ *
273
+ * ```js
274
+ * const { inspect } = require('util');
275
+ *
276
+ * const obj = { a: 1 };
277
+ * const obj2 = { b: 2 };
278
+ * const weakSet = new WeakSet([obj, obj2]);
279
+ *
280
+ * console.log(inspect(weakSet, { showHidden: true }));
281
+ * // WeakSet { { a: 1 }, { b: 2 } }
282
+ * ```
283
+ *
284
+ * The `sorted` option ensures that an object's property insertion order does not
285
+ * impact the result of `util.inspect()`.
286
+ *
287
+ * ```js
288
+ * const { inspect } = require('util');
289
+ * const assert = require('assert');
290
+ *
291
+ * const o1 = {
292
+ * b: [2, 3, 1],
293
+ * a: '`a` comes before `b`',
294
+ * c: new Set([2, 3, 1])
295
+ * };
296
+ * console.log(inspect(o1, { sorted: true }));
297
+ * // { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set(3) { 1, 2, 3 } }
298
+ * console.log(inspect(o1, { sorted: (a, b) => b.localeCompare(a) }));
299
+ * // { c: Set(3) { 3, 2, 1 }, b: [ 2, 3, 1 ], a: '`a` comes before `b`' }
300
+ *
301
+ * const o2 = {
302
+ * c: new Set([2, 1, 3]),
303
+ * a: '`a` comes before `b`',
304
+ * b: [2, 3, 1]
305
+ * };
306
+ * assert.strict.equal(
307
+ * inspect(o1, { sorted: true }),
308
+ * inspect(o2, { sorted: true })
309
+ * );
310
+ * ```
311
+ *
312
+ * The `numericSeparator` option adds an underscore every three digits to all
313
+ * numbers.
314
+ *
315
+ * ```js
316
+ * const { inspect } = require('util');
317
+ *
318
+ * const thousand = 1_000;
319
+ * const million = 1_000_000;
320
+ * const bigNumber = 123_456_789n;
321
+ * const bigDecimal = 1_234.123_45;
322
+ *
323
+ * console.log(thousand, million, bigNumber, bigDecimal);
324
+ * // 1_000 1_000_000 123_456_789n 1_234.123_45
325
+ * ```
326
+ *
327
+ * `util.inspect()` is a synchronous method intended for debugging. Its maximum
328
+ * output length is approximately 128 MB. Inputs that result in longer output will
329
+ * be truncated.
330
+ * @since v0.3.0
331
+ * @param object Any JavaScript primitive or `Object`.
332
+ * @return The representation of `object`.
333
+ */
334
+ export function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
335
+ export function inspect(object: any, options?: InspectOptions): string;
336
+ export namespace inspect {
337
+ let colors: NodeJS.Dict<[number, number]>;
338
+ let styles: {
339
+ [K in Style]: string;
340
+ };
341
+ let defaultOptions: InspectOptions;
342
+ /**
343
+ * Allows changing inspect settings from the repl.
344
+ */
345
+ let replDefaults: InspectOptions;
346
+ /**
347
+ * That can be used to declare custom inspect functions.
348
+ */
349
+ const custom: unique symbol;
350
+ }
351
+ /**
352
+ * Alias for [`Array.isArray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray).
353
+ *
354
+ * Returns `true` if the given `object` is an `Array`. Otherwise, returns `false`.
355
+ *
356
+ * ```js
357
+ * const util = require('util');
358
+ *
359
+ * util.isArray([]);
360
+ * // Returns: true
361
+ * util.isArray(new Array());
362
+ * // Returns: true
363
+ * util.isArray({});
364
+ * // Returns: false
365
+ * ```
366
+ * @since v0.6.0
367
+ * @deprecated Since v4.0.0 - Use `isArray` instead.
368
+ */
369
+ export function isArray(object: unknown): object is unknown[];
370
+ /**
371
+ * Returns `true` if the given `object` is a `RegExp`. Otherwise, returns `false`.
372
+ *
373
+ * ```js
374
+ * const util = require('util');
375
+ *
376
+ * util.isRegExp(/some regexp/);
377
+ * // Returns: true
378
+ * util.isRegExp(new RegExp('another regexp'));
379
+ * // Returns: true
380
+ * util.isRegExp({});
381
+ * // Returns: false
382
+ * ```
383
+ * @since v0.6.0
384
+ * @deprecated Since v4.0.0 - Deprecated
385
+ */
386
+ export function isRegExp(object: unknown): object is RegExp;
387
+ /**
388
+ * Returns `true` if the given `object` is a `Date`. Otherwise, returns `false`.
389
+ *
390
+ * ```js
391
+ * const util = require('util');
392
+ *
393
+ * util.isDate(new Date());
394
+ * // Returns: true
395
+ * util.isDate(Date());
396
+ * // false (without 'new' returns a String)
397
+ * util.isDate({});
398
+ * // Returns: false
399
+ * ```
400
+ * @since v0.6.0
401
+ * @deprecated Since v4.0.0 - Use {@link types.isDate} instead.
402
+ */
403
+ export function isDate(object: unknown): object is Date;
404
+ /**
405
+ * Returns `true` if the given `object` is an `Error`. Otherwise, returns`false`.
406
+ *
407
+ * ```js
408
+ * const util = require('util');
409
+ *
410
+ * util.isError(new Error());
411
+ * // Returns: true
412
+ * util.isError(new TypeError());
413
+ * // Returns: true
414
+ * util.isError({ name: 'Error', message: 'an error occurred' });
415
+ * // Returns: false
416
+ * ```
417
+ *
418
+ * This method relies on `Object.prototype.toString()` behavior. It is
419
+ * possible to obtain an incorrect result when the `object` argument manipulates`@@toStringTag`.
420
+ *
421
+ * ```js
422
+ * const util = require('util');
423
+ * const obj = { name: 'Error', message: 'an error occurred' };
424
+ *
425
+ * util.isError(obj);
426
+ * // Returns: false
427
+ * obj[Symbol.toStringTag] = 'Error';
428
+ * util.isError(obj);
429
+ * // Returns: true
430
+ * ```
431
+ * @since v0.6.0
432
+ * @deprecated Since v4.0.0 - Use {@link types.isNativeError} instead.
433
+ */
434
+ export function isError(object: unknown): object is Error;
435
+ /**
436
+ * Usage of `util.inherits()` is discouraged. Please use the ES6 `class` and`extends` keywords to get language level inheritance support. Also note
437
+ * that the two styles are [semantically incompatible](https://github.com/nodejs/node/issues/4179).
438
+ *
439
+ * Inherit the prototype methods from one [constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor) into another. The
440
+ * prototype of `constructor` will be set to a new object created from`superConstructor`.
441
+ *
442
+ * This mainly adds some input validation on top of`Object.setPrototypeOf(constructor.prototype, superConstructor.prototype)`.
443
+ * As an additional convenience, `superConstructor` will be accessible
444
+ * through the `constructor.super_` property.
445
+ *
446
+ * ```js
447
+ * const util = require('util');
448
+ * const EventEmitter = require('events');
449
+ *
450
+ * function MyStream() {
451
+ * EventEmitter.call(this);
452
+ * }
453
+ *
454
+ * util.inherits(MyStream, EventEmitter);
455
+ *
456
+ * MyStream.prototype.write = function(data) {
457
+ * this.emit('data', data);
458
+ * };
459
+ *
460
+ * const stream = new MyStream();
461
+ *
462
+ * console.log(stream instanceof EventEmitter); // true
463
+ * console.log(MyStream.super_ === EventEmitter); // true
464
+ *
465
+ * stream.on('data', (data) => {
466
+ * console.log(`Received data: "${data}"`);
467
+ * });
468
+ * stream.write('It works!'); // Received data: "It works!"
469
+ * ```
470
+ *
471
+ * ES6 example using `class` and `extends`:
472
+ *
473
+ * ```js
474
+ * const EventEmitter = require('events');
475
+ *
476
+ * class MyStream extends EventEmitter {
477
+ * write(data) {
478
+ * this.emit('data', data);
479
+ * }
480
+ * }
481
+ *
482
+ * const stream = new MyStream();
483
+ *
484
+ * stream.on('data', (data) => {
485
+ * console.log(`Received data: "${data}"`);
486
+ * });
487
+ * stream.write('With ES6');
488
+ * ```
489
+ * @since v0.3.0
490
+ * @deprecated Legacy: Use ES2015 class syntax and `extends` keyword instead.
491
+ */
492
+ export function inherits(constructor: unknown, superConstructor: unknown): void;
493
+ export type DebugLoggerFunction = (msg: string, ...param: unknown[]) => void;
494
+ export interface DebugLogger extends DebugLoggerFunction {
495
+ enabled: boolean;
496
+ }
497
+ /**
498
+ * The `util.debuglog()` method is used to create a function that conditionally
499
+ * writes debug messages to `stderr` based on the existence of the `NODE_DEBUG`environment variable. If the `section` name appears within the value of that
500
+ * environment variable, then the returned function operates similar to `console.error()`. If not, then the returned function is a no-op.
501
+ *
502
+ * ```js
503
+ * const util = require('util');
504
+ * const debuglog = util.debuglog('foo');
505
+ *
506
+ * debuglog('hello from foo [%d]', 123);
507
+ * ```
508
+ *
509
+ * If this program is run with `NODE_DEBUG=foo` in the environment, then
510
+ * it will output something like:
511
+ *
512
+ * ```console
513
+ * FOO 3245: hello from foo [123]
514
+ * ```
515
+ *
516
+ * where `3245` is the process id. If it is not run with that
517
+ * environment variable set, then it will not print anything.
518
+ *
519
+ * The `section` supports wildcard also:
520
+ *
521
+ * ```js
522
+ * const util = require('util');
523
+ * const debuglog = util.debuglog('foo-bar');
524
+ *
525
+ * debuglog('hi there, it\'s foo-bar [%d]', 2333);
526
+ * ```
527
+ *
528
+ * if it is run with `NODE_DEBUG=foo*` in the environment, then it will output
529
+ * something like:
530
+ *
531
+ * ```console
532
+ * FOO-BAR 3257: hi there, it's foo-bar [2333]
533
+ * ```
534
+ *
535
+ * Multiple comma-separated `section` names may be specified in the `NODE_DEBUG`environment variable: `NODE_DEBUG=fs,net,tls`.
536
+ *
537
+ * The optional `callback` argument can be used to replace the logging function
538
+ * with a different function that doesn't have any initialization or
539
+ * unnecessary wrapping.
540
+ *
541
+ * ```js
542
+ * const util = require('util');
543
+ * let debuglog = util.debuglog('internals', (debug) => {
544
+ * // Replace with a logging function that optimizes out
545
+ * // testing if the section is enabled
546
+ * debuglog = debug;
547
+ * });
548
+ * ```
549
+ * @since v0.11.3
550
+ * @param section A string identifying the portion of the application for which the `debuglog` function is being created.
551
+ * @param callback A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function.
552
+ * @return The logging function
553
+ */
554
+ export function debuglog(section: string, callback?: (fn: DebugLoggerFunction) => void): DebugLogger;
555
+ export const debug: typeof debuglog;
556
+ /**
557
+ * Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`.
558
+ *
559
+ * ```js
560
+ * const util = require('util');
561
+ *
562
+ * util.isBoolean(1);
563
+ * // Returns: false
564
+ * util.isBoolean(0);
565
+ * // Returns: false
566
+ * util.isBoolean(false);
567
+ * // Returns: true
568
+ * ```
569
+ * @since v0.11.5
570
+ * @deprecated Since v4.0.0 - Use `typeof value === 'boolean'` instead.
571
+ */
572
+ export function isBoolean(object: unknown): object is boolean;
573
+ /**
574
+ * Returns `true` if the given `object` is a `Buffer`. Otherwise, returns `false`.
575
+ *
576
+ * ```js
577
+ * const util = require('util');
578
+ *
579
+ * util.isBuffer({ length: 0 });
580
+ * // Returns: false
581
+ * util.isBuffer([]);
582
+ * // Returns: false
583
+ * util.isBuffer(Buffer.from('hello world'));
584
+ * // Returns: true
585
+ * ```
586
+ * @since v0.11.5
587
+ * @deprecated Since v4.0.0 - Use `isBuffer` instead.
588
+ */
589
+ export function isBuffer(object: unknown): object is Buffer;
590
+ /**
591
+ * Returns `true` if the given `object` is a `Function`. Otherwise, returns`false`.
592
+ *
593
+ * ```js
594
+ * const util = require('util');
595
+ *
596
+ * function Foo() {}
597
+ * const Bar = () => {};
598
+ *
599
+ * util.isFunction({});
600
+ * // Returns: false
601
+ * util.isFunction(Foo);
602
+ * // Returns: true
603
+ * util.isFunction(Bar);
604
+ * // Returns: true
605
+ * ```
606
+ * @since v0.11.5
607
+ * @deprecated Since v4.0.0 - Use `typeof value === 'function'` instead.
608
+ */
609
+ export function isFunction(object: unknown): boolean;
610
+ /**
611
+ * Returns `true` if the given `object` is strictly `null`. Otherwise, returns`false`.
612
+ *
613
+ * ```js
614
+ * const util = require('util');
615
+ *
616
+ * util.isNull(0);
617
+ * // Returns: false
618
+ * util.isNull(undefined);
619
+ * // Returns: false
620
+ * util.isNull(null);
621
+ * // Returns: true
622
+ * ```
623
+ * @since v0.11.5
624
+ * @deprecated Since v4.0.0 - Use `value === null` instead.
625
+ */
626
+ export function isNull(object: unknown): object is null;
627
+ /**
628
+ * Returns `true` if the given `object` is `null` or `undefined`. Otherwise,
629
+ * returns `false`.
630
+ *
631
+ * ```js
632
+ * const util = require('util');
633
+ *
634
+ * util.isNullOrUndefined(0);
635
+ * // Returns: false
636
+ * util.isNullOrUndefined(undefined);
637
+ * // Returns: true
638
+ * util.isNullOrUndefined(null);
639
+ * // Returns: true
640
+ * ```
641
+ * @since v0.11.5
642
+ * @deprecated Since v4.0.0 - Use `value === undefined || value === null` instead.
643
+ */
644
+ export function isNullOrUndefined(object: unknown): object is null | undefined;
645
+ /**
646
+ * Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`.
647
+ *
648
+ * ```js
649
+ * const util = require('util');
650
+ *
651
+ * util.isNumber(false);
652
+ * // Returns: false
653
+ * util.isNumber(Infinity);
654
+ * // Returns: true
655
+ * util.isNumber(0);
656
+ * // Returns: true
657
+ * util.isNumber(NaN);
658
+ * // Returns: true
659
+ * ```
660
+ * @since v0.11.5
661
+ * @deprecated Since v4.0.0 - Use `typeof value === 'number'` instead.
662
+ */
663
+ export function isNumber(object: unknown): object is number;
664
+ /**
665
+ * Returns `true` if the given `object` is strictly an `Object`**and** not a`Function` (even though functions are objects in JavaScript).
666
+ * Otherwise, returns `false`.
667
+ *
668
+ * ```js
669
+ * const util = require('util');
670
+ *
671
+ * util.isObject(5);
672
+ * // Returns: false
673
+ * util.isObject(null);
674
+ * // Returns: false
675
+ * util.isObject({});
676
+ * // Returns: true
677
+ * util.isObject(() => {});
678
+ * // Returns: false
679
+ * ```
680
+ * @since v0.11.5
681
+ * @deprecated Since v4.0.0 - Deprecated: Use `value !== null && typeof value === 'object'` instead.
682
+ */
683
+ export function isObject(object: unknown): boolean;
684
+ /**
685
+ * Returns `true` if the given `object` is a primitive type. Otherwise, returns`false`.
686
+ *
687
+ * ```js
688
+ * const util = require('util');
689
+ *
690
+ * util.isPrimitive(5);
691
+ * // Returns: true
692
+ * util.isPrimitive('foo');
693
+ * // Returns: true
694
+ * util.isPrimitive(false);
695
+ * // Returns: true
696
+ * util.isPrimitive(null);
697
+ * // Returns: true
698
+ * util.isPrimitive(undefined);
699
+ * // Returns: true
700
+ * util.isPrimitive({});
701
+ * // Returns: false
702
+ * util.isPrimitive(() => {});
703
+ * // Returns: false
704
+ * util.isPrimitive(/^$/);
705
+ * // Returns: false
706
+ * util.isPrimitive(new Date());
707
+ * // Returns: false
708
+ * ```
709
+ * @since v0.11.5
710
+ * @deprecated Since v4.0.0 - Use `(typeof value !== 'object' && typeof value !== 'function') || value === null` instead.
711
+ */
712
+ export function isPrimitive(object: unknown): boolean;
713
+ /**
714
+ * Returns `true` if the given `object` is a `string`. Otherwise, returns `false`.
715
+ *
716
+ * ```js
717
+ * const util = require('util');
718
+ *
719
+ * util.isString('');
720
+ * // Returns: true
721
+ * util.isString('foo');
722
+ * // Returns: true
723
+ * util.isString(String('foo'));
724
+ * // Returns: true
725
+ * util.isString(5);
726
+ * // Returns: false
727
+ * ```
728
+ * @since v0.11.5
729
+ * @deprecated Since v4.0.0 - Use `typeof value === 'string'` instead.
730
+ */
731
+ export function isString(object: unknown): object is string;
732
+ /**
733
+ * Returns `true` if the given `object` is a `Symbol`. Otherwise, returns `false`.
734
+ *
735
+ * ```js
736
+ * const util = require('util');
737
+ *
738
+ * util.isSymbol(5);
739
+ * // Returns: false
740
+ * util.isSymbol('foo');
741
+ * // Returns: false
742
+ * util.isSymbol(Symbol('foo'));
743
+ * // Returns: true
744
+ * ```
745
+ * @since v0.11.5
746
+ * @deprecated Since v4.0.0 - Use `typeof value === 'symbol'` instead.
747
+ */
748
+ export function isSymbol(object: unknown): object is symbol;
749
+ /**
750
+ * Returns `true` if the given `object` is `undefined`. Otherwise, returns `false`.
751
+ *
752
+ * ```js
753
+ * const util = require('util');
754
+ *
755
+ * const foo = undefined;
756
+ * util.isUndefined(5);
757
+ * // Returns: false
758
+ * util.isUndefined(foo);
759
+ * // Returns: true
760
+ * util.isUndefined(null);
761
+ * // Returns: false
762
+ * ```
763
+ * @since v0.11.5
764
+ * @deprecated Since v4.0.0 - Use `value === undefined` instead.
765
+ */
766
+ export function isUndefined(object: unknown): object is undefined;
767
+ /**
768
+ * The `util.deprecate()` method wraps `fn` (which may be a function or class) in
769
+ * such a way that it is marked as deprecated.
770
+ *
771
+ * ```js
772
+ * const util = require('util');
773
+ *
774
+ * exports.obsoleteFunction = util.deprecate(() => {
775
+ * // Do something here.
776
+ * }, 'obsoleteFunction() is deprecated. Use newShinyFunction() instead.');
777
+ * ```
778
+ *
779
+ * When called, `util.deprecate()` will return a function that will emit a`DeprecationWarning` using the `'warning'` event. The warning will
780
+ * be emitted and printed to `stderr` the first time the returned function is
781
+ * called. After the warning is emitted, the wrapped function is called without
782
+ * emitting a warning.
783
+ *
784
+ * If the same optional `code` is supplied in multiple calls to `util.deprecate()`,
785
+ * the warning will be emitted only once for that `code`.
786
+ *
787
+ * ```js
788
+ * const util = require('util');
789
+ *
790
+ * const fn1 = util.deprecate(someFunction, someMessage, 'DEP0001');
791
+ * const fn2 = util.deprecate(someOtherFunction, someOtherMessage, 'DEP0001');
792
+ * fn1(); // Emits a deprecation warning with code DEP0001
793
+ * fn2(); // Does not emit a deprecation warning because it has the same code
794
+ * ```
795
+ *
796
+ * If either the `--no-deprecation` or `--no-warnings` command-line flags are
797
+ * used, or if the `process.noDeprecation` property is set to `true`_prior_ to
798
+ * the first deprecation warning, the `util.deprecate()` method does nothing.
799
+ *
800
+ * If the `--trace-deprecation` or `--trace-warnings` command-line flags are set,
801
+ * or the `process.traceDeprecation` property is set to `true`, a warning and a
802
+ * stack trace are printed to `stderr` the first time the deprecated function is
803
+ * called.
804
+ *
805
+ * If the `--throw-deprecation` command-line flag is set, or the`process.throwDeprecation` property is set to `true`, then an exception will be
806
+ * thrown when the deprecated function is called.
807
+ *
808
+ * The `--throw-deprecation` command-line flag and `process.throwDeprecation`property take precedence over `--trace-deprecation` and`process.traceDeprecation`.
809
+ * @since v0.8.0
810
+ * @param fn The function that is being deprecated.
811
+ * @param msg A warning message to display when the deprecated function is invoked.
812
+ * @param code A deprecation code. See the `list of deprecated APIs` for a list of codes.
813
+ * @return The deprecated function wrapped to emit a warning.
814
+ */
815
+ export function deprecate<T extends Function>(fn: T, msg: string, code?: string): T;
816
+ /**
817
+ * Returns `true` if there is deep strict equality between `val1` and `val2`.
818
+ * Otherwise, returns `false`.
819
+ *
820
+ * See `assert.deepStrictEqual()` for more information about deep strict
821
+ * equality.
822
+ * @since v9.0.0
823
+ */
824
+ export function isDeepStrictEqual(val1: unknown, val2: unknown): boolean;
825
+ /**
826
+ * Returns `str` with any ANSI escape codes removed.
827
+ *
828
+ * ```js
829
+ * console.log(util.stripVTControlCharacters('\u001B[4mvalue\u001B[0m'));
830
+ * // Prints "value"
831
+ * ```
832
+ * @since v16.11.0
833
+ */
834
+ export function stripVTControlCharacters(str: string): string;
835
+ /**
836
+ * Takes an `async` function (or a function that returns a `Promise`) and returns a
837
+ * function following the error-first callback style, i.e. taking
838
+ * an `(err, value) => ...` callback as the last argument. In the callback, the
839
+ * first argument will be the rejection reason (or `null` if the `Promise`resolved), and the second argument will be the resolved value.
840
+ *
841
+ * ```js
842
+ * const util = require('util');
843
+ *
844
+ * async function fn() {
845
+ * return 'hello world';
846
+ * }
847
+ * const callbackFunction = util.callbackify(fn);
848
+ *
849
+ * callbackFunction((err, ret) => {
850
+ * if (err) throw err;
851
+ * console.log(ret);
852
+ * });
853
+ * ```
854
+ *
855
+ * Will print:
856
+ *
857
+ * ```text
858
+ * hello world
859
+ * ```
860
+ *
861
+ * The callback is executed asynchronously, and will have a limited stack trace.
862
+ * If the callback throws, the process will emit an `'uncaughtException'` event, and if not handled will exit.
863
+ *
864
+ * Since `null` has a special meaning as the first argument to a callback, if a
865
+ * wrapped function rejects a `Promise` with a falsy value as a reason, the value
866
+ * is wrapped in an `Error` with the original value stored in a field named`reason`.
867
+ *
868
+ * ```js
869
+ * function fn() {
870
+ * return Promise.reject(null);
871
+ * }
872
+ * const callbackFunction = util.callbackify(fn);
873
+ *
874
+ * callbackFunction((err, ret) => {
875
+ * // When the Promise was rejected with `null` it is wrapped with an Error and
876
+ * // the original value is stored in `reason`.
877
+ * err &#x26;&#x26; Object.hasOwn(err, 'reason') &#x26;&#x26; err.reason === null; // true
878
+ * });
879
+ * ```
880
+ * @since v8.2.0
881
+ * @param original An `async` function
882
+ * @return a callback style function
883
+ */
884
+ export function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
885
+ export function callbackify<TResult>(fn: () => Promise<TResult>): (callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
886
+ export function callbackify<T1>(fn: (arg1: T1) => Promise<void>): (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void;
887
+ export function callbackify<T1, TResult>(fn: (arg1: T1) => Promise<TResult>): (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
888
+ export function callbackify<T1, T2>(fn: (arg1: T1, arg2: T2) => Promise<void>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void;
889
+ export function callbackify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2) => Promise<TResult>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
890
+ export function callbackify<T1, T2, T3>(fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<void>): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException) => void) => void;
891
+ export function callbackify<T1, T2, T3, TResult>(
892
+ fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>
893
+ ): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
894
+ export function callbackify<T1, T2, T3, T4>(
895
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>
896
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException) => void) => void;
897
+ export function callbackify<T1, T2, T3, T4, TResult>(
898
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>
899
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
900
+ export function callbackify<T1, T2, T3, T4, T5>(
901
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>
902
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException) => void) => void;
903
+ export function callbackify<T1, T2, T3, T4, T5, TResult>(
904
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>
905
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
906
+ export function callbackify<T1, T2, T3, T4, T5, T6>(
907
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<void>
908
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException) => void) => void;
909
+ export function callbackify<T1, T2, T3, T4, T5, T6, TResult>(
910
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<TResult>
911
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
912
+ export interface CustomPromisifyLegacy<TCustom extends Function> extends Function {
913
+ __promisify__: TCustom;
914
+ }
915
+ export interface CustomPromisifySymbol<TCustom extends Function> extends Function {
916
+ [promisify.custom]: TCustom;
917
+ }
918
+ export type CustomPromisify<TCustom extends Function> = CustomPromisifySymbol<TCustom> | CustomPromisifyLegacy<TCustom>;
919
+ /**
920
+ * Takes a function following the common error-first callback style, i.e. taking
921
+ * an `(err, value) => ...` callback as the last argument, and returns a version
922
+ * that returns promises.
923
+ *
924
+ * ```js
925
+ * const util = require('util');
926
+ * const fs = require('fs');
927
+ *
928
+ * const stat = util.promisify(fs.stat);
929
+ * stat('.').then((stats) => {
930
+ * // Do something with `stats`
931
+ * }).catch((error) => {
932
+ * // Handle the error.
933
+ * });
934
+ * ```
935
+ *
936
+ * Or, equivalently using `async function`s:
937
+ *
938
+ * ```js
939
+ * const util = require('util');
940
+ * const fs = require('fs');
941
+ *
942
+ * const stat = util.promisify(fs.stat);
943
+ *
944
+ * async function callStat() {
945
+ * const stats = await stat('.');
946
+ * console.log(`This directory is owned by ${stats.uid}`);
947
+ * }
948
+ * ```
949
+ *
950
+ * If there is an `original[util.promisify.custom]` property present, `promisify`will return its value, see `Custom promisified functions`.
951
+ *
952
+ * `promisify()` assumes that `original` is a function taking a callback as its
953
+ * final argument in all cases. If `original` is not a function, `promisify()`will throw an error. If `original` is a function but its last argument is not
954
+ * an error-first callback, it will still be passed an error-first
955
+ * callback as its last argument.
956
+ *
957
+ * Using `promisify()` on class methods or other methods that use `this` may not
958
+ * work as expected unless handled specially:
959
+ *
960
+ * ```js
961
+ * const util = require('util');
962
+ *
963
+ * class Foo {
964
+ * constructor() {
965
+ * this.a = 42;
966
+ * }
967
+ *
968
+ * bar(callback) {
969
+ * callback(null, this.a);
970
+ * }
971
+ * }
972
+ *
973
+ * const foo = new Foo();
974
+ *
975
+ * const naiveBar = util.promisify(foo.bar);
976
+ * // TypeError: Cannot read property 'a' of undefined
977
+ * // naiveBar().then(a => console.log(a));
978
+ *
979
+ * naiveBar.call(foo).then((a) => console.log(a)); // '42'
980
+ *
981
+ * const bindBar = naiveBar.bind(foo);
982
+ * bindBar().then((a) => console.log(a)); // '42'
983
+ * ```
984
+ * @since v8.0.0
985
+ */
986
+ export function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
987
+ export function promisify<TResult>(fn: (callback: (err: any, result: TResult) => void) => void): () => Promise<TResult>;
988
+ export function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
989
+ export function promisify<T1, TResult>(fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void): (arg1: T1) => Promise<TResult>;
990
+ export function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
991
+ export function promisify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise<TResult>;
992
+ export function promisify<T1, T2>(fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2) => Promise<void>;
993
+ export function promisify<T1, T2, T3, TResult>(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void): (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>;
994
+ export function promisify<T1, T2, T3>(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2, arg3: T3) => Promise<void>;
995
+ export function promisify<T1, T2, T3, T4, TResult>(
996
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void
997
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
998
+ export function promisify<T1, T2, T3, T4>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>;
999
+ export function promisify<T1, T2, T3, T4, T5, TResult>(
1000
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void
1001
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
1002
+ export function promisify<T1, T2, T3, T4, T5>(
1003
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void
1004
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
1005
+ export function promisify(fn: Function): Function;
1006
+ export namespace promisify {
1007
+ /**
1008
+ * That can be used to declare custom promisified variants of functions.
1009
+ */
1010
+ const custom: unique symbol;
1011
+ }
1012
+ /**
1013
+ * An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextDecoder` API.
1014
+ *
1015
+ * ```js
1016
+ * const decoder = new TextDecoder();
1017
+ * const u8arr = new Uint8Array([72, 101, 108, 108, 111]);
1018
+ * console.log(decoder.decode(u8arr)); // Hello
1019
+ * ```
1020
+ * @since v8.3.0
1021
+ */
1022
+ export class TextDecoder {
1023
+ /**
1024
+ * The encoding supported by the `TextDecoder` instance.
1025
+ */
1026
+ readonly encoding: string;
1027
+ /**
1028
+ * The value will be `true` if decoding errors result in a `TypeError` being
1029
+ * thrown.
1030
+ */
1031
+ readonly fatal: boolean;
1032
+ /**
1033
+ * The value will be `true` if the decoding result will include the byte order
1034
+ * mark.
1035
+ */
1036
+ readonly ignoreBOM: boolean;
1037
+ constructor(
1038
+ encoding?: string,
1039
+ options?: {
1040
+ fatal?: boolean | undefined;
1041
+ ignoreBOM?: boolean | undefined;
1042
+ }
1043
+ );
1044
+ /**
1045
+ * Decodes the `input` and returns a string. If `options.stream` is `true`, any
1046
+ * incomplete byte sequences occurring at the end of the `input` are buffered
1047
+ * internally and emitted after the next call to `textDecoder.decode()`.
1048
+ *
1049
+ * If `textDecoder.fatal` is `true`, decoding errors that occur will result in a`TypeError` being thrown.
1050
+ * @param input An `ArrayBuffer`, `DataView` or `TypedArray` instance containing the encoded data.
1051
+ */
1052
+ decode(
1053
+ input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
1054
+ options?: {
1055
+ stream?: boolean | undefined;
1056
+ }
1057
+ ): string;
1058
+ }
1059
+ export interface EncodeIntoResult {
1060
+ /**
1061
+ * The read Unicode code units of input.
1062
+ */
1063
+ read: number;
1064
+ /**
1065
+ * The written UTF-8 bytes of output.
1066
+ */
1067
+ written: number;
1068
+ }
1069
+ export { types };
1070
+ /**
1071
+ * An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextEncoder` API. All
1072
+ * instances of `TextEncoder` only support UTF-8 encoding.
1073
+ *
1074
+ * ```js
1075
+ * const encoder = new TextEncoder();
1076
+ * const uint8array = encoder.encode('this is some data');
1077
+ * ```
1078
+ *
1079
+ * The `TextEncoder` class is also available on the global object.
1080
+ * @since v8.3.0
1081
+ */
1082
+ export class TextEncoder {
1083
+ /**
1084
+ * The encoding supported by the `TextEncoder` instance. Always set to `'utf-8'`.
1085
+ */
1086
+ readonly encoding: string;
1087
+ /**
1088
+ * UTF-8 encodes the `input` string and returns a `Uint8Array` containing the
1089
+ * encoded bytes.
1090
+ * @param [input='an empty string'] The text to encode.
1091
+ */
1092
+ encode(input?: string): Uint8Array;
1093
+ /**
1094
+ * UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object
1095
+ * containing the read Unicode code units and written UTF-8 bytes.
1096
+ *
1097
+ * ```js
1098
+ * const encoder = new TextEncoder();
1099
+ * const src = 'this is some data';
1100
+ * const dest = new Uint8Array(10);
1101
+ * const { read, written } = encoder.encodeInto(src, dest);
1102
+ * ```
1103
+ * @param src The text to encode.
1104
+ * @param dest The array to hold the encode result.
1105
+ */
1106
+ encodeInto(src: string, dest: Uint8Array): EncodeIntoResult;
1107
+ }
1108
+
1109
+ /**
1110
+ * Provides a high-level API for command-line argument parsing. Takes a
1111
+ * specification for the expected arguments and returns a structured object
1112
+ * with the parsed values and positionals.
1113
+ *
1114
+ * `config` provides arguments for parsing and configures the parser. It
1115
+ * supports the following properties:
1116
+ *
1117
+ * - `args` The array of argument strings. **Default:** `process.argv` with
1118
+ * `execPath` and `filename` removed.
1119
+ * - `options` Arguments known to the parser. Keys of `options` are the long
1120
+ * names of options and values are objects accepting the following properties:
1121
+ *
1122
+ * - `type` Type of argument, which must be either `boolean` (for options
1123
+ * which do not take values) or `string` (for options which do).
1124
+ * - `multiple` Whether this option can be provided multiple
1125
+ * times. If `true`, all values will be collected in an array. If
1126
+ * `false`, values for the option are last-wins. **Default:** `false`.
1127
+ * - `short` A single character alias for the option.
1128
+ *
1129
+ * - `strict`: Whether an error should be thrown when unknown arguments
1130
+ * are encountered, or when arguments are passed that do not match the
1131
+ * `type` configured in `options`. **Default:** `true`.
1132
+ * - `allowPositionals`: Whether this command accepts positional arguments.
1133
+ * **Default:** `false` if `strict` is `true`, otherwise `true`.
1134
+ * - `tokens`: Whether tokens {boolean} Return the parsed tokens. This is useful
1135
+ * for extending the built-in behavior, from adding additional checks through
1136
+ * to reprocessing the tokens in different ways.
1137
+ * **Default:** `false`.
1138
+ *
1139
+ * @returns The parsed command line arguments:
1140
+ *
1141
+ * - `values` A mapping of parsed option names with their string
1142
+ * or boolean values.
1143
+ * - `positionals` Positional arguments.
1144
+ * - `tokens` Detailed parse information (only if `tokens` was specified).
1145
+ *
1146
+ */
1147
+ export function parseArgs<T extends ParseArgsConfig>(config: T): ParsedResults<T>;
1148
+
1149
+ interface ParseArgsOptionConfig {
1150
+ type: 'string' | 'boolean';
1151
+ short?: string;
1152
+ multiple?: boolean;
1153
+ }
1154
+
1155
+ interface ParseArgsOptionsConfig {
1156
+ [longOption: string]: ParseArgsOptionConfig;
1157
+ }
1158
+
1159
+ export interface ParseArgsConfig {
1160
+ strict?: boolean;
1161
+ allowPositionals?: boolean;
1162
+ tokens?: boolean;
1163
+ options?: ParseArgsOptionsConfig;
1164
+ args?: string[];
1165
+ }
1166
+
1167
+ /*
1168
+ IfDefaultsTrue and IfDefaultsFalse are helpers to handle default values for missing boolean properties.
1169
+ TypeScript does not have exact types for objects: https://github.com/microsoft/TypeScript/issues/12936
1170
+ This means it is impossible to distinguish between "field X is definitely not present" and "field X may or may not be present".
1171
+ But we expect users to generally provide their config inline or `as const`, which means TS will always know whether a given field is present.
1172
+ So this helper treats "not definitely present" (i.e., not `extends boolean`) as being "definitely not present", i.e. it should have its default value.
1173
+ This is technically incorrect but is a much nicer UX for the common case.
1174
+ The IfDefaultsTrue version is for things which default to true; the IfDefaultsFalse version is for things which default to false.
1175
+ */
1176
+ type IfDefaultsTrue<T, IfTrue, IfFalse> = T extends true
1177
+ ? IfTrue
1178
+ : T extends false
1179
+ ? IfFalse
1180
+ : IfTrue;
1181
+
1182
+ // we put the `extends false` condition first here because `undefined` compares like `any` when `strictNullChecks: false`
1183
+ type IfDefaultsFalse<T, IfTrue, IfFalse> = T extends false
1184
+ ? IfFalse
1185
+ : T extends true
1186
+ ? IfTrue
1187
+ : IfFalse;
1188
+
1189
+ type ExtractOptionValue<T extends ParseArgsConfig, O extends ParseArgsOptionConfig> = IfDefaultsTrue<
1190
+ T['strict'],
1191
+ O['type'] extends 'string' ? string : O['type'] extends 'boolean' ? boolean : string | boolean,
1192
+ string | boolean
1193
+ >;
1194
+
1195
+ type ParsedValues<T extends ParseArgsConfig> =
1196
+ & IfDefaultsTrue<T['strict'], unknown, { [longOption: string]: undefined | string | boolean }>
1197
+ & (T['options'] extends ParseArgsOptionsConfig
1198
+ ? {
1199
+ -readonly [LongOption in keyof T['options']]: IfDefaultsFalse<
1200
+ T['options'][LongOption]['multiple'],
1201
+ undefined | Array<ExtractOptionValue<T, T['options'][LongOption]>>,
1202
+ undefined | ExtractOptionValue<T, T['options'][LongOption]>
1203
+ >;
1204
+ }
1205
+ : {});
1206
+
1207
+ type ParsedPositionals<T extends ParseArgsConfig> = IfDefaultsTrue<
1208
+ T['strict'],
1209
+ IfDefaultsFalse<T['allowPositionals'], string[], []>,
1210
+ IfDefaultsTrue<T['allowPositionals'], string[], []>
1211
+ >;
1212
+
1213
+ type PreciseTokenForOptions<
1214
+ K extends string,
1215
+ O extends ParseArgsOptionConfig,
1216
+ > = O['type'] extends 'string'
1217
+ ? {
1218
+ kind: 'option';
1219
+ index: number;
1220
+ name: K;
1221
+ rawName: string;
1222
+ value: string;
1223
+ inlineValue: boolean;
1224
+ }
1225
+ : O['type'] extends 'boolean'
1226
+ ? {
1227
+ kind: 'option';
1228
+ index: number;
1229
+ name: K;
1230
+ rawName: string;
1231
+ value: undefined;
1232
+ inlineValue: undefined;
1233
+ }
1234
+ : OptionToken & { name: K };
1235
+
1236
+ type TokenForOptions<
1237
+ T extends ParseArgsConfig,
1238
+ K extends keyof T['options'] = keyof T['options'],
1239
+ > = K extends unknown
1240
+ ? T['options'] extends ParseArgsOptionsConfig
1241
+ ? PreciseTokenForOptions<K & string, T['options'][K]>
1242
+ : OptionToken
1243
+ : never;
1244
+
1245
+ type ParsedOptionToken<T extends ParseArgsConfig> = IfDefaultsTrue<T['strict'], TokenForOptions<T>, OptionToken>;
1246
+
1247
+ type ParsedPositionalToken<T extends ParseArgsConfig> = IfDefaultsTrue<
1248
+ T['strict'],
1249
+ IfDefaultsFalse<T['allowPositionals'], { kind: 'positional'; index: number; value: string }, never>,
1250
+ IfDefaultsTrue<T['allowPositionals'], { kind: 'positional'; index: number; value: string }, never>
1251
+ >;
1252
+
1253
+ type ParsedTokens<T extends ParseArgsConfig> = Array<
1254
+ ParsedOptionToken<T> | ParsedPositionalToken<T> | { kind: 'option-terminator'; index: number }
1255
+ >;
1256
+
1257
+ type PreciseParsedResults<T extends ParseArgsConfig> = IfDefaultsFalse<
1258
+ T['tokens'],
1259
+ {
1260
+ values: ParsedValues<T>;
1261
+ positionals: ParsedPositionals<T>;
1262
+ tokens: ParsedTokens<T>;
1263
+ },
1264
+ {
1265
+ values: ParsedValues<T>;
1266
+ positionals: ParsedPositionals<T>;
1267
+ }
1268
+ >;
1269
+
1270
+ type OptionToken =
1271
+ | { kind: 'option'; index: number; name: string; rawName: string; value: string; inlineValue: boolean }
1272
+ | {
1273
+ kind: 'option';
1274
+ index: number;
1275
+ name: string;
1276
+ rawName: string;
1277
+ value: undefined;
1278
+ inlineValue: undefined;
1279
+ };
1280
+
1281
+ type Token =
1282
+ | OptionToken
1283
+ | { kind: 'positional'; index: number; value: string }
1284
+ | { kind: 'option-terminator'; index: number };
1285
+
1286
+ // If ParseArgsConfig extends T, then the user passed config constructed elsewhere.
1287
+ // So we can't rely on the `"not definitely present" implies "definitely not present"` assumption mentioned above.
1288
+ type ParsedResults<T extends ParseArgsConfig> = ParseArgsConfig extends T
1289
+ ? {
1290
+ values: { [longOption: string]: undefined | string | boolean | Array<string | boolean> };
1291
+ positionals: string[];
1292
+ tokens?: Token[];
1293
+ }
1294
+ : PreciseParsedResults<T>;
1295
+ }
1296
+ declare module 'util/types' {
1297
+ export * from 'util/types';
1298
+ }
1299
+ declare module 'util/types' {
1300
+ import { KeyObject, webcrypto } from 'node:crypto';
1301
+ /**
1302
+ * Returns `true` if the value is a built-in [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) or
1303
+ * [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instance.
1304
+ *
1305
+ * See also `util.types.isArrayBuffer()` and `util.types.isSharedArrayBuffer()`.
1306
+ *
1307
+ * ```js
1308
+ * util.types.isAnyArrayBuffer(new ArrayBuffer()); // Returns true
1309
+ * util.types.isAnyArrayBuffer(new SharedArrayBuffer()); // Returns true
1310
+ * ```
1311
+ * @since v10.0.0
1312
+ */
1313
+ function isAnyArrayBuffer(object: unknown): object is ArrayBufferLike;
1314
+ /**
1315
+ * Returns `true` if the value is an `arguments` object.
1316
+ *
1317
+ * ```js
1318
+ * function foo() {
1319
+ * util.types.isArgumentsObject(arguments); // Returns true
1320
+ * }
1321
+ * ```
1322
+ * @since v10.0.0
1323
+ */
1324
+ function isArgumentsObject(object: unknown): object is IArguments;
1325
+ /**
1326
+ * Returns `true` if the value is a built-in [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) instance.
1327
+ * This does _not_ include [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances. Usually, it is
1328
+ * desirable to test for both; See `util.types.isAnyArrayBuffer()` for that.
1329
+ *
1330
+ * ```js
1331
+ * util.types.isArrayBuffer(new ArrayBuffer()); // Returns true
1332
+ * util.types.isArrayBuffer(new SharedArrayBuffer()); // Returns false
1333
+ * ```
1334
+ * @since v10.0.0
1335
+ */
1336
+ function isArrayBuffer(object: unknown): object is ArrayBuffer;
1337
+ /**
1338
+ * Returns `true` if the value is an instance of one of the [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) views, such as typed
1339
+ * array objects or [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView). Equivalent to
1340
+ * [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
1341
+ *
1342
+ * ```js
1343
+ * util.types.isArrayBufferView(new Int8Array()); // true
1344
+ * util.types.isArrayBufferView(Buffer.from('hello world')); // true
1345
+ * util.types.isArrayBufferView(new DataView(new ArrayBuffer(16))); // true
1346
+ * util.types.isArrayBufferView(new ArrayBuffer()); // false
1347
+ * ```
1348
+ * @since v10.0.0
1349
+ */
1350
+ function isArrayBufferView(object: unknown): object is NodeJS.ArrayBufferView;
1351
+ /**
1352
+ * Returns `true` if the value is an [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).
1353
+ * This only reports back what the JavaScript engine is seeing;
1354
+ * in particular, the return value may not match the original source code if
1355
+ * a transpilation tool was used.
1356
+ *
1357
+ * ```js
1358
+ * util.types.isAsyncFunction(function foo() {}); // Returns false
1359
+ * util.types.isAsyncFunction(async function foo() {}); // Returns true
1360
+ * ```
1361
+ * @since v10.0.0
1362
+ */
1363
+ function isAsyncFunction(object: unknown): boolean;
1364
+ /**
1365
+ * Returns `true` if the value is a `BigInt64Array` instance.
1366
+ *
1367
+ * ```js
1368
+ * util.types.isBigInt64Array(new BigInt64Array()); // Returns true
1369
+ * util.types.isBigInt64Array(new BigUint64Array()); // Returns false
1370
+ * ```
1371
+ * @since v10.0.0
1372
+ */
1373
+ function isBigInt64Array(value: unknown): value is BigInt64Array;
1374
+ /**
1375
+ * Returns `true` if the value is a `BigUint64Array` instance.
1376
+ *
1377
+ * ```js
1378
+ * util.types.isBigUint64Array(new BigInt64Array()); // Returns false
1379
+ * util.types.isBigUint64Array(new BigUint64Array()); // Returns true
1380
+ * ```
1381
+ * @since v10.0.0
1382
+ */
1383
+ function isBigUint64Array(value: unknown): value is BigUint64Array;
1384
+ /**
1385
+ * Returns `true` if the value is a boolean object, e.g. created
1386
+ * by `new Boolean()`.
1387
+ *
1388
+ * ```js
1389
+ * util.types.isBooleanObject(false); // Returns false
1390
+ * util.types.isBooleanObject(true); // Returns false
1391
+ * util.types.isBooleanObject(new Boolean(false)); // Returns true
1392
+ * util.types.isBooleanObject(new Boolean(true)); // Returns true
1393
+ * util.types.isBooleanObject(Boolean(false)); // Returns false
1394
+ * util.types.isBooleanObject(Boolean(true)); // Returns false
1395
+ * ```
1396
+ * @since v10.0.0
1397
+ */
1398
+ function isBooleanObject(object: unknown): object is Boolean;
1399
+ /**
1400
+ * Returns `true` if the value is any boxed primitive object, e.g. created
1401
+ * by `new Boolean()`, `new String()` or `Object(Symbol())`.
1402
+ *
1403
+ * For example:
1404
+ *
1405
+ * ```js
1406
+ * util.types.isBoxedPrimitive(false); // Returns false
1407
+ * util.types.isBoxedPrimitive(new Boolean(false)); // Returns true
1408
+ * util.types.isBoxedPrimitive(Symbol('foo')); // Returns false
1409
+ * util.types.isBoxedPrimitive(Object(Symbol('foo'))); // Returns true
1410
+ * util.types.isBoxedPrimitive(Object(BigInt(5))); // Returns true
1411
+ * ```
1412
+ * @since v10.11.0
1413
+ */
1414
+ function isBoxedPrimitive(object: unknown): object is String | Number | BigInt | Boolean | Symbol;
1415
+ /**
1416
+ * Returns `true` if the value is a built-in [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) instance.
1417
+ *
1418
+ * ```js
1419
+ * const ab = new ArrayBuffer(20);
1420
+ * util.types.isDataView(new DataView(ab)); // Returns true
1421
+ * util.types.isDataView(new Float64Array()); // Returns false
1422
+ * ```
1423
+ *
1424
+ * See also [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
1425
+ * @since v10.0.0
1426
+ */
1427
+ function isDataView(object: unknown): object is DataView;
1428
+ /**
1429
+ * Returns `true` if the value is a built-in [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance.
1430
+ *
1431
+ * ```js
1432
+ * util.types.isDate(new Date()); // Returns true
1433
+ * ```
1434
+ * @since v10.0.0
1435
+ */
1436
+ function isDate(object: unknown): object is Date;
1437
+ /**
1438
+ * Returns `true` if the value is a native `External` value.
1439
+ *
1440
+ * A native `External` value is a special type of object that contains a
1441
+ * raw C++ pointer (`void*`) for access from native code, and has no other
1442
+ * properties. Such objects are created either by Node.js internals or native
1443
+ * addons. In JavaScript, they are [frozen](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) objects with a`null` prototype.
1444
+ *
1445
+ * ```c
1446
+ * #include <js_native_api.h>
1447
+ * #include <stdlib.h>
1448
+ * napi_value result;
1449
+ * static napi_value MyNapi(napi_env env, napi_callback_info info) {
1450
+ * int* raw = (int*) malloc(1024);
1451
+ * napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &#x26;result);
1452
+ * if (status != napi_ok) {
1453
+ * napi_throw_error(env, NULL, "napi_create_external failed");
1454
+ * return NULL;
1455
+ * }
1456
+ * return result;
1457
+ * }
1458
+ * ...
1459
+ * DECLARE_NAPI_PROPERTY("myNapi", MyNapi)
1460
+ * ...
1461
+ * ```
1462
+ *
1463
+ * ```js
1464
+ * const native = require('napi_addon.node');
1465
+ * const data = native.myNapi();
1466
+ * util.types.isExternal(data); // returns true
1467
+ * util.types.isExternal(0); // returns false
1468
+ * util.types.isExternal(new String('foo')); // returns false
1469
+ * ```
1470
+ *
1471
+ * For further information on `napi_create_external`, refer to `napi_create_external()`.
1472
+ * @since v10.0.0
1473
+ */
1474
+ function isExternal(object: unknown): boolean;
1475
+ /**
1476
+ * Returns `true` if the value is a built-in [`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array) instance.
1477
+ *
1478
+ * ```js
1479
+ * util.types.isFloat32Array(new ArrayBuffer()); // Returns false
1480
+ * util.types.isFloat32Array(new Float32Array()); // Returns true
1481
+ * util.types.isFloat32Array(new Float64Array()); // Returns false
1482
+ * ```
1483
+ * @since v10.0.0
1484
+ */
1485
+ function isFloat32Array(object: unknown): object is Float32Array;
1486
+ /**
1487
+ * Returns `true` if the value is a built-in [`Float64Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array) instance.
1488
+ *
1489
+ * ```js
1490
+ * util.types.isFloat64Array(new ArrayBuffer()); // Returns false
1491
+ * util.types.isFloat64Array(new Uint8Array()); // Returns false
1492
+ * util.types.isFloat64Array(new Float64Array()); // Returns true
1493
+ * ```
1494
+ * @since v10.0.0
1495
+ */
1496
+ function isFloat64Array(object: unknown): object is Float64Array;
1497
+ /**
1498
+ * Returns `true` if the value is a generator function.
1499
+ * This only reports back what the JavaScript engine is seeing;
1500
+ * in particular, the return value may not match the original source code if
1501
+ * a transpilation tool was used.
1502
+ *
1503
+ * ```js
1504
+ * util.types.isGeneratorFunction(function foo() {}); // Returns false
1505
+ * util.types.isGeneratorFunction(function* foo() {}); // Returns true
1506
+ * ```
1507
+ * @since v10.0.0
1508
+ */
1509
+ function isGeneratorFunction(object: unknown): object is GeneratorFunction;
1510
+ /**
1511
+ * Returns `true` if the value is a generator object as returned from a
1512
+ * built-in generator function.
1513
+ * This only reports back what the JavaScript engine is seeing;
1514
+ * in particular, the return value may not match the original source code if
1515
+ * a transpilation tool was used.
1516
+ *
1517
+ * ```js
1518
+ * function* foo() {}
1519
+ * const generator = foo();
1520
+ * util.types.isGeneratorObject(generator); // Returns true
1521
+ * ```
1522
+ * @since v10.0.0
1523
+ */
1524
+ function isGeneratorObject(object: unknown): object is Generator;
1525
+ /**
1526
+ * Returns `true` if the value is a built-in [`Int8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array) instance.
1527
+ *
1528
+ * ```js
1529
+ * util.types.isInt8Array(new ArrayBuffer()); // Returns false
1530
+ * util.types.isInt8Array(new Int8Array()); // Returns true
1531
+ * util.types.isInt8Array(new Float64Array()); // Returns false
1532
+ * ```
1533
+ * @since v10.0.0
1534
+ */
1535
+ function isInt8Array(object: unknown): object is Int8Array;
1536
+ /**
1537
+ * Returns `true` if the value is a built-in [`Int16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array) instance.
1538
+ *
1539
+ * ```js
1540
+ * util.types.isInt16Array(new ArrayBuffer()); // Returns false
1541
+ * util.types.isInt16Array(new Int16Array()); // Returns true
1542
+ * util.types.isInt16Array(new Float64Array()); // Returns false
1543
+ * ```
1544
+ * @since v10.0.0
1545
+ */
1546
+ function isInt16Array(object: unknown): object is Int16Array;
1547
+ /**
1548
+ * Returns `true` if the value is a built-in [`Int32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array) instance.
1549
+ *
1550
+ * ```js
1551
+ * util.types.isInt32Array(new ArrayBuffer()); // Returns false
1552
+ * util.types.isInt32Array(new Int32Array()); // Returns true
1553
+ * util.types.isInt32Array(new Float64Array()); // Returns false
1554
+ * ```
1555
+ * @since v10.0.0
1556
+ */
1557
+ function isInt32Array(object: unknown): object is Int32Array;
1558
+ /**
1559
+ * Returns `true` if the value is a built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance.
1560
+ *
1561
+ * ```js
1562
+ * util.types.isMap(new Map()); // Returns true
1563
+ * ```
1564
+ * @since v10.0.0
1565
+ */
1566
+ function isMap<T>(object: T | {}): object is T extends ReadonlyMap<any, any> ? (unknown extends T ? never : ReadonlyMap<any, any>) : Map<unknown, unknown>;
1567
+ /**
1568
+ * Returns `true` if the value is an iterator returned for a built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance.
1569
+ *
1570
+ * ```js
1571
+ * const map = new Map();
1572
+ * util.types.isMapIterator(map.keys()); // Returns true
1573
+ * util.types.isMapIterator(map.values()); // Returns true
1574
+ * util.types.isMapIterator(map.entries()); // Returns true
1575
+ * util.types.isMapIterator(map[Symbol.iterator]()); // Returns true
1576
+ * ```
1577
+ * @since v10.0.0
1578
+ */
1579
+ function isMapIterator(object: unknown): boolean;
1580
+ /**
1581
+ * Returns `true` if the value is an instance of a [Module Namespace Object](https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects).
1582
+ *
1583
+ * ```js
1584
+ * import * as ns from './a.js';
1585
+ *
1586
+ * util.types.isModuleNamespaceObject(ns); // Returns true
1587
+ * ```
1588
+ * @since v10.0.0
1589
+ */
1590
+ function isModuleNamespaceObject(value: unknown): boolean;
1591
+ /**
1592
+ * Returns `true` if the value is an instance of a built-in `Error` type.
1593
+ *
1594
+ * ```js
1595
+ * util.types.isNativeError(new Error()); // Returns true
1596
+ * util.types.isNativeError(new TypeError()); // Returns true
1597
+ * util.types.isNativeError(new RangeError()); // Returns true
1598
+ * ```
1599
+ * @since v10.0.0
1600
+ */
1601
+ function isNativeError(object: unknown): object is Error;
1602
+ /**
1603
+ * Returns `true` if the value is a number object, e.g. created
1604
+ * by `new Number()`.
1605
+ *
1606
+ * ```js
1607
+ * util.types.isNumberObject(0); // Returns false
1608
+ * util.types.isNumberObject(new Number(0)); // Returns true
1609
+ * ```
1610
+ * @since v10.0.0
1611
+ */
1612
+ function isNumberObject(object: unknown): object is Number;
1613
+ /**
1614
+ * Returns `true` if the value is a built-in [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
1615
+ *
1616
+ * ```js
1617
+ * util.types.isPromise(Promise.resolve(42)); // Returns true
1618
+ * ```
1619
+ * @since v10.0.0
1620
+ */
1621
+ function isPromise(object: unknown): object is Promise<unknown>;
1622
+ /**
1623
+ * Returns `true` if the value is a [`Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) instance.
1624
+ *
1625
+ * ```js
1626
+ * const target = {};
1627
+ * const proxy = new Proxy(target, {});
1628
+ * util.types.isProxy(target); // Returns false
1629
+ * util.types.isProxy(proxy); // Returns true
1630
+ * ```
1631
+ * @since v10.0.0
1632
+ */
1633
+ function isProxy(object: unknown): boolean;
1634
+ /**
1635
+ * Returns `true` if the value is a regular expression object.
1636
+ *
1637
+ * ```js
1638
+ * util.types.isRegExp(/abc/); // Returns true
1639
+ * util.types.isRegExp(new RegExp('abc')); // Returns true
1640
+ * ```
1641
+ * @since v10.0.0
1642
+ */
1643
+ function isRegExp(object: unknown): object is RegExp;
1644
+ /**
1645
+ * Returns `true` if the value is a built-in [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance.
1646
+ *
1647
+ * ```js
1648
+ * util.types.isSet(new Set()); // Returns true
1649
+ * ```
1650
+ * @since v10.0.0
1651
+ */
1652
+ function isSet<T>(object: T | {}): object is T extends ReadonlySet<any> ? (unknown extends T ? never : ReadonlySet<any>) : Set<unknown>;
1653
+ /**
1654
+ * Returns `true` if the value is an iterator returned for a built-in [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance.
1655
+ *
1656
+ * ```js
1657
+ * const set = new Set();
1658
+ * util.types.isSetIterator(set.keys()); // Returns true
1659
+ * util.types.isSetIterator(set.values()); // Returns true
1660
+ * util.types.isSetIterator(set.entries()); // Returns true
1661
+ * util.types.isSetIterator(set[Symbol.iterator]()); // Returns true
1662
+ * ```
1663
+ * @since v10.0.0
1664
+ */
1665
+ function isSetIterator(object: unknown): boolean;
1666
+ /**
1667
+ * Returns `true` if the value is a built-in [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instance.
1668
+ * This does _not_ include [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) instances. Usually, it is
1669
+ * desirable to test for both; See `util.types.isAnyArrayBuffer()` for that.
1670
+ *
1671
+ * ```js
1672
+ * util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false
1673
+ * util.types.isSharedArrayBuffer(new SharedArrayBuffer()); // Returns true
1674
+ * ```
1675
+ * @since v10.0.0
1676
+ */
1677
+ function isSharedArrayBuffer(object: unknown): object is SharedArrayBuffer;
1678
+ /**
1679
+ * Returns `true` if the value is a string object, e.g. created
1680
+ * by `new String()`.
1681
+ *
1682
+ * ```js
1683
+ * util.types.isStringObject('foo'); // Returns false
1684
+ * util.types.isStringObject(new String('foo')); // Returns true
1685
+ * ```
1686
+ * @since v10.0.0
1687
+ */
1688
+ function isStringObject(object: unknown): object is String;
1689
+ /**
1690
+ * Returns `true` if the value is a symbol object, created
1691
+ * by calling `Object()` on a `Symbol` primitive.
1692
+ *
1693
+ * ```js
1694
+ * const symbol = Symbol('foo');
1695
+ * util.types.isSymbolObject(symbol); // Returns false
1696
+ * util.types.isSymbolObject(Object(symbol)); // Returns true
1697
+ * ```
1698
+ * @since v10.0.0
1699
+ */
1700
+ function isSymbolObject(object: unknown): object is Symbol;
1701
+ /**
1702
+ * Returns `true` if the value is a built-in [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) instance.
1703
+ *
1704
+ * ```js
1705
+ * util.types.isTypedArray(new ArrayBuffer()); // Returns false
1706
+ * util.types.isTypedArray(new Uint8Array()); // Returns true
1707
+ * util.types.isTypedArray(new Float64Array()); // Returns true
1708
+ * ```
1709
+ *
1710
+ * See also [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
1711
+ * @since v10.0.0
1712
+ */
1713
+ function isTypedArray(object: unknown): object is NodeJS.TypedArray;
1714
+ /**
1715
+ * Returns `true` if the value is a built-in [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) instance.
1716
+ *
1717
+ * ```js
1718
+ * util.types.isUint8Array(new ArrayBuffer()); // Returns false
1719
+ * util.types.isUint8Array(new Uint8Array()); // Returns true
1720
+ * util.types.isUint8Array(new Float64Array()); // Returns false
1721
+ * ```
1722
+ * @since v10.0.0
1723
+ */
1724
+ function isUint8Array(object: unknown): object is Uint8Array;
1725
+ /**
1726
+ * Returns `true` if the value is a built-in [`Uint8ClampedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) instance.
1727
+ *
1728
+ * ```js
1729
+ * util.types.isUint8ClampedArray(new ArrayBuffer()); // Returns false
1730
+ * util.types.isUint8ClampedArray(new Uint8ClampedArray()); // Returns true
1731
+ * util.types.isUint8ClampedArray(new Float64Array()); // Returns false
1732
+ * ```
1733
+ * @since v10.0.0
1734
+ */
1735
+ function isUint8ClampedArray(object: unknown): object is Uint8ClampedArray;
1736
+ /**
1737
+ * Returns `true` if the value is a built-in [`Uint16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array) instance.
1738
+ *
1739
+ * ```js
1740
+ * util.types.isUint16Array(new ArrayBuffer()); // Returns false
1741
+ * util.types.isUint16Array(new Uint16Array()); // Returns true
1742
+ * util.types.isUint16Array(new Float64Array()); // Returns false
1743
+ * ```
1744
+ * @since v10.0.0
1745
+ */
1746
+ function isUint16Array(object: unknown): object is Uint16Array;
1747
+ /**
1748
+ * Returns `true` if the value is a built-in [`Uint32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array) instance.
1749
+ *
1750
+ * ```js
1751
+ * util.types.isUint32Array(new ArrayBuffer()); // Returns false
1752
+ * util.types.isUint32Array(new Uint32Array()); // Returns true
1753
+ * util.types.isUint32Array(new Float64Array()); // Returns false
1754
+ * ```
1755
+ * @since v10.0.0
1756
+ */
1757
+ function isUint32Array(object: unknown): object is Uint32Array;
1758
+ /**
1759
+ * Returns `true` if the value is a built-in [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) instance.
1760
+ *
1761
+ * ```js
1762
+ * util.types.isWeakMap(new WeakMap()); // Returns true
1763
+ * ```
1764
+ * @since v10.0.0
1765
+ */
1766
+ function isWeakMap(object: unknown): object is WeakMap<object, unknown>;
1767
+ /**
1768
+ * Returns `true` if the value is a built-in [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) instance.
1769
+ *
1770
+ * ```js
1771
+ * util.types.isWeakSet(new WeakSet()); // Returns true
1772
+ * ```
1773
+ * @since v10.0.0
1774
+ */
1775
+ function isWeakSet(object: unknown): object is WeakSet<object>;
1776
+ /**
1777
+ * Returns `true` if `value` is a `KeyObject`, `false` otherwise.
1778
+ * @since v16.2.0
1779
+ */
1780
+ function isKeyObject(object: unknown): object is KeyObject;
1781
+ /**
1782
+ * Returns `true` if `value` is a `CryptoKey`, `false` otherwise.
1783
+ * @since v16.2.0
1784
+ */
1785
+ function isCryptoKey(object: unknown): object is webcrypto.CryptoKey;
1786
+ }
1787
+ declare module 'node:util' {
1788
+ export * from 'util';
1789
+ }
1790
+ declare module 'node:util/types' {
1791
+ export * from 'util/types';
1792
+ }