UNPKG

64.3 kBTypeScriptView Raw
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/v17.0.0/lib/util.js)
10 */
11declare 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 * `util.inspect()` is a synchronous method intended for debugging. Its maximum
313 * output length is approximately 128 MB. Inputs that result in longer output will
314 * be truncated.
315 * @since v0.3.0
316 * @param object Any JavaScript primitive or `Object`.
317 * @return The representation of `object`.
318 */
319 export function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
320 export function inspect(object: any, options: InspectOptions): string;
321 export namespace inspect {
322 let colors: NodeJS.Dict<[number, number]>;
323 let styles: {
324 [K in Style]: string;
325 };
326 let defaultOptions: InspectOptions;
327 /**
328 * Allows changing inspect settings from the repl.
329 */
330 let replDefaults: InspectOptions;
331 /**
332 * That can be used to declare custom inspect functions.
333 */
334 const custom: unique symbol;
335 }
336 /**
337 * Alias for [`Array.isArray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray).
338 *
339 * Returns `true` if the given `object` is an `Array`. Otherwise, returns `false`.
340 *
341 * ```js
342 * const util = require('util');
343 *
344 * util.isArray([]);
345 * // Returns: true
346 * util.isArray(new Array());
347 * // Returns: true
348 * util.isArray({});
349 * // Returns: false
350 * ```
351 * @since v0.6.0
352 * @deprecated Since v4.0.0 - Use `isArray` instead.
353 */
354 export function isArray(object: unknown): object is unknown[];
355 /**
356 * Returns `true` if the given `object` is a `RegExp`. Otherwise, returns `false`.
357 *
358 * ```js
359 * const util = require('util');
360 *
361 * util.isRegExp(/some regexp/);
362 * // Returns: true
363 * util.isRegExp(new RegExp('another regexp'));
364 * // Returns: true
365 * util.isRegExp({});
366 * // Returns: false
367 * ```
368 * @since v0.6.0
369 * @deprecated Since v4.0.0 - Deprecated
370 */
371 export function isRegExp(object: unknown): object is RegExp;
372 /**
373 * Returns `true` if the given `object` is a `Date`. Otherwise, returns `false`.
374 *
375 * ```js
376 * const util = require('util');
377 *
378 * util.isDate(new Date());
379 * // Returns: true
380 * util.isDate(Date());
381 * // false (without 'new' returns a String)
382 * util.isDate({});
383 * // Returns: false
384 * ```
385 * @since v0.6.0
386 * @deprecated Since v4.0.0 - Use {@link types.isDate} instead.
387 */
388 export function isDate(object: unknown): object is Date;
389 /**
390 * Returns `true` if the given `object` is an `Error`. Otherwise, returns`false`.
391 *
392 * ```js
393 * const util = require('util');
394 *
395 * util.isError(new Error());
396 * // Returns: true
397 * util.isError(new TypeError());
398 * // Returns: true
399 * util.isError({ name: 'Error', message: 'an error occurred' });
400 * // Returns: false
401 * ```
402 *
403 * This method relies on `Object.prototype.toString()` behavior. It is
404 * possible to obtain an incorrect result when the `object` argument manipulates`@@toStringTag`.
405 *
406 * ```js
407 * const util = require('util');
408 * const obj = { name: 'Error', message: 'an error occurred' };
409 *
410 * util.isError(obj);
411 * // Returns: false
412 * obj[Symbol.toStringTag] = 'Error';
413 * util.isError(obj);
414 * // Returns: true
415 * ```
416 * @since v0.6.0
417 * @deprecated Since v4.0.0 - Use {@link types.isNativeError} instead.
418 */
419 export function isError(object: unknown): object is Error;
420 /**
421 * Usage of `util.inherits()` is discouraged. Please use the ES6 `class` and`extends` keywords to get language level inheritance support. Also note
422 * that the two styles are [semantically incompatible](https://github.com/nodejs/node/issues/4179).
423 *
424 * Inherit the prototype methods from one [constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor) into another. The
425 * prototype of `constructor` will be set to a new object created from`superConstructor`.
426 *
427 * This mainly adds some input validation on top of`Object.setPrototypeOf(constructor.prototype, superConstructor.prototype)`.
428 * As an additional convenience, `superConstructor` will be accessible
429 * through the `constructor.super_` property.
430 *
431 * ```js
432 * const util = require('util');
433 * const EventEmitter = require('events');
434 *
435 * function MyStream() {
436 * EventEmitter.call(this);
437 * }
438 *
439 * util.inherits(MyStream, EventEmitter);
440 *
441 * MyStream.prototype.write = function(data) {
442 * this.emit('data', data);
443 * };
444 *
445 * const stream = new MyStream();
446 *
447 * console.log(stream instanceof EventEmitter); // true
448 * console.log(MyStream.super_ === EventEmitter); // true
449 *
450 * stream.on('data', (data) => {
451 * console.log(`Received data: "${data}"`);
452 * });
453 * stream.write('It works!'); // Received data: "It works!"
454 * ```
455 *
456 * ES6 example using `class` and `extends`:
457 *
458 * ```js
459 * const EventEmitter = require('events');
460 *
461 * class MyStream extends EventEmitter {
462 * write(data) {
463 * this.emit('data', data);
464 * }
465 * }
466 *
467 * const stream = new MyStream();
468 *
469 * stream.on('data', (data) => {
470 * console.log(`Received data: "${data}"`);
471 * });
472 * stream.write('With ES6');
473 * ```
474 * @since v0.3.0
475 * @deprecated Legacy: Use ES2015 class syntax and `extends` keyword instead.
476 */
477 export function inherits(constructor: unknown, superConstructor: unknown): void;
478 export type DebugLoggerFunction = (msg: string, ...param: unknown[]) => void;
479 export interface DebugLogger extends DebugLoggerFunction {
480 enabled: boolean;
481 }
482 /**
483 * The `util.debuglog()` method is used to create a function that conditionally
484 * 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
485 * environment variable, then the returned function operates similar to `console.error()`. If not, then the returned function is a no-op.
486 *
487 * ```js
488 * const util = require('util');
489 * const debuglog = util.debuglog('foo');
490 *
491 * debuglog('hello from foo [%d]', 123);
492 * ```
493 *
494 * If this program is run with `NODE_DEBUG=foo` in the environment, then
495 * it will output something like:
496 *
497 * ```console
498 * FOO 3245: hello from foo [123]
499 * ```
500 *
501 * where `3245` is the process id. If it is not run with that
502 * environment variable set, then it will not print anything.
503 *
504 * The `section` supports wildcard also:
505 *
506 * ```js
507 * const util = require('util');
508 * const debuglog = util.debuglog('foo-bar');
509 *
510 * debuglog('hi there, it\'s foo-bar [%d]', 2333);
511 * ```
512 *
513 * if it is run with `NODE_DEBUG=foo*` in the environment, then it will output
514 * something like:
515 *
516 * ```console
517 * FOO-BAR 3257: hi there, it's foo-bar [2333]
518 * ```
519 *
520 * Multiple comma-separated `section` names may be specified in the `NODE_DEBUG`environment variable: `NODE_DEBUG=fs,net,tls`.
521 *
522 * The optional `callback` argument can be used to replace the logging function
523 * with a different function that doesn't have any initialization or
524 * unnecessary wrapping.
525 *
526 * ```js
527 * const util = require('util');
528 * let debuglog = util.debuglog('internals', (debug) => {
529 * // Replace with a logging function that optimizes out
530 * // testing if the section is enabled
531 * debuglog = debug;
532 * });
533 * ```
534 * @since v0.11.3
535 * @param section A string identifying the portion of the application for which the `debuglog` function is being created.
536 * @param callback A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function.
537 * @return The logging function
538 */
539 export function debuglog(section: string, callback?: (fn: DebugLoggerFunction) => void): DebugLogger;
540 export const debug: typeof debuglog;
541 /**
542 * Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`.
543 *
544 * ```js
545 * const util = require('util');
546 *
547 * util.isBoolean(1);
548 * // Returns: false
549 * util.isBoolean(0);
550 * // Returns: false
551 * util.isBoolean(false);
552 * // Returns: true
553 * ```
554 * @since v0.11.5
555 * @deprecated Since v4.0.0 - Use `typeof value === 'boolean'` instead.
556 */
557 export function isBoolean(object: unknown): object is boolean;
558 /**
559 * Returns `true` if the given `object` is a `Buffer`. Otherwise, returns `false`.
560 *
561 * ```js
562 * const util = require('util');
563 *
564 * util.isBuffer({ length: 0 });
565 * // Returns: false
566 * util.isBuffer([]);
567 * // Returns: false
568 * util.isBuffer(Buffer.from('hello world'));
569 * // Returns: true
570 * ```
571 * @since v0.11.5
572 * @deprecated Since v4.0.0 - Use `isBuffer` instead.
573 */
574 export function isBuffer(object: unknown): object is Buffer;
575 /**
576 * Returns `true` if the given `object` is a `Function`. Otherwise, returns`false`.
577 *
578 * ```js
579 * const util = require('util');
580 *
581 * function Foo() {}
582 * const Bar = () => {};
583 *
584 * util.isFunction({});
585 * // Returns: false
586 * util.isFunction(Foo);
587 * // Returns: true
588 * util.isFunction(Bar);
589 * // Returns: true
590 * ```
591 * @since v0.11.5
592 * @deprecated Since v4.0.0 - Use `typeof value === 'function'` instead.
593 */
594 export function isFunction(object: unknown): boolean;
595 /**
596 * Returns `true` if the given `object` is strictly `null`. Otherwise, returns`false`.
597 *
598 * ```js
599 * const util = require('util');
600 *
601 * util.isNull(0);
602 * // Returns: false
603 * util.isNull(undefined);
604 * // Returns: false
605 * util.isNull(null);
606 * // Returns: true
607 * ```
608 * @since v0.11.5
609 * @deprecated Since v4.0.0 - Use `value === null` instead.
610 */
611 export function isNull(object: unknown): object is null;
612 /**
613 * Returns `true` if the given `object` is `null` or `undefined`. Otherwise,
614 * returns `false`.
615 *
616 * ```js
617 * const util = require('util');
618 *
619 * util.isNullOrUndefined(0);
620 * // Returns: false
621 * util.isNullOrUndefined(undefined);
622 * // Returns: true
623 * util.isNullOrUndefined(null);
624 * // Returns: true
625 * ```
626 * @since v0.11.5
627 * @deprecated Since v4.0.0 - Use `value === undefined || value === null` instead.
628 */
629 export function isNullOrUndefined(object: unknown): object is null | undefined;
630 /**
631 * Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`.
632 *
633 * ```js
634 * const util = require('util');
635 *
636 * util.isNumber(false);
637 * // Returns: false
638 * util.isNumber(Infinity);
639 * // Returns: true
640 * util.isNumber(0);
641 * // Returns: true
642 * util.isNumber(NaN);
643 * // Returns: true
644 * ```
645 * @since v0.11.5
646 * @deprecated Since v4.0.0 - Use `typeof value === 'number'` instead.
647 */
648 export function isNumber(object: unknown): object is number;
649 /**
650 * Returns `true` if the given `object` is strictly an `Object`**and** not a`Function` (even though functions are objects in JavaScript).
651 * Otherwise, returns `false`.
652 *
653 * ```js
654 * const util = require('util');
655 *
656 * util.isObject(5);
657 * // Returns: false
658 * util.isObject(null);
659 * // Returns: false
660 * util.isObject({});
661 * // Returns: true
662 * util.isObject(() => {});
663 * // Returns: false
664 * ```
665 * @since v0.11.5
666 * @deprecated Since v4.0.0 - Deprecated: Use `value !== null && typeof value === 'object'` instead.
667 */
668 export function isObject(object: unknown): boolean;
669 /**
670 * Returns `true` if the given `object` is a primitive type. Otherwise, returns`false`.
671 *
672 * ```js
673 * const util = require('util');
674 *
675 * util.isPrimitive(5);
676 * // Returns: true
677 * util.isPrimitive('foo');
678 * // Returns: true
679 * util.isPrimitive(false);
680 * // Returns: true
681 * util.isPrimitive(null);
682 * // Returns: true
683 * util.isPrimitive(undefined);
684 * // Returns: true
685 * util.isPrimitive({});
686 * // Returns: false
687 * util.isPrimitive(() => {});
688 * // Returns: false
689 * util.isPrimitive(/^$/);
690 * // Returns: false
691 * util.isPrimitive(new Date());
692 * // Returns: false
693 * ```
694 * @since v0.11.5
695 * @deprecated Since v4.0.0 - Use `(typeof value !== 'object' && typeof value !== 'function') || value === null` instead.
696 */
697 export function isPrimitive(object: unknown): boolean;
698 /**
699 * Returns `true` if the given `object` is a `string`. Otherwise, returns `false`.
700 *
701 * ```js
702 * const util = require('util');
703 *
704 * util.isString('');
705 * // Returns: true
706 * util.isString('foo');
707 * // Returns: true
708 * util.isString(String('foo'));
709 * // Returns: true
710 * util.isString(5);
711 * // Returns: false
712 * ```
713 * @since v0.11.5
714 * @deprecated Since v4.0.0 - Use `typeof value === 'string'` instead.
715 */
716 export function isString(object: unknown): object is string;
717 /**
718 * Returns `true` if the given `object` is a `Symbol`. Otherwise, returns `false`.
719 *
720 * ```js
721 * const util = require('util');
722 *
723 * util.isSymbol(5);
724 * // Returns: false
725 * util.isSymbol('foo');
726 * // Returns: false
727 * util.isSymbol(Symbol('foo'));
728 * // Returns: true
729 * ```
730 * @since v0.11.5
731 * @deprecated Since v4.0.0 - Use `typeof value === 'symbol'` instead.
732 */
733 export function isSymbol(object: unknown): object is symbol;
734 /**
735 * Returns `true` if the given `object` is `undefined`. Otherwise, returns `false`.
736 *
737 * ```js
738 * const util = require('util');
739 *
740 * const foo = undefined;
741 * util.isUndefined(5);
742 * // Returns: false
743 * util.isUndefined(foo);
744 * // Returns: true
745 * util.isUndefined(null);
746 * // Returns: false
747 * ```
748 * @since v0.11.5
749 * @deprecated Since v4.0.0 - Use `value === undefined` instead.
750 */
751 export function isUndefined(object: unknown): object is undefined;
752 /**
753 * The `util.deprecate()` method wraps `fn` (which may be a function or class) in
754 * such a way that it is marked as deprecated.
755 *
756 * ```js
757 * const util = require('util');
758 *
759 * exports.obsoleteFunction = util.deprecate(() => {
760 * // Do something here.
761 * }, 'obsoleteFunction() is deprecated. Use newShinyFunction() instead.');
762 * ```
763 *
764 * When called, `util.deprecate()` will return a function that will emit a`DeprecationWarning` using the `'warning'` event. The warning will
765 * be emitted and printed to `stderr` the first time the returned function is
766 * called. After the warning is emitted, the wrapped function is called without
767 * emitting a warning.
768 *
769 * If the same optional `code` is supplied in multiple calls to `util.deprecate()`,
770 * the warning will be emitted only once for that `code`.
771 *
772 * ```js
773 * const util = require('util');
774 *
775 * const fn1 = util.deprecate(someFunction, someMessage, 'DEP0001');
776 * const fn2 = util.deprecate(someOtherFunction, someOtherMessage, 'DEP0001');
777 * fn1(); // Emits a deprecation warning with code DEP0001
778 * fn2(); // Does not emit a deprecation warning because it has the same code
779 * ```
780 *
781 * If either the `--no-deprecation` or `--no-warnings` command-line flags are
782 * used, or if the `process.noDeprecation` property is set to `true`_prior_ to
783 * the first deprecation warning, the `util.deprecate()` method does nothing.
784 *
785 * If the `--trace-deprecation` or `--trace-warnings` command-line flags are set,
786 * or the `process.traceDeprecation` property is set to `true`, a warning and a
787 * stack trace are printed to `stderr` the first time the deprecated function is
788 * called.
789 *
790 * If the `--throw-deprecation` command-line flag is set, or the`process.throwDeprecation` property is set to `true`, then an exception will be
791 * thrown when the deprecated function is called.
792 *
793 * The `--throw-deprecation` command-line flag and `process.throwDeprecation`property take precedence over `--trace-deprecation` and`process.traceDeprecation`.
794 * @since v0.8.0
795 * @param fn The function that is being deprecated.
796 * @param msg A warning message to display when the deprecated function is invoked.
797 * @param code A deprecation code. See the `list of deprecated APIs` for a list of codes.
798 * @return The deprecated function wrapped to emit a warning.
799 */
800 export function deprecate<T extends Function>(fn: T, msg: string, code?: string): T;
801 /**
802 * Returns `true` if there is deep strict equality between `val1` and `val2`.
803 * Otherwise, returns `false`.
804 *
805 * See `assert.deepStrictEqual()` for more information about deep strict
806 * equality.
807 * @since v9.0.0
808 */
809 export function isDeepStrictEqual(val1: unknown, val2: unknown): boolean;
810 /**
811 * Returns `str` with any ANSI escape codes removed.
812 *
813 * ```js
814 * console.log(util.stripVTControlCharacters('\u001B[4mvalue\u001B[0m'));
815 * // Prints "value"
816 * ```
817 * @since v16.11.0
818 */
819 export function stripVTControlCharacters(str: string): string;
820 /**
821 * Takes an `async` function (or a function that returns a `Promise`) and returns a
822 * function following the error-first callback style, i.e. taking
823 * an `(err, value) => ...` callback as the last argument. In the callback, the
824 * first argument will be the rejection reason (or `null` if the `Promise`resolved), and the second argument will be the resolved value.
825 *
826 * ```js
827 * const util = require('util');
828 *
829 * async function fn() {
830 * return 'hello world';
831 * }
832 * const callbackFunction = util.callbackify(fn);
833 *
834 * callbackFunction((err, ret) => {
835 * if (err) throw err;
836 * console.log(ret);
837 * });
838 * ```
839 *
840 * Will print:
841 *
842 * ```text
843 * hello world
844 * ```
845 *
846 * The callback is executed asynchronously, and will have a limited stack trace.
847 * If the callback throws, the process will emit an `'uncaughtException'` event, and if not handled will exit.
848 *
849 * Since `null` has a special meaning as the first argument to a callback, if a
850 * wrapped function rejects a `Promise` with a falsy value as a reason, the value
851 * is wrapped in an `Error` with the original value stored in a field named`reason`.
852 *
853 * ```js
854 * function fn() {
855 * return Promise.reject(null);
856 * }
857 * const callbackFunction = util.callbackify(fn);
858 *
859 * callbackFunction((err, ret) => {
860 * // When the Promise was rejected with `null` it is wrapped with an Error and
861 * // the original value is stored in `reason`.
862 * err &#x26;&#x26; err.hasOwnProperty('reason') &#x26;&#x26; err.reason === null; // true
863 * });
864 * ```
865 * @since v8.2.0
866 * @param original An `async` function
867 * @return a callback style function
868 */
869 export function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
870 export function callbackify<TResult>(fn: () => Promise<TResult>): (callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
871 export function callbackify<T1>(fn: (arg1: T1) => Promise<void>): (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void;
872 export function callbackify<T1, TResult>(fn: (arg1: T1) => Promise<TResult>): (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
873 export function callbackify<T1, T2>(fn: (arg1: T1, arg2: T2) => Promise<void>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void;
874 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;
875 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;
876 export function callbackify<T1, T2, T3, TResult>(
877 fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>
878 ): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
879 export function callbackify<T1, T2, T3, T4>(
880 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>
881 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException) => void) => void;
882 export function callbackify<T1, T2, T3, T4, TResult>(
883 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>
884 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
885 export function callbackify<T1, T2, T3, T4, T5>(
886 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>
887 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException) => void) => void;
888 export function callbackify<T1, T2, T3, T4, T5, TResult>(
889 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>
890 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
891 export function callbackify<T1, T2, T3, T4, T5, T6>(
892 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<void>
893 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException) => void) => void;
894 export function callbackify<T1, T2, T3, T4, T5, T6, TResult>(
895 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<TResult>
896 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
897 export interface CustomPromisifyLegacy<TCustom extends Function> extends Function {
898 __promisify__: TCustom;
899 }
900 export interface CustomPromisifySymbol<TCustom extends Function> extends Function {
901 [promisify.custom]: TCustom;
902 }
903 export type CustomPromisify<TCustom extends Function> = CustomPromisifySymbol<TCustom> | CustomPromisifyLegacy<TCustom>;
904 /**
905 * Takes a function following the common error-first callback style, i.e. taking
906 * an `(err, value) => ...` callback as the last argument, and returns a version
907 * that returns promises.
908 *
909 * ```js
910 * const util = require('util');
911 * const fs = require('fs');
912 *
913 * const stat = util.promisify(fs.stat);
914 * stat('.').then((stats) => {
915 * // Do something with `stats`
916 * }).catch((error) => {
917 * // Handle the error.
918 * });
919 * ```
920 *
921 * Or, equivalently using `async function`s:
922 *
923 * ```js
924 * const util = require('util');
925 * const fs = require('fs');
926 *
927 * const stat = util.promisify(fs.stat);
928 *
929 * async function callStat() {
930 * const stats = await stat('.');
931 * console.log(`This directory is owned by ${stats.uid}`);
932 * }
933 * ```
934 *
935 * If there is an `original[util.promisify.custom]` property present, `promisify`will return its value, see `Custom promisified functions`.
936 *
937 * `promisify()` assumes that `original` is a function taking a callback as its
938 * 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
939 * an error-first callback, it will still be passed an error-first
940 * callback as its last argument.
941 *
942 * Using `promisify()` on class methods or other methods that use `this` may not
943 * work as expected unless handled specially:
944 *
945 * ```js
946 * const util = require('util');
947 *
948 * class Foo {
949 * constructor() {
950 * this.a = 42;
951 * }
952 *
953 * bar(callback) {
954 * callback(null, this.a);
955 * }
956 * }
957 *
958 * const foo = new Foo();
959 *
960 * const naiveBar = util.promisify(foo.bar);
961 * // TypeError: Cannot read property 'a' of undefined
962 * // naiveBar().then(a => console.log(a));
963 *
964 * naiveBar.call(foo).then((a) => console.log(a)); // '42'
965 *
966 * const bindBar = naiveBar.bind(foo);
967 * bindBar().then((a) => console.log(a)); // '42'
968 * ```
969 * @since v8.0.0
970 */
971 export function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
972 export function promisify<TResult>(fn: (callback: (err: any, result: TResult) => void) => void): () => Promise<TResult>;
973 export function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
974 export function promisify<T1, TResult>(fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void): (arg1: T1) => Promise<TResult>;
975 export function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
976 export function promisify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise<TResult>;
977 export function promisify<T1, T2>(fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2) => Promise<void>;
978 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>;
979 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>;
980 export function promisify<T1, T2, T3, T4, TResult>(
981 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void
982 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
983 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>;
984 export function promisify<T1, T2, T3, T4, T5, TResult>(
985 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void
986 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
987 export function promisify<T1, T2, T3, T4, T5>(
988 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void
989 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
990 export function promisify(fn: Function): Function;
991 export namespace promisify {
992 /**
993 * That can be used to declare custom promisified variants of functions.
994 */
995 const custom: unique symbol;
996 }
997 /**
998 * An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextDecoder` API.
999 *
1000 * ```js
1001 * const decoder = new TextDecoder('shift_jis');
1002 * let string = '';
1003 * let buffer;
1004 * while (buffer = getNextChunkSomehow()) {
1005 * string += decoder.decode(buffer, { stream: true });
1006 * }
1007 * string += decoder.decode(); // end-of-stream
1008 * ```
1009 * @since v8.3.0
1010 */
1011 export class TextDecoder {
1012 /**
1013 * The encoding supported by the `TextDecoder` instance.
1014 */
1015 readonly encoding: string;
1016 /**
1017 * The value will be `true` if decoding errors result in a `TypeError` being
1018 * thrown.
1019 */
1020 readonly fatal: boolean;
1021 /**
1022 * The value will be `true` if the decoding result will include the byte order
1023 * mark.
1024 */
1025 readonly ignoreBOM: boolean;
1026 constructor(
1027 encoding?: string,
1028 options?: {
1029 fatal?: boolean | undefined;
1030 ignoreBOM?: boolean | undefined;
1031 }
1032 );
1033 /**
1034 * Decodes the `input` and returns a string. If `options.stream` is `true`, any
1035 * incomplete byte sequences occurring at the end of the `input` are buffered
1036 * internally and emitted after the next call to `textDecoder.decode()`.
1037 *
1038 * If `textDecoder.fatal` is `true`, decoding errors that occur will result in a`TypeError` being thrown.
1039 * @param input An `ArrayBuffer`, `DataView` or `TypedArray` instance containing the encoded data.
1040 */
1041 decode(
1042 input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
1043 options?: {
1044 stream?: boolean | undefined;
1045 }
1046 ): string;
1047 }
1048 export interface EncodeIntoResult {
1049 /**
1050 * The read Unicode code units of input.
1051 */
1052 read: number;
1053 /**
1054 * The written UTF-8 bytes of output.
1055 */
1056 written: number;
1057 }
1058 export { types };
1059 /**
1060 * An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextEncoder` API. All
1061 * instances of `TextEncoder` only support UTF-8 encoding.
1062 *
1063 * ```js
1064 * const encoder = new TextEncoder();
1065 * const uint8array = encoder.encode('this is some data');
1066 * ```
1067 *
1068 * The `TextEncoder` class is also available on the global object.
1069 * @since v8.3.0
1070 */
1071 export class TextEncoder {
1072 /**
1073 * The encoding supported by the `TextEncoder` instance. Always set to `'utf-8'`.
1074 */
1075 readonly encoding: string;
1076 /**
1077 * UTF-8 encodes the `input` string and returns a `Uint8Array` containing the
1078 * encoded bytes.
1079 * @param [input='an empty string'] The text to encode.
1080 */
1081 encode(input?: string): Uint8Array;
1082 /**
1083 * UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object
1084 * containing the read Unicode code units and written UTF-8 bytes.
1085 *
1086 * ```js
1087 * const encoder = new TextEncoder();
1088 * const src = 'this is some data';
1089 * const dest = new Uint8Array(10);
1090 * const { read, written } = encoder.encodeInto(src, dest);
1091 * ```
1092 * @param src The text to encode.
1093 * @param dest The array to hold the encode result.
1094 */
1095 encodeInto(src: string, dest: Uint8Array): EncodeIntoResult;
1096 }
1097}
1098declare module 'util/types' {
1099 export * from 'util/types';
1100}
1101declare module 'util/types' {
1102 import { KeyObject, webcrypto } from 'node:crypto';
1103 /**
1104 * Returns `true` if the value is a built-in [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) or
1105 * [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instance.
1106 *
1107 * See also `util.types.isArrayBuffer()` and `util.types.isSharedArrayBuffer()`.
1108 *
1109 * ```js
1110 * util.types.isAnyArrayBuffer(new ArrayBuffer()); // Returns true
1111 * util.types.isAnyArrayBuffer(new SharedArrayBuffer()); // Returns true
1112 * ```
1113 * @since v10.0.0
1114 */
1115 function isAnyArrayBuffer(object: unknown): object is ArrayBufferLike;
1116 /**
1117 * Returns `true` if the value is an `arguments` object.
1118 *
1119 * ```js
1120 * function foo() {
1121 * util.types.isArgumentsObject(arguments); // Returns true
1122 * }
1123 * ```
1124 * @since v10.0.0
1125 */
1126 function isArgumentsObject(object: unknown): object is IArguments;
1127 /**
1128 * Returns `true` if the value is a built-in [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) instance.
1129 * This does _not_ include [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances. Usually, it is
1130 * desirable to test for both; See `util.types.isAnyArrayBuffer()` for that.
1131 *
1132 * ```js
1133 * util.types.isArrayBuffer(new ArrayBuffer()); // Returns true
1134 * util.types.isArrayBuffer(new SharedArrayBuffer()); // Returns false
1135 * ```
1136 * @since v10.0.0
1137 */
1138 function isArrayBuffer(object: unknown): object is ArrayBuffer;
1139 /**
1140 * 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
1141 * array objects or [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView). Equivalent to
1142 * [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
1143 *
1144 * ```js
1145 * util.types.isArrayBufferView(new Int8Array()); // true
1146 * util.types.isArrayBufferView(Buffer.from('hello world')); // true
1147 * util.types.isArrayBufferView(new DataView(new ArrayBuffer(16))); // true
1148 * util.types.isArrayBufferView(new ArrayBuffer()); // false
1149 * ```
1150 * @since v10.0.0
1151 */
1152 function isArrayBufferView(object: unknown): object is NodeJS.ArrayBufferView;
1153 /**
1154 * Returns `true` if the value is an [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).
1155 * This only reports back what the JavaScript engine is seeing;
1156 * in particular, the return value may not match the original source code if
1157 * a transpilation tool was used.
1158 *
1159 * ```js
1160 * util.types.isAsyncFunction(function foo() {}); // Returns false
1161 * util.types.isAsyncFunction(async function foo() {}); // Returns true
1162 * ```
1163 * @since v10.0.0
1164 */
1165 function isAsyncFunction(object: unknown): boolean;
1166 /**
1167 * Returns `true` if the value is a `BigInt64Array` instance.
1168 *
1169 * ```js
1170 * util.types.isBigInt64Array(new BigInt64Array()); // Returns true
1171 * util.types.isBigInt64Array(new BigUint64Array()); // Returns false
1172 * ```
1173 * @since v10.0.0
1174 */
1175 function isBigInt64Array(value: unknown): value is BigInt64Array;
1176 /**
1177 * Returns `true` if the value is a `BigUint64Array` instance.
1178 *
1179 * ```js
1180 * util.types.isBigUint64Array(new BigInt64Array()); // Returns false
1181 * util.types.isBigUint64Array(new BigUint64Array()); // Returns true
1182 * ```
1183 * @since v10.0.0
1184 */
1185 function isBigUint64Array(value: unknown): value is BigUint64Array;
1186 /**
1187 * Returns `true` if the value is a boolean object, e.g. created
1188 * by `new Boolean()`.
1189 *
1190 * ```js
1191 * util.types.isBooleanObject(false); // Returns false
1192 * util.types.isBooleanObject(true); // Returns false
1193 * util.types.isBooleanObject(new Boolean(false)); // Returns true
1194 * util.types.isBooleanObject(new Boolean(true)); // Returns true
1195 * util.types.isBooleanObject(Boolean(false)); // Returns false
1196 * util.types.isBooleanObject(Boolean(true)); // Returns false
1197 * ```
1198 * @since v10.0.0
1199 */
1200 function isBooleanObject(object: unknown): object is Boolean;
1201 /**
1202 * Returns `true` if the value is any boxed primitive object, e.g. created
1203 * by `new Boolean()`, `new String()` or `Object(Symbol())`.
1204 *
1205 * For example:
1206 *
1207 * ```js
1208 * util.types.isBoxedPrimitive(false); // Returns false
1209 * util.types.isBoxedPrimitive(new Boolean(false)); // Returns true
1210 * util.types.isBoxedPrimitive(Symbol('foo')); // Returns false
1211 * util.types.isBoxedPrimitive(Object(Symbol('foo'))); // Returns true
1212 * util.types.isBoxedPrimitive(Object(BigInt(5))); // Returns true
1213 * ```
1214 * @since v10.11.0
1215 */
1216 function isBoxedPrimitive(object: unknown): object is String | Number | BigInt | Boolean | Symbol;
1217 /**
1218 * Returns `true` if the value is a built-in [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) instance.
1219 *
1220 * ```js
1221 * const ab = new ArrayBuffer(20);
1222 * util.types.isDataView(new DataView(ab)); // Returns true
1223 * util.types.isDataView(new Float64Array()); // Returns false
1224 * ```
1225 *
1226 * See also [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
1227 * @since v10.0.0
1228 */
1229 function isDataView(object: unknown): object is DataView;
1230 /**
1231 * Returns `true` if the value is a built-in [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance.
1232 *
1233 * ```js
1234 * util.types.isDate(new Date()); // Returns true
1235 * ```
1236 * @since v10.0.0
1237 */
1238 function isDate(object: unknown): object is Date;
1239 /**
1240 * Returns `true` if the value is a native `External` value.
1241 *
1242 * A native `External` value is a special type of object that contains a
1243 * raw C++ pointer (`void*`) for access from native code, and has no other
1244 * properties. Such objects are created either by Node.js internals or native
1245 * 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.
1246 *
1247 * ```c
1248 * #include <js_native_api.h>
1249 * #include <stdlib.h>
1250 * napi_value result;
1251 * static napi_value MyNapi(napi_env env, napi_callback_info info) {
1252 * int* raw = (int*) malloc(1024);
1253 * napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &#x26;result);
1254 * if (status != napi_ok) {
1255 * napi_throw_error(env, NULL, "napi_create_external failed");
1256 * return NULL;
1257 * }
1258 * return result;
1259 * }
1260 * ...
1261 * DECLARE_NAPI_PROPERTY("myNapi", MyNapi)
1262 * ...
1263 * ```
1264 *
1265 * ```js
1266 * const native = require('napi_addon.node');
1267 * const data = native.myNapi();
1268 * util.types.isExternal(data); // returns true
1269 * util.types.isExternal(0); // returns false
1270 * util.types.isExternal(new String('foo')); // returns false
1271 * ```
1272 *
1273 * For further information on `napi_create_external`, refer to `napi_create_external()`.
1274 * @since v10.0.0
1275 */
1276 function isExternal(object: unknown): boolean;
1277 /**
1278 * Returns `true` if the value is a built-in [`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array) instance.
1279 *
1280 * ```js
1281 * util.types.isFloat32Array(new ArrayBuffer()); // Returns false
1282 * util.types.isFloat32Array(new Float32Array()); // Returns true
1283 * util.types.isFloat32Array(new Float64Array()); // Returns false
1284 * ```
1285 * @since v10.0.0
1286 */
1287 function isFloat32Array(object: unknown): object is Float32Array;
1288 /**
1289 * Returns `true` if the value is a built-in [`Float64Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array) instance.
1290 *
1291 * ```js
1292 * util.types.isFloat64Array(new ArrayBuffer()); // Returns false
1293 * util.types.isFloat64Array(new Uint8Array()); // Returns false
1294 * util.types.isFloat64Array(new Float64Array()); // Returns true
1295 * ```
1296 * @since v10.0.0
1297 */
1298 function isFloat64Array(object: unknown): object is Float64Array;
1299 /**
1300 * Returns `true` if the value is a generator function.
1301 * This only reports back what the JavaScript engine is seeing;
1302 * in particular, the return value may not match the original source code if
1303 * a transpilation tool was used.
1304 *
1305 * ```js
1306 * util.types.isGeneratorFunction(function foo() {}); // Returns false
1307 * util.types.isGeneratorFunction(function* foo() {}); // Returns true
1308 * ```
1309 * @since v10.0.0
1310 */
1311 function isGeneratorFunction(object: unknown): object is GeneratorFunction;
1312 /**
1313 * Returns `true` if the value is a generator object as returned from a
1314 * built-in generator function.
1315 * This only reports back what the JavaScript engine is seeing;
1316 * in particular, the return value may not match the original source code if
1317 * a transpilation tool was used.
1318 *
1319 * ```js
1320 * function* foo() {}
1321 * const generator = foo();
1322 * util.types.isGeneratorObject(generator); // Returns true
1323 * ```
1324 * @since v10.0.0
1325 */
1326 function isGeneratorObject(object: unknown): object is Generator;
1327 /**
1328 * Returns `true` if the value is a built-in [`Int8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array) instance.
1329 *
1330 * ```js
1331 * util.types.isInt8Array(new ArrayBuffer()); // Returns false
1332 * util.types.isInt8Array(new Int8Array()); // Returns true
1333 * util.types.isInt8Array(new Float64Array()); // Returns false
1334 * ```
1335 * @since v10.0.0
1336 */
1337 function isInt8Array(object: unknown): object is Int8Array;
1338 /**
1339 * Returns `true` if the value is a built-in [`Int16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array) instance.
1340 *
1341 * ```js
1342 * util.types.isInt16Array(new ArrayBuffer()); // Returns false
1343 * util.types.isInt16Array(new Int16Array()); // Returns true
1344 * util.types.isInt16Array(new Float64Array()); // Returns false
1345 * ```
1346 * @since v10.0.0
1347 */
1348 function isInt16Array(object: unknown): object is Int16Array;
1349 /**
1350 * Returns `true` if the value is a built-in [`Int32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array) instance.
1351 *
1352 * ```js
1353 * util.types.isInt32Array(new ArrayBuffer()); // Returns false
1354 * util.types.isInt32Array(new Int32Array()); // Returns true
1355 * util.types.isInt32Array(new Float64Array()); // Returns false
1356 * ```
1357 * @since v10.0.0
1358 */
1359 function isInt32Array(object: unknown): object is Int32Array;
1360 /**
1361 * Returns `true` if the value is a built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance.
1362 *
1363 * ```js
1364 * util.types.isMap(new Map()); // Returns true
1365 * ```
1366 * @since v10.0.0
1367 */
1368 function isMap<T>(object: T | {}): object is T extends ReadonlyMap<any, any> ? (unknown extends T ? never : ReadonlyMap<any, any>) : Map<unknown, unknown>;
1369 /**
1370 * 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.
1371 *
1372 * ```js
1373 * const map = new Map();
1374 * util.types.isMapIterator(map.keys()); // Returns true
1375 * util.types.isMapIterator(map.values()); // Returns true
1376 * util.types.isMapIterator(map.entries()); // Returns true
1377 * util.types.isMapIterator(map[Symbol.iterator]()); // Returns true
1378 * ```
1379 * @since v10.0.0
1380 */
1381 function isMapIterator(object: unknown): boolean;
1382 /**
1383 * Returns `true` if the value is an instance of a [Module Namespace Object](https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects).
1384 *
1385 * ```js
1386 * import * as ns from './a.js';
1387 *
1388 * util.types.isModuleNamespaceObject(ns); // Returns true
1389 * ```
1390 * @since v10.0.0
1391 */
1392 function isModuleNamespaceObject(value: unknown): boolean;
1393 /**
1394 * Returns `true` if the value is an instance of a built-in `Error` type.
1395 *
1396 * ```js
1397 * util.types.isNativeError(new Error()); // Returns true
1398 * util.types.isNativeError(new TypeError()); // Returns true
1399 * util.types.isNativeError(new RangeError()); // Returns true
1400 * ```
1401 * @since v10.0.0
1402 */
1403 function isNativeError(object: unknown): object is Error;
1404 /**
1405 * Returns `true` if the value is a number object, e.g. created
1406 * by `new Number()`.
1407 *
1408 * ```js
1409 * util.types.isNumberObject(0); // Returns false
1410 * util.types.isNumberObject(new Number(0)); // Returns true
1411 * ```
1412 * @since v10.0.0
1413 */
1414 function isNumberObject(object: unknown): object is Number;
1415 /**
1416 * Returns `true` if the value is a built-in [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
1417 *
1418 * ```js
1419 * util.types.isPromise(Promise.resolve(42)); // Returns true
1420 * ```
1421 * @since v10.0.0
1422 */
1423 function isPromise(object: unknown): object is Promise<unknown>;
1424 /**
1425 * Returns `true` if the value is a [`Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) instance.
1426 *
1427 * ```js
1428 * const target = {};
1429 * const proxy = new Proxy(target, {});
1430 * util.types.isProxy(target); // Returns false
1431 * util.types.isProxy(proxy); // Returns true
1432 * ```
1433 * @since v10.0.0
1434 */
1435 function isProxy(object: unknown): boolean;
1436 /**
1437 * Returns `true` if the value is a regular expression object.
1438 *
1439 * ```js
1440 * util.types.isRegExp(/abc/); // Returns true
1441 * util.types.isRegExp(new RegExp('abc')); // Returns true
1442 * ```
1443 * @since v10.0.0
1444 */
1445 function isRegExp(object: unknown): object is RegExp;
1446 /**
1447 * Returns `true` if the value is a built-in [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance.
1448 *
1449 * ```js
1450 * util.types.isSet(new Set()); // Returns true
1451 * ```
1452 * @since v10.0.0
1453 */
1454 function isSet<T>(object: T | {}): object is T extends ReadonlySet<any> ? (unknown extends T ? never : ReadonlySet<any>) : Set<unknown>;
1455 /**
1456 * 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.
1457 *
1458 * ```js
1459 * const set = new Set();
1460 * util.types.isSetIterator(set.keys()); // Returns true
1461 * util.types.isSetIterator(set.values()); // Returns true
1462 * util.types.isSetIterator(set.entries()); // Returns true
1463 * util.types.isSetIterator(set[Symbol.iterator]()); // Returns true
1464 * ```
1465 * @since v10.0.0
1466 */
1467 function isSetIterator(object: unknown): boolean;
1468 /**
1469 * Returns `true` if the value is a built-in [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instance.
1470 * This does _not_ include [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) instances. Usually, it is
1471 * desirable to test for both; See `util.types.isAnyArrayBuffer()` for that.
1472 *
1473 * ```js
1474 * util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false
1475 * util.types.isSharedArrayBuffer(new SharedArrayBuffer()); // Returns true
1476 * ```
1477 * @since v10.0.0
1478 */
1479 function isSharedArrayBuffer(object: unknown): object is SharedArrayBuffer;
1480 /**
1481 * Returns `true` if the value is a string object, e.g. created
1482 * by `new String()`.
1483 *
1484 * ```js
1485 * util.types.isStringObject('foo'); // Returns false
1486 * util.types.isStringObject(new String('foo')); // Returns true
1487 * ```
1488 * @since v10.0.0
1489 */
1490 function isStringObject(object: unknown): object is String;
1491 /**
1492 * Returns `true` if the value is a symbol object, created
1493 * by calling `Object()` on a `Symbol` primitive.
1494 *
1495 * ```js
1496 * const symbol = Symbol('foo');
1497 * util.types.isSymbolObject(symbol); // Returns false
1498 * util.types.isSymbolObject(Object(symbol)); // Returns true
1499 * ```
1500 * @since v10.0.0
1501 */
1502 function isSymbolObject(object: unknown): object is Symbol;
1503 /**
1504 * Returns `true` if the value is a built-in [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) instance.
1505 *
1506 * ```js
1507 * util.types.isTypedArray(new ArrayBuffer()); // Returns false
1508 * util.types.isTypedArray(new Uint8Array()); // Returns true
1509 * util.types.isTypedArray(new Float64Array()); // Returns true
1510 * ```
1511 *
1512 * See also [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
1513 * @since v10.0.0
1514 */
1515 function isTypedArray(object: unknown): object is NodeJS.TypedArray;
1516 /**
1517 * Returns `true` if the value is a built-in [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) instance.
1518 *
1519 * ```js
1520 * util.types.isUint8Array(new ArrayBuffer()); // Returns false
1521 * util.types.isUint8Array(new Uint8Array()); // Returns true
1522 * util.types.isUint8Array(new Float64Array()); // Returns false
1523 * ```
1524 * @since v10.0.0
1525 */
1526 function isUint8Array(object: unknown): object is Uint8Array;
1527 /**
1528 * Returns `true` if the value is a built-in [`Uint8ClampedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) instance.
1529 *
1530 * ```js
1531 * util.types.isUint8ClampedArray(new ArrayBuffer()); // Returns false
1532 * util.types.isUint8ClampedArray(new Uint8ClampedArray()); // Returns true
1533 * util.types.isUint8ClampedArray(new Float64Array()); // Returns false
1534 * ```
1535 * @since v10.0.0
1536 */
1537 function isUint8ClampedArray(object: unknown): object is Uint8ClampedArray;
1538 /**
1539 * Returns `true` if the value is a built-in [`Uint16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array) instance.
1540 *
1541 * ```js
1542 * util.types.isUint16Array(new ArrayBuffer()); // Returns false
1543 * util.types.isUint16Array(new Uint16Array()); // Returns true
1544 * util.types.isUint16Array(new Float64Array()); // Returns false
1545 * ```
1546 * @since v10.0.0
1547 */
1548 function isUint16Array(object: unknown): object is Uint16Array;
1549 /**
1550 * Returns `true` if the value is a built-in [`Uint32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array) instance.
1551 *
1552 * ```js
1553 * util.types.isUint32Array(new ArrayBuffer()); // Returns false
1554 * util.types.isUint32Array(new Uint32Array()); // Returns true
1555 * util.types.isUint32Array(new Float64Array()); // Returns false
1556 * ```
1557 * @since v10.0.0
1558 */
1559 function isUint32Array(object: unknown): object is Uint32Array;
1560 /**
1561 * Returns `true` if the value is a built-in [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) instance.
1562 *
1563 * ```js
1564 * util.types.isWeakMap(new WeakMap()); // Returns true
1565 * ```
1566 * @since v10.0.0
1567 */
1568 function isWeakMap(object: unknown): object is WeakMap<object, unknown>;
1569 /**
1570 * Returns `true` if the value is a built-in [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) instance.
1571 *
1572 * ```js
1573 * util.types.isWeakSet(new WeakSet()); // Returns true
1574 * ```
1575 * @since v10.0.0
1576 */
1577 function isWeakSet(object: unknown): object is WeakSet<object>;
1578 /**
1579 * Returns `true` if `value` is a `KeyObject`, `false` otherwise.
1580 * @since v16.2.0
1581 */
1582 function isKeyObject(object: unknown): object is KeyObject;
1583 /**
1584 * Returns `true` if `value` is a `CryptoKey`, `false` otherwise.
1585 * @since v16.2.0
1586 */
1587 function isCryptoKey(object: unknown): object is webcrypto.CryptoKey;
1588}
1589declare module 'node:util' {
1590 export * from 'util';
1591}
1592declare module 'node:util/types' {
1593 export * from 'util/types';
1594}