@types/node 18.19.22 → 18.19.23

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