lts/doc/api/util.json
{
"type": "module",
"source": "doc/api/util.md",
"modules": [
{
"textRaw": "Util",
"name": "util",
"introduced_in": "v0.10.0",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p>The <code>util</code> module supports the needs of Node.js internal APIs. Many of the\nutilities are useful for application and module developers as well. To access\nit:</p>\n<pre><code class=\"language-js\">const util = require('util');\n</code></pre>",
"methods": [
{
"textRaw": "`util.callbackify(original)`",
"type": "method",
"name": "callbackify",
"meta": {
"added": [
"v8.2.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Function} a callback style function",
"name": "return",
"type": "Function",
"desc": "a callback style function"
},
"params": [
{
"textRaw": "`original` {Function} An `async` function",
"name": "original",
"type": "Function",
"desc": "An `async` function"
}
]
}
],
"desc": "<p>Takes an <code>async</code> function (or a function that returns a <code>Promise</code>) and returns a\nfunction following the error-first callback style, i.e. taking\nan <code>(err, value) => ...</code> callback as the last argument. In the callback, the\nfirst argument will be the rejection reason (or <code>null</code> if the <code>Promise</code>\nresolved), and the second argument will be the resolved value.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nasync function fn() {\n return 'hello world';\n}\nconst callbackFunction = util.callbackify(fn);\n\ncallbackFunction((err, ret) => {\n if (err) throw err;\n console.log(ret);\n});\n</code></pre>\n<p>Will print:</p>\n<pre><code class=\"language-text\">hello world\n</code></pre>\n<p>The callback is executed asynchronously, and will have a limited stack trace.\nIf the callback throws, the process will emit an <a href=\"process.html#process_event_uncaughtexception\"><code>'uncaughtException'</code></a>\nevent, and if not handled will exit.</p>\n<p>Since <code>null</code> has a special meaning as the first argument to a callback, if a\nwrapped function rejects a <code>Promise</code> with a falsy value as a reason, the value\nis wrapped in an <code>Error</code> with the original value stored in a field named\n<code>reason</code>.</p>\n<pre><code class=\"language-js\">function fn() {\n return Promise.reject(null);\n}\nconst callbackFunction = util.callbackify(fn);\n\ncallbackFunction((err, ret) => {\n // When the Promise was rejected with `null` it is wrapped with an Error and\n // the original value is stored in `reason`.\n err && err.hasOwnProperty('reason') && err.reason === null; // true\n});\n</code></pre>"
},
{
"textRaw": "`util.debuglog(section)`",
"type": "method",
"name": "debuglog",
"meta": {
"added": [
"v0.11.3"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Function} The logging function",
"name": "return",
"type": "Function",
"desc": "The logging function"
},
"params": [
{
"textRaw": "`section` {string} A string identifying the portion of the application for which the `debuglog` function is being created.",
"name": "section",
"type": "string",
"desc": "A string identifying the portion of the application for which the `debuglog` function is being created."
}
]
}
],
"desc": "<p>The <code>util.debuglog()</code> method is used to create a function that conditionally\nwrites debug messages to <code>stderr</code> based on the existence of the <code>NODE_DEBUG</code>\nenvironment variable. If the <code>section</code> name appears within the value of that\nenvironment variable, then the returned function operates similar to\n<a href=\"console.html#console_console_error_data_args\"><code>console.error()</code></a>. If not, then the returned function is a no-op.</p>\n<pre><code class=\"language-js\">const util = require('util');\nconst debuglog = util.debuglog('foo');\n\ndebuglog('hello from foo [%d]', 123);\n</code></pre>\n<p>If this program is run with <code>NODE_DEBUG=foo</code> in the environment, then\nit will output something like:</p>\n<pre><code class=\"language-console\">FOO 3245: hello from foo [123]\n</code></pre>\n<p>where <code>3245</code> is the process id. If it is not run with that\nenvironment variable set, then it will not print anything.</p>\n<p>The <code>section</code> supports wildcard also:</p>\n<pre><code class=\"language-js\">const util = require('util');\nconst debuglog = util.debuglog('foo-bar');\n\ndebuglog('hi there, it\\'s foo-bar [%d]', 2333);\n</code></pre>\n<p>if it is run with <code>NODE_DEBUG=foo*</code> in the environment, then it will output\nsomething like:</p>\n<pre><code class=\"language-console\">FOO-BAR 3257: hi there, it's foo-bar [2333]\n</code></pre>\n<p>Multiple comma-separated <code>section</code> names may be specified in the <code>NODE_DEBUG</code>\nenvironment variable: <code>NODE_DEBUG=fs,net,tls</code>.</p>"
},
{
"textRaw": "`util.deprecate(fn, msg[, code])`",
"type": "method",
"name": "deprecate",
"meta": {
"added": [
"v0.8.0"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/16393",
"description": "Deprecation warnings are only emitted once for each code."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Function} The deprecated function wrapped to emit a warning.",
"name": "return",
"type": "Function",
"desc": "The deprecated function wrapped to emit a warning."
},
"params": [
{
"textRaw": "`fn` {Function} The function that is being deprecated.",
"name": "fn",
"type": "Function",
"desc": "The function that is being deprecated."
},
{
"textRaw": "`msg` {string} A warning message to display when the deprecated function is invoked.",
"name": "msg",
"type": "string",
"desc": "A warning message to display when the deprecated function is invoked."
},
{
"textRaw": "`code` {string} A deprecation code. See the [list of deprecated APIs][] for a list of codes.",
"name": "code",
"type": "string",
"desc": "A deprecation code. See the [list of deprecated APIs][] for a list of codes."
}
]
}
],
"desc": "<p>The <code>util.deprecate()</code> method wraps <code>fn</code> (which may be a function or class) in\nsuch a way that it is marked as deprecated.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nexports.obsoleteFunction = util.deprecate(() => {\n // Do something here.\n}, 'obsoleteFunction() is deprecated. Use newShinyFunction() instead.');\n</code></pre>\n<p>When called, <code>util.deprecate()</code> will return a function that will emit a\n<code>DeprecationWarning</code> using the <a href=\"process.html#process_event_warning\"><code>'warning'</code></a> event. The warning will\nbe emitted and printed to <code>stderr</code> the first time the returned function is\ncalled. After the warning is emitted, the wrapped function is called without\nemitting a warning.</p>\n<p>If the same optional <code>code</code> is supplied in multiple calls to <code>util.deprecate()</code>,\nthe warning will be emitted only once for that <code>code</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nconst fn1 = util.deprecate(someFunction, someMessage, 'DEP0001');\nconst fn2 = util.deprecate(someOtherFunction, someOtherMessage, 'DEP0001');\nfn1(); // Emits a deprecation warning with code DEP0001\nfn2(); // Does not emit a deprecation warning because it has the same code\n</code></pre>\n<p>If either the <code>--no-deprecation</code> or <code>--no-warnings</code> command line flags are\nused, or if the <code>process.noDeprecation</code> property is set to <code>true</code> <em>prior</em> to\nthe first deprecation warning, the <code>util.deprecate()</code> method does nothing.</p>\n<p>If the <code>--trace-deprecation</code> or <code>--trace-warnings</code> command line flags are set,\nor the <code>process.traceDeprecation</code> property is set to <code>true</code>, a warning and a\nstack trace are printed to <code>stderr</code> the first time the deprecated function is\ncalled.</p>\n<p>If the <code>--throw-deprecation</code> command line flag is set, or the\n<code>process.throwDeprecation</code> property is set to <code>true</code>, then an exception will be\nthrown when the deprecated function is called.</p>\n<p>The <code>--throw-deprecation</code> command line flag and <code>process.throwDeprecation</code>\nproperty take precedence over <code>--trace-deprecation</code> and\n<code>process.traceDeprecation</code>.</p>"
},
{
"textRaw": "`util.format(format[, ...args])`",
"type": "method",
"name": "format",
"meta": {
"added": [
"v0.5.3"
],
"changes": [
{
"version": "v12.11.0",
"pr-url": "https://github.com/nodejs/node/pull/29606",
"description": "The `%c` specifier is ignored now."
},
{
"version": "v11.4.0",
"pr-url": "https://github.com/nodejs/node/pull/23708",
"description": "The `%d`, `%f` and `%i` specifiers now support Symbols properly."
},
{
"version": "v12.0.0",
"pr-url": "https://github.com/nodejs/node/pull/23162",
"description": "The `format` argument is now only taken as such if it actually contains format specifiers."
},
{
"version": "v12.0.0",
"pr-url": "https://github.com/nodejs/node/pull/23162",
"description": "If the `format` argument is not a format string, the output string's formatting is no longer dependent on the type of the first argument. This change removes previously present quotes from strings that were being output when the first argument was not a string."
},
{
"version": "v11.4.0",
"pr-url": "https://github.com/nodejs/node/pull/24806",
"description": "The `%o` specifier's `depth` has default depth of 4 again."
},
{
"version": "v11.0.0",
"pr-url": "https://github.com/nodejs/node/pull/17907",
"description": "The `%o` specifier's `depth` option will now fall back to the default depth."
},
{
"version": "v10.12.0",
"pr-url": "https://github.com/nodejs/node/pull/22097",
"description": "The `%d` and `%i` specifiers now support BigInt."
},
{
"version": "v8.4.0",
"pr-url": "https://github.com/nodejs/node/pull/14558",
"description": "The `%o` and `%O` specifiers are supported now."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`format` {string} A `printf`-like format string.",
"name": "format",
"type": "string",
"desc": "A `printf`-like format string."
}
]
}
],
"desc": "<p>The <code>util.format()</code> method returns a formatted string using the first argument\nas a <code>printf</code>-like format string which can contain zero or more format\nspecifiers. Each specifier is replaced with the converted value from the\ncorresponding argument. Supported specifiers are:</p>\n<ul>\n<li><code>%s</code>: <code>String</code> will be used to convert all values except <code>BigInt</code>, <code>Object</code>\nand <code>-0</code>. <code>BigInt</code> values will be represented with an <code>n</code> and Objects that\nhave no user defined <code>toString</code> function are inspected using <code>util.inspect()</code>\nwith options <code>{ depth: 0, colors: false, compact: 3 }</code>.</li>\n<li><code>%d</code>: <code>Number</code> will be used to convert all values except <code>BigInt</code> and\n<code>Symbol</code>.</li>\n<li><code>%i</code>: <code>parseInt(value, 10)</code> is used for all values except <code>BigInt</code> and\n<code>Symbol</code>.</li>\n<li><code>%f</code>: <code>parseFloat(value)</code> is used for all values expect <code>Symbol</code>.</li>\n<li><code>%j</code>: JSON. Replaced with the string <code>'[Circular]'</code> if the argument contains\ncircular references.</li>\n<li><code>%o</code>: <code>Object</code>. A string representation of an object with generic JavaScript\nobject formatting. Similar to <code>util.inspect()</code> with options\n<code>{ showHidden: true, showProxy: true }</code>. This will show the full object\nincluding non-enumerable properties and proxies.</li>\n<li><code>%O</code>: <code>Object</code>. A string representation of an object with generic JavaScript\nobject formatting. Similar to <code>util.inspect()</code> without options. This will show\nthe full object not including non-enumerable properties and proxies.</li>\n<li><code>%c</code>: <code>CSS</code>. This specifier is ignored and will skip any CSS passed in.</li>\n<li><code>%%</code>: single percent sign (<code>'%'</code>). This does not consume an argument.</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a> The formatted string</li>\n</ul>\n<p>If a specifier does not have a corresponding argument, it is not replaced:</p>\n<pre><code class=\"language-js\">util.format('%s:%s', 'foo');\n// Returns: 'foo:%s'\n</code></pre>\n<p>Values that are not part of the format string are formatted using\n<code>util.inspect()</code> if their type is not <code>string</code>.</p>\n<p>If there are more arguments passed to the <code>util.format()</code> method than the\nnumber of specifiers, the extra arguments are concatenated to the returned\nstring, separated by spaces:</p>\n<pre><code class=\"language-js\">util.format('%s:%s', 'foo', 'bar', 'baz');\n// Returns: 'foo:bar baz'\n</code></pre>\n<p>If the first argument does not contain a valid format specifier, <code>util.format()</code>\nreturns a string that is the concatenation of all arguments separated by spaces:</p>\n<pre><code class=\"language-js\">util.format(1, 2, 3);\n// Returns: '1 2 3'\n</code></pre>\n<p>If only one argument is passed to <code>util.format()</code>, it is returned as it is\nwithout any formatting:</p>\n<pre><code class=\"language-js\">util.format('%% %s');\n// Returns: '%% %s'\n</code></pre>\n<p><code>util.format()</code> is a synchronous method that is intended as a debugging tool.\nSome input values can have a significant performance overhead that can block the\nevent loop. Use this function with care and never in a hot code path.</p>"
},
{
"textRaw": "`util.formatWithOptions(inspectOptions, format[, ...args])`",
"type": "method",
"name": "formatWithOptions",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`inspectOptions` {Object}",
"name": "inspectOptions",
"type": "Object"
},
{
"textRaw": "`format` {string}",
"name": "format",
"type": "string"
}
]
}
],
"desc": "<p>This function is identical to <a href=\"#util_util_format_format_args\"><code>util.format()</code></a>, except in that it takes\nan <code>inspectOptions</code> argument which specifies options that are passed along to\n<a href=\"#util_util_inspect_object_options\"><code>util.inspect()</code></a>.</p>\n<pre><code class=\"language-js\">util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 });\n// Returns 'See object { foo: 42 }', where `42` is colored as a number\n// when printed to a terminal.\n</code></pre>"
},
{
"textRaw": "`util.getSystemErrorName(err)`",
"type": "method",
"name": "getSystemErrorName",
"meta": {
"added": [
"v9.7.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {string}",
"name": "return",
"type": "string"
},
"params": [
{
"textRaw": "`err` {number}",
"name": "err",
"type": "number"
}
]
}
],
"desc": "<p>Returns the string name for a numeric error code that comes from a Node.js API.\nThe mapping between error codes and error names is platform-dependent.\nSee <a href=\"errors.html#errors_common_system_errors\">Common System Errors</a> for the names of common errors.</p>\n<pre><code class=\"language-js\">fs.access('file/that/does/not/exist', (err) => {\n const name = util.getSystemErrorName(err.errno);\n console.error(name); // ENOENT\n});\n</code></pre>"
},
{
"textRaw": "`util.inherits(constructor, superConstructor)`",
"type": "method",
"name": "inherits",
"meta": {
"added": [
"v0.3.0"
],
"changes": [
{
"version": "v5.0.0",
"pr-url": "https://github.com/nodejs/node/pull/3455",
"description": "The `constructor` parameter can refer to an ES6 class now."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`constructor` {Function}",
"name": "constructor",
"type": "Function"
},
{
"textRaw": "`superConstructor` {Function}",
"name": "superConstructor",
"type": "Function"
}
]
}
],
"desc": "<p>Usage of <code>util.inherits()</code> is discouraged. Please use the ES6 <code>class</code> and\n<code>extends</code> keywords to get language level inheritance support. Also note\nthat the two styles are <a href=\"https://github.com/nodejs/node/issues/4179\">semantically incompatible</a>.</p>\n<p>Inherit the prototype methods from one <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor\">constructor</a> into another. The\nprototype of <code>constructor</code> will be set to a new object created from\n<code>superConstructor</code>.</p>\n<p>This mainly adds some input validation on top of\n<code>Object.setPrototypeOf(constructor.prototype, superConstructor.prototype)</code>.\nAs an additional convenience, <code>superConstructor</code> will be accessible\nthrough the <code>constructor.super_</code> property.</p>\n<pre><code class=\"language-js\">const util = require('util');\nconst EventEmitter = require('events');\n\nfunction MyStream() {\n EventEmitter.call(this);\n}\n\nutil.inherits(MyStream, EventEmitter);\n\nMyStream.prototype.write = function(data) {\n this.emit('data', data);\n};\n\nconst stream = new MyStream();\n\nconsole.log(stream instanceof EventEmitter); // true\nconsole.log(MyStream.super_ === EventEmitter); // true\n\nstream.on('data', (data) => {\n console.log(`Received data: \"${data}\"`);\n});\nstream.write('It works!'); // Received data: \"It works!\"\n</code></pre>\n<p>ES6 example using <code>class</code> and <code>extends</code>:</p>\n<pre><code class=\"language-js\">const EventEmitter = require('events');\n\nclass MyStream extends EventEmitter {\n write(data) {\n this.emit('data', data);\n }\n}\n\nconst stream = new MyStream();\n\nstream.on('data', (data) => {\n console.log(`Received data: \"${data}\"`);\n});\nstream.write('With ES6');\n</code></pre>"
},
{
"textRaw": "`util.inspect(object[, options])`",
"type": "method",
"name": "inspect",
"meta": {
"added": [
"v0.3.0"
],
"changes": [
{
"version": "v12.17.0",
"pr-url": "https://github.com/nodejs/node/pull/32392",
"description": "The `maxStringLength` option is supported now."
},
{
"version": "v12.16.0",
"pr-url": "https://github.com/nodejs/node/pull/30768",
"description": "User defined prototype properties are inspected in case `showHidden` is `true`."
},
{
"version": "v12.0.0",
"pr-url": "https://github.com/nodejs/node/pull/27109",
"description": "The `compact` options default is changed to `3` and the `breakLength` options default is changed to `80`."
},
{
"version": "v11.11.0",
"pr-url": "https://github.com/nodejs/node/pull/26269",
"description": "The `compact` option accepts numbers for a new output mode."
},
{
"version": "v12.0.0",
"pr-url": "https://github.com/nodejs/node/pull/24971",
"description": "Internal properties no longer appear in the context argument of a custom inspection function."
},
{
"version": "v11.7.0",
"pr-url": "https://github.com/nodejs/node/pull/25006",
"description": "ArrayBuffers now also show their binary contents."
},
{
"version": "v11.5.0",
"pr-url": "https://github.com/nodejs/node/pull/24852",
"description": "The `getters` option is supported now."
},
{
"version": "v11.4.0",
"pr-url": "https://github.com/nodejs/node/pull/24326",
"description": "The `depth` default changed back to `2`."
},
{
"version": "v11.0.0",
"pr-url": "https://github.com/nodejs/node/pull/22846",
"description": "The `depth` default changed to `20`."
},
{
"version": "v10.12.0",
"pr-url": "https://github.com/nodejs/node/pull/22788",
"description": "The `sorted` option is supported now."
},
{
"version": "v11.0.0",
"pr-url": "https://github.com/nodejs/node/pull/22756",
"description": "The inspection output is now limited to about 128 MB. Data above that size will not be fully inspected."
},
{
"version": "v10.6.0",
"pr-url": "https://github.com/nodejs/node/pull/20725",
"description": "Inspecting linked lists and similar objects is now possible up to the maximum call stack size."
},
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/19259",
"description": "The `WeakMap` and `WeakSet` entries can now be inspected as well."
},
{
"version": "v9.9.0",
"pr-url": "https://github.com/nodejs/node/pull/17576",
"description": "The `compact` option is supported now."
},
{
"version": "v6.6.0",
"pr-url": "https://github.com/nodejs/node/pull/8174",
"description": "Custom inspection functions can now return `this`."
},
{
"version": "v6.3.0",
"pr-url": "https://github.com/nodejs/node/pull/7499",
"description": "The `breakLength` option is supported now."
},
{
"version": "v6.1.0",
"pr-url": "https://github.com/nodejs/node/pull/6334",
"description": "The `maxArrayLength` option is supported now; in particular, long arrays are truncated by default."
},
{
"version": "v6.1.0",
"pr-url": "https://github.com/nodejs/node/pull/6465",
"description": "The `showProxy` option is supported now."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {string} The representation of `object`.",
"name": "return",
"type": "string",
"desc": "The representation of `object`."
},
"params": [
{
"textRaw": "`object` {any} Any JavaScript primitive or `Object`.",
"name": "object",
"type": "any",
"desc": "Any JavaScript primitive or `Object`."
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`showHidden` {boolean} If `true`, `object`'s non-enumerable symbols and properties are included in the formatted result. [`WeakMap`][] and [`WeakSet`][] entries are also included as well as user defined prototype properties (excluding method properties). **Default:** `false`.",
"name": "showHidden",
"type": "boolean",
"default": "`false`",
"desc": "If `true`, `object`'s non-enumerable symbols and properties are included in the formatted result. [`WeakMap`][] and [`WeakSet`][] entries are also included as well as user defined prototype properties (excluding method properties)."
},
{
"textRaw": "`depth` {number} Specifies the number of times to recurse while formatting `object`. This is useful for inspecting large objects. To recurse up to the maximum call stack size pass `Infinity` or `null`. **Default:** `2`.",
"name": "depth",
"type": "number",
"default": "`2`",
"desc": "Specifies the number of times to recurse while formatting `object`. This is useful for inspecting large objects. To recurse up to the maximum call stack size pass `Infinity` or `null`."
},
{
"textRaw": "`colors` {boolean} If `true`, the output is styled with ANSI color codes. Colors are customizable. See [Customizing `util.inspect` colors][]. **Default:** `false`.",
"name": "colors",
"type": "boolean",
"default": "`false`",
"desc": "If `true`, the output is styled with ANSI color codes. Colors are customizable. See [Customizing `util.inspect` colors][]."
},
{
"textRaw": "`customInspect` {boolean} If `false`, `[util.inspect.custom](depth, opts)` functions are not invoked. **Default:** `true`.",
"name": "customInspect",
"type": "boolean",
"default": "`true`",
"desc": "If `false`, `[util.inspect.custom](depth, opts)` functions are not invoked."
},
{
"textRaw": "`showProxy` {boolean} If `true`, `Proxy` inspection includes the [`target` and `handler`][] objects. **Default:** `false`.",
"name": "showProxy",
"type": "boolean",
"default": "`false`",
"desc": "If `true`, `Proxy` inspection includes the [`target` and `handler`][] objects."
},
{
"textRaw": "`maxArrayLength` {integer} Specifies the maximum number of `Array`, [`TypedArray`][], [`WeakMap`][] and [`WeakSet`][] elements to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no elements. **Default:** `100`.",
"name": "maxArrayLength",
"type": "integer",
"default": "`100`",
"desc": "Specifies the maximum number of `Array`, [`TypedArray`][], [`WeakMap`][] and [`WeakSet`][] elements to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no elements."
},
{
"textRaw": "`maxStringLength` {integer} Specifies the maximum number of characters to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no characters. **Default:** `Infinity`.",
"name": "maxStringLength",
"type": "integer",
"default": "`Infinity`",
"desc": "Specifies the maximum number of characters to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no characters."
},
{
"textRaw": "`breakLength` {integer} The length at which input values are split across multiple lines. Set to `Infinity` to format the input as a single line (in combination with `compact` set to `true` or any number >= `1`). **Default:** `80`.",
"name": "breakLength",
"type": "integer",
"default": "`80`",
"desc": "The length at which input values are split across multiple lines. Set to `Infinity` to format the input as a single line (in combination with `compact` set to `true` or any number >= `1`)."
},
{
"textRaw": "`compact` {boolean|integer} Setting this to `false` causes each object key to be displayed on a new line. It will also add new lines to text that is longer than `breakLength`. If set to a number, the most `n` inner elements are united on a single line as long as all properties fit into `breakLength`. Short array elements are also grouped together. No text will be reduced below 16 characters, no matter the `breakLength` size. For more information, see the example below. **Default:** `3`.",
"name": "compact",
"type": "boolean|integer",
"default": "`3`",
"desc": "Setting this to `false` causes each object key to be displayed on a new line. It will also add new lines to text that is longer than `breakLength`. If set to a number, the most `n` inner elements are united on a single line as long as all properties fit into `breakLength`. Short array elements are also grouped together. No text will be reduced below 16 characters, no matter the `breakLength` size. For more information, see the example below."
},
{
"textRaw": "`sorted` {boolean|Function} If set to `true` or a function, all properties of an object, and `Set` and `Map` entries are sorted in the resulting string. If set to `true` the [default sort][] is used. If set to a function, it is used as a [compare function][].",
"name": "sorted",
"type": "boolean|Function",
"desc": "If set to `true` or a function, all properties of an object, and `Set` and `Map` entries are sorted in the resulting string. If set to `true` the [default sort][] is used. If set to a function, it is used as a [compare function][]."
},
{
"textRaw": "`getters` {boolean|string} If set to `true`, getters are inspected. If set to `'get'`, only getters without a corresponding setter are inspected. If set to `'set'`, only getters with a corresponding setter are inspected. This might cause side effects depending on the getter function. **Default:** `false`.",
"name": "getters",
"type": "boolean|string",
"default": "`false`",
"desc": "If set to `true`, getters are inspected. If set to `'get'`, only getters without a corresponding setter are inspected. If set to `'set'`, only getters with a corresponding setter are inspected. This might cause side effects depending on the getter function."
}
]
}
]
}
],
"desc": "<p>The <code>util.inspect()</code> method returns a string representation of <code>object</code> that is\nintended for debugging. The output of <code>util.inspect</code> may change at any time\nand should not be depended upon programmatically. Additional <code>options</code> may be\npassed that alter the result.\n<code>util.inspect()</code> will use the constructor's name and/or <code>@@toStringTag</code> to make\nan identifiable tag for an inspected value.</p>\n<pre><code class=\"language-js\">class Foo {\n get [Symbol.toStringTag]() {\n return 'bar';\n }\n}\n\nclass Bar {}\n\nconst baz = Object.create(null, { [Symbol.toStringTag]: { value: 'foo' } });\n\nutil.inspect(new Foo()); // 'Foo [bar] {}'\nutil.inspect(new Bar()); // 'Bar {}'\nutil.inspect(baz); // '[foo] {}'\n</code></pre>\n<p>Circular references are marked as <code>'[Circular]'</code>:</p>\n<pre><code class=\"language-js\">const { inspect } = require('util');\n\nconst obj = {};\nobj.a = [obj];\nobj.b = {};\nobj.b.inner = obj.b;\nobj.b.obj = obj;\n\nconsole.log(inspect(obj));\n// {\n// a: [ [Circular] ],\n// b: { inner: [Circular], obj: [Circular] }\n// }\n</code></pre>\n<p>The following example inspects all properties of the <code>util</code> object:</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nconsole.log(util.inspect(util, { showHidden: true, depth: null }));\n</code></pre>\n<p>The following example highlights the effect of the <code>compact</code> option:</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nconst o = {\n a: [1, 2, [[\n 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ' +\n 'eiusmod tempor incididunt ut labore et dolore magna aliqua.',\n 'test',\n 'foo']], 4],\n b: new Map([['za', 1], ['zb', 'test']])\n};\nconsole.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));\n\n// { a:\n// [ 1,\n// 2,\n// [ [ 'Lorem ipsum dolor sit amet, consectetur [...]', // A long line\n// 'test',\n// 'foo' ] ],\n// 4 ],\n// b: Map { 'za' => 1, 'zb' => 'test' } }\n\n// Setting `compact` to false changes the output to be more reader friendly.\nconsole.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 }));\n\n// {\n// a: [\n// 1,\n// 2,\n// [\n// [\n// 'Lorem ipsum dolor sit amet, consectetur ' +\n// 'adipiscing elit, sed do eiusmod tempor ' +\n// 'incididunt ut labore et dolore magna ' +\n// 'aliqua.,\n// 'test',\n// 'foo'\n// ]\n// ],\n// 4\n// ],\n// b: Map {\n// 'za' => 1,\n// 'zb' => 'test'\n// }\n// }\n\n// Setting `breakLength` to e.g. 150 will print the \"Lorem ipsum\" text in a\n// single line.\n// Reducing the `breakLength` will split the \"Lorem ipsum\" text in smaller\n// chunks.\n</code></pre>\n<p>The <code>showHidden</code> option allows <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap\"><code>WeakMap</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet\"><code>WeakSet</code></a> entries to be\ninspected. If there are more entries than <code>maxArrayLength</code>, there is no\nguarantee which entries are displayed. That means retrieving the same\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet\"><code>WeakSet</code></a> entries twice may result in different output. Furthermore, entries\nwith no remaining strong references may be garbage collected at any time.</p>\n<pre><code class=\"language-js\">const { inspect } = require('util');\n\nconst obj = { a: 1 };\nconst obj2 = { b: 2 };\nconst weakSet = new WeakSet([obj, obj2]);\n\nconsole.log(inspect(weakSet, { showHidden: true }));\n// WeakSet { { a: 1 }, { b: 2 } }\n</code></pre>\n<p>The <code>sorted</code> option ensures that an object's property insertion order does not\nimpact the result of <code>util.inspect()</code>.</p>\n<pre><code class=\"language-js\">const { inspect } = require('util');\nconst assert = require('assert');\n\nconst o1 = {\n b: [2, 3, 1],\n a: '`a` comes before `b`',\n c: new Set([2, 3, 1])\n};\nconsole.log(inspect(o1, { sorted: true }));\n// { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set { 1, 2, 3 } }\nconsole.log(inspect(o1, { sorted: (a, b) => b.localeCompare(a) }));\n// { c: Set { 3, 2, 1 }, b: [ 2, 3, 1 ], a: '`a` comes before `b`' }\n\nconst o2 = {\n c: new Set([2, 1, 3]),\n a: '`a` comes before `b`',\n b: [2, 3, 1]\n};\nassert.strict.equal(\n inspect(o1, { sorted: true }),\n inspect(o2, { sorted: true })\n);\n</code></pre>\n<p><code>util.inspect()</code> is a synchronous method intended for debugging. Its maximum\noutput length is approximately 128 MB. Inputs that result in longer output will\nbe truncated.</p>"
},
{
"textRaw": "`util.inspect(object[, showHidden[, depth[, colors]]])`",
"type": "method",
"name": "inspect",
"meta": {
"added": [
"v0.3.0"
],
"changes": [
{
"version": "v12.17.0",
"pr-url": "https://github.com/nodejs/node/pull/32392",
"description": "The `maxStringLength` option is supported now."
},
{
"version": "v12.16.0",
"pr-url": "https://github.com/nodejs/node/pull/30768",
"description": "User defined prototype properties are inspected in case `showHidden` is `true`."
},
{
"version": "v12.0.0",
"pr-url": "https://github.com/nodejs/node/pull/27109",
"description": "The `compact` options default is changed to `3` and the `breakLength` options default is changed to `80`."
},
{
"version": "v11.11.0",
"pr-url": "https://github.com/nodejs/node/pull/26269",
"description": "The `compact` option accepts numbers for a new output mode."
},
{
"version": "v12.0.0",
"pr-url": "https://github.com/nodejs/node/pull/24971",
"description": "Internal properties no longer appear in the context argument of a custom inspection function."
},
{
"version": "v11.7.0",
"pr-url": "https://github.com/nodejs/node/pull/25006",
"description": "ArrayBuffers now also show their binary contents."
},
{
"version": "v11.5.0",
"pr-url": "https://github.com/nodejs/node/pull/24852",
"description": "The `getters` option is supported now."
},
{
"version": "v11.4.0",
"pr-url": "https://github.com/nodejs/node/pull/24326",
"description": "The `depth` default changed back to `2`."
},
{
"version": "v11.0.0",
"pr-url": "https://github.com/nodejs/node/pull/22846",
"description": "The `depth` default changed to `20`."
},
{
"version": "v10.12.0",
"pr-url": "https://github.com/nodejs/node/pull/22788",
"description": "The `sorted` option is supported now."
},
{
"version": "v11.0.0",
"pr-url": "https://github.com/nodejs/node/pull/22756",
"description": "The inspection output is now limited to about 128 MB. Data above that size will not be fully inspected."
},
{
"version": "v10.6.0",
"pr-url": "https://github.com/nodejs/node/pull/20725",
"description": "Inspecting linked lists and similar objects is now possible up to the maximum call stack size."
},
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/19259",
"description": "The `WeakMap` and `WeakSet` entries can now be inspected as well."
},
{
"version": "v9.9.0",
"pr-url": "https://github.com/nodejs/node/pull/17576",
"description": "The `compact` option is supported now."
},
{
"version": "v6.6.0",
"pr-url": "https://github.com/nodejs/node/pull/8174",
"description": "Custom inspection functions can now return `this`."
},
{
"version": "v6.3.0",
"pr-url": "https://github.com/nodejs/node/pull/7499",
"description": "The `breakLength` option is supported now."
},
{
"version": "v6.1.0",
"pr-url": "https://github.com/nodejs/node/pull/6334",
"description": "The `maxArrayLength` option is supported now; in particular, long arrays are truncated by default."
},
{
"version": "v6.1.0",
"pr-url": "https://github.com/nodejs/node/pull/6465",
"description": "The `showProxy` option is supported now."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {string} The representation of `object`.",
"name": "return",
"type": "string",
"desc": "The representation of `object`."
},
"params": [
{
"textRaw": "`object` {any} Any JavaScript primitive or `Object`.",
"name": "object",
"type": "any",
"desc": "Any JavaScript primitive or `Object`."
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`showHidden` {boolean} If `true`, `object`'s non-enumerable symbols and properties are included in the formatted result. [`WeakMap`][] and [`WeakSet`][] entries are also included as well as user defined prototype properties (excluding method properties). **Default:** `false`.",
"name": "showHidden",
"type": "boolean",
"default": "`false`",
"desc": "If `true`, `object`'s non-enumerable symbols and properties are included in the formatted result. [`WeakMap`][] and [`WeakSet`][] entries are also included as well as user defined prototype properties (excluding method properties)."
},
{
"textRaw": "`depth` {number} Specifies the number of times to recurse while formatting `object`. This is useful for inspecting large objects. To recurse up to the maximum call stack size pass `Infinity` or `null`. **Default:** `2`.",
"name": "depth",
"type": "number",
"default": "`2`",
"desc": "Specifies the number of times to recurse while formatting `object`. This is useful for inspecting large objects. To recurse up to the maximum call stack size pass `Infinity` or `null`."
},
{
"textRaw": "`colors` {boolean} If `true`, the output is styled with ANSI color codes. Colors are customizable. See [Customizing `util.inspect` colors][]. **Default:** `false`.",
"name": "colors",
"type": "boolean",
"default": "`false`",
"desc": "If `true`, the output is styled with ANSI color codes. Colors are customizable. See [Customizing `util.inspect` colors][]."
},
{
"textRaw": "`customInspect` {boolean} If `false`, `[util.inspect.custom](depth, opts)` functions are not invoked. **Default:** `true`.",
"name": "customInspect",
"type": "boolean",
"default": "`true`",
"desc": "If `false`, `[util.inspect.custom](depth, opts)` functions are not invoked."
},
{
"textRaw": "`showProxy` {boolean} If `true`, `Proxy` inspection includes the [`target` and `handler`][] objects. **Default:** `false`.",
"name": "showProxy",
"type": "boolean",
"default": "`false`",
"desc": "If `true`, `Proxy` inspection includes the [`target` and `handler`][] objects."
},
{
"textRaw": "`maxArrayLength` {integer} Specifies the maximum number of `Array`, [`TypedArray`][], [`WeakMap`][] and [`WeakSet`][] elements to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no elements. **Default:** `100`.",
"name": "maxArrayLength",
"type": "integer",
"default": "`100`",
"desc": "Specifies the maximum number of `Array`, [`TypedArray`][], [`WeakMap`][] and [`WeakSet`][] elements to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no elements."
},
{
"textRaw": "`maxStringLength` {integer} Specifies the maximum number of characters to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no characters. **Default:** `Infinity`.",
"name": "maxStringLength",
"type": "integer",
"default": "`Infinity`",
"desc": "Specifies the maximum number of characters to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no characters."
},
{
"textRaw": "`breakLength` {integer} The length at which input values are split across multiple lines. Set to `Infinity` to format the input as a single line (in combination with `compact` set to `true` or any number >= `1`). **Default:** `80`.",
"name": "breakLength",
"type": "integer",
"default": "`80`",
"desc": "The length at which input values are split across multiple lines. Set to `Infinity` to format the input as a single line (in combination with `compact` set to `true` or any number >= `1`)."
},
{
"textRaw": "`compact` {boolean|integer} Setting this to `false` causes each object key to be displayed on a new line. It will also add new lines to text that is longer than `breakLength`. If set to a number, the most `n` inner elements are united on a single line as long as all properties fit into `breakLength`. Short array elements are also grouped together. No text will be reduced below 16 characters, no matter the `breakLength` size. For more information, see the example below. **Default:** `3`.",
"name": "compact",
"type": "boolean|integer",
"default": "`3`",
"desc": "Setting this to `false` causes each object key to be displayed on a new line. It will also add new lines to text that is longer than `breakLength`. If set to a number, the most `n` inner elements are united on a single line as long as all properties fit into `breakLength`. Short array elements are also grouped together. No text will be reduced below 16 characters, no matter the `breakLength` size. For more information, see the example below."
},
{
"textRaw": "`sorted` {boolean|Function} If set to `true` or a function, all properties of an object, and `Set` and `Map` entries are sorted in the resulting string. If set to `true` the [default sort][] is used. If set to a function, it is used as a [compare function][].",
"name": "sorted",
"type": "boolean|Function",
"desc": "If set to `true` or a function, all properties of an object, and `Set` and `Map` entries are sorted in the resulting string. If set to `true` the [default sort][] is used. If set to a function, it is used as a [compare function][]."
},
{
"textRaw": "`getters` {boolean|string} If set to `true`, getters are inspected. If set to `'get'`, only getters without a corresponding setter are inspected. If set to `'set'`, only getters with a corresponding setter are inspected. This might cause side effects depending on the getter function. **Default:** `false`.",
"name": "getters",
"type": "boolean|string",
"default": "`false`",
"desc": "If set to `true`, getters are inspected. If set to `'get'`, only getters without a corresponding setter are inspected. If set to `'set'`, only getters with a corresponding setter are inspected. This might cause side effects depending on the getter function."
}
]
}
]
}
],
"desc": "<p>The <code>util.inspect()</code> method returns a string representation of <code>object</code> that is\nintended for debugging. The output of <code>util.inspect</code> may change at any time\nand should not be depended upon programmatically. Additional <code>options</code> may be\npassed that alter the result.\n<code>util.inspect()</code> will use the constructor's name and/or <code>@@toStringTag</code> to make\nan identifiable tag for an inspected value.</p>\n<pre><code class=\"language-js\">class Foo {\n get [Symbol.toStringTag]() {\n return 'bar';\n }\n}\n\nclass Bar {}\n\nconst baz = Object.create(null, { [Symbol.toStringTag]: { value: 'foo' } });\n\nutil.inspect(new Foo()); // 'Foo [bar] {}'\nutil.inspect(new Bar()); // 'Bar {}'\nutil.inspect(baz); // '[foo] {}'\n</code></pre>\n<p>Circular references are marked as <code>'[Circular]'</code>:</p>\n<pre><code class=\"language-js\">const { inspect } = require('util');\n\nconst obj = {};\nobj.a = [obj];\nobj.b = {};\nobj.b.inner = obj.b;\nobj.b.obj = obj;\n\nconsole.log(inspect(obj));\n// {\n// a: [ [Circular] ],\n// b: { inner: [Circular], obj: [Circular] }\n// }\n</code></pre>\n<p>The following example inspects all properties of the <code>util</code> object:</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nconsole.log(util.inspect(util, { showHidden: true, depth: null }));\n</code></pre>\n<p>The following example highlights the effect of the <code>compact</code> option:</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nconst o = {\n a: [1, 2, [[\n 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ' +\n 'eiusmod tempor incididunt ut labore et dolore magna aliqua.',\n 'test',\n 'foo']], 4],\n b: new Map([['za', 1], ['zb', 'test']])\n};\nconsole.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));\n\n// { a:\n// [ 1,\n// 2,\n// [ [ 'Lorem ipsum dolor sit amet, consectetur [...]', // A long line\n// 'test',\n// 'foo' ] ],\n// 4 ],\n// b: Map { 'za' => 1, 'zb' => 'test' } }\n\n// Setting `compact` to false changes the output to be more reader friendly.\nconsole.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 }));\n\n// {\n// a: [\n// 1,\n// 2,\n// [\n// [\n// 'Lorem ipsum dolor sit amet, consectetur ' +\n// 'adipiscing elit, sed do eiusmod tempor ' +\n// 'incididunt ut labore et dolore magna ' +\n// 'aliqua.,\n// 'test',\n// 'foo'\n// ]\n// ],\n// 4\n// ],\n// b: Map {\n// 'za' => 1,\n// 'zb' => 'test'\n// }\n// }\n\n// Setting `breakLength` to e.g. 150 will print the \"Lorem ipsum\" text in a\n// single line.\n// Reducing the `breakLength` will split the \"Lorem ipsum\" text in smaller\n// chunks.\n</code></pre>\n<p>The <code>showHidden</code> option allows <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap\"><code>WeakMap</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet\"><code>WeakSet</code></a> entries to be\ninspected. If there are more entries than <code>maxArrayLength</code>, there is no\nguarantee which entries are displayed. That means retrieving the same\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet\"><code>WeakSet</code></a> entries twice may result in different output. Furthermore, entries\nwith no remaining strong references may be garbage collected at any time.</p>\n<pre><code class=\"language-js\">const { inspect } = require('util');\n\nconst obj = { a: 1 };\nconst obj2 = { b: 2 };\nconst weakSet = new WeakSet([obj, obj2]);\n\nconsole.log(inspect(weakSet, { showHidden: true }));\n// WeakSet { { a: 1 }, { b: 2 } }\n</code></pre>\n<p>The <code>sorted</code> option ensures that an object's property insertion order does not\nimpact the result of <code>util.inspect()</code>.</p>\n<pre><code class=\"language-js\">const { inspect } = require('util');\nconst assert = require('assert');\n\nconst o1 = {\n b: [2, 3, 1],\n a: '`a` comes before `b`',\n c: new Set([2, 3, 1])\n};\nconsole.log(inspect(o1, { sorted: true }));\n// { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set { 1, 2, 3 } }\nconsole.log(inspect(o1, { sorted: (a, b) => b.localeCompare(a) }));\n// { c: Set { 3, 2, 1 }, b: [ 2, 3, 1 ], a: '`a` comes before `b`' }\n\nconst o2 = {\n c: new Set([2, 1, 3]),\n a: '`a` comes before `b`',\n b: [2, 3, 1]\n};\nassert.strict.equal(\n inspect(o1, { sorted: true }),\n inspect(o2, { sorted: true })\n);\n</code></pre>\n<p><code>util.inspect()</code> is a synchronous method intended for debugging. Its maximum\noutput length is approximately 128 MB. Inputs that result in longer output will\nbe truncated.</p>",
"miscs": [
{
"textRaw": "Customizing `util.inspect` colors",
"name": "Customizing `util.inspect` colors",
"type": "misc",
"desc": "<p>Color output (if enabled) of <code>util.inspect</code> is customizable globally\nvia the <code>util.inspect.styles</code> and <code>util.inspect.colors</code> properties.</p>\n<p><code>util.inspect.styles</code> is a map associating a style name to a color from\n<code>util.inspect.colors</code>.</p>\n<p>The default styles and associated colors are:</p>\n<ul>\n<li><code>bigint</code>: <code>yellow</code></li>\n<li><code>boolean</code>: <code>yellow</code></li>\n<li><code>date</code>: <code>magenta</code></li>\n<li><code>module</code>: <code>underline</code></li>\n<li><code>name</code>: (no styling)</li>\n<li><code>null</code>: <code>bold</code></li>\n<li><code>number</code>: <code>yellow</code></li>\n<li><code>regexp</code>: <code>red</code></li>\n<li><code>special</code>: <code>cyan</code> (e.g., <code>Proxies</code>)</li>\n<li><code>string</code>: <code>green</code></li>\n<li><code>symbol</code>: <code>green</code></li>\n<li><code>undefined</code>: <code>grey</code></li>\n</ul>\n<p>Color styling uses ANSI control codes that may not be supported on all\nterminals. To verify color support use <a href=\"tty.html#tty_writestream_hascolors_count_env\"><code>tty.hasColors()</code></a>.</p>\n<p>Predefined control codes are listed below (grouped as \"Modifiers\", \"Foreground\ncolors\", and \"Background colors\").</p>",
"miscs": [
{
"textRaw": "Modifiers",
"name": "modifiers",
"desc": "<p>Modifier support varies throughout different terminals. They will mostly be\nignored, if not supported.</p>\n<ul>\n<li><code>reset</code> - Resets all (color) modifiers to their defaults</li>\n<li><strong>bold</strong> - Make text bold</li>\n<li><em>italic</em> - Make text italic</li>\n<li><span style=\"border-bottom: 1px;\">underline</span> - Make text underlined</li>\n<li><del>strikethrough</del> - Puts a horizontal line through the center of the text\n(Alias: <code>strikeThrough</code>, <code>crossedout</code>, <code>crossedOut</code>)</li>\n<li><code>hidden</code> - Prints the text, but makes it invisible (Alias: conceal)</li>\n<li><span style=\"opacity: 0.5;\">dim</span> - Decreased color intensity (Alias:\n<code>faint</code>)</li>\n<li><span style=\"border-top: 1px\">overlined</span> - Make text overlined</li>\n<li>blink - Hides and shows the text in an interval</li>\n<li><span style=\"filter: invert(100%)\">inverse</span> - Swap foreground and\nbackground colors (Alias: <code>swapcolors</code>, <code>swapColors</code>)</li>\n<li><span style=\"border-bottom: 1px double;\">doubleunderline</span> - Make text\ndouble underlined (Alias: <code>doubleUnderline</code>)</li>\n<li><span style=\"border: 1px\">framed</span> - Draw a frame around the text</li>\n</ul>",
"type": "misc",
"displayName": "Modifiers"
},
{
"textRaw": "Foreground colors",
"name": "foreground_colors",
"desc": "<ul>\n<li><code>black</code></li>\n<li><code>red</code></li>\n<li><code>green</code></li>\n<li><code>yellow</code></li>\n<li><code>blue</code></li>\n<li><code>magenta</code></li>\n<li><code>cyan</code></li>\n<li><code>white</code></li>\n<li><code>gray</code> (alias: <code>grey</code>, <code>blackBright</code>)</li>\n<li><code>redBright</code></li>\n<li><code>greenBright</code></li>\n<li><code>yellowBright</code></li>\n<li><code>blueBright</code></li>\n<li><code>magentaBright</code></li>\n<li><code>cyanBright</code></li>\n<li><code>whiteBright</code></li>\n</ul>",
"type": "misc",
"displayName": "Foreground colors"
},
{
"textRaw": "Background colors",
"name": "background_colors",
"desc": "<ul>\n<li><code>bgBlack</code></li>\n<li><code>bgRed</code></li>\n<li><code>bgGreen</code></li>\n<li><code>bgYellow</code></li>\n<li><code>bgBlue</code></li>\n<li><code>bgMagenta</code></li>\n<li><code>bgCyan</code></li>\n<li><code>bgWhite</code></li>\n<li><code>bgGray</code> (alias: <code>bgGrey</code>, <code>bgBlackBright</code>)</li>\n<li><code>bgRedBright</code></li>\n<li><code>bgGreenBright</code></li>\n<li><code>bgYellowBright</code></li>\n<li><code>bgBlueBright</code></li>\n<li><code>bgMagentaBright</code></li>\n<li><code>bgCyanBright</code></li>\n<li><code>bgWhiteBright</code></li>\n</ul>",
"type": "misc",
"displayName": "Background colors"
}
]
},
{
"textRaw": "Custom inspection functions on objects",
"name": "Custom inspection functions on objects",
"type": "misc",
"desc": "<p>Objects may also define their own\n<a href=\"#util_util_inspect_custom\"><code>[util.inspect.custom](depth, opts)</code></a> function,\nwhich <code>util.inspect()</code> will invoke and use the result of when inspecting\nthe object:</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nclass Box {\n constructor(value) {\n this.value = value;\n }\n\n [util.inspect.custom](depth, options) {\n if (depth < 0) {\n return options.stylize('[Box]', 'special');\n }\n\n const newOptions = Object.assign({}, options, {\n depth: options.depth === null ? null : options.depth - 1\n });\n\n // Five space padding because that's the size of \"Box< \".\n const padding = ' '.repeat(5);\n const inner = util.inspect(this.value, newOptions)\n .replace(/\\n/g, `\\n${padding}`);\n return `${options.stylize('Box', 'special')}< ${inner} >`;\n }\n}\n\nconst box = new Box(true);\n\nutil.inspect(box);\n// Returns: \"Box< true >\"\n</code></pre>\n<p>Custom <code>[util.inspect.custom](depth, opts)</code> functions typically return a string\nbut may return a value of any type that will be formatted accordingly by\n<code>util.inspect()</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nconst obj = { foo: 'this will not show up in the inspect() output' };\nobj[util.inspect.custom] = (depth) => {\n return { bar: 'baz' };\n};\n\nutil.inspect(obj);\n// Returns: \"{ bar: 'baz' }\"\n</code></pre>"
}
],
"properties": [
{
"textRaw": "`custom` {symbol} that can be used to declare custom inspect functions.",
"type": "symbol",
"name": "custom",
"meta": {
"added": [
"v6.6.0"
],
"changes": [
{
"version": "v10.12.0",
"pr-url": "https://github.com/nodejs/node/pull/20857",
"description": "This is now defined as a shared symbol."
}
]
},
"desc": "<p>In addition to being accessible through <code>util.inspect.custom</code>, this\nsymbol is <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for\">registered globally</a> and can be\naccessed in any environment as <code>Symbol.for('nodejs.util.inspect.custom')</code>.</p>\n<pre><code class=\"language-js\">const inspect = Symbol.for('nodejs.util.inspect.custom');\n\nclass Password {\n constructor(value) {\n this.value = value;\n }\n\n toString() {\n return 'xxxxxxxx';\n }\n\n [inspect]() {\n return `Password <${this.toString()}>`;\n }\n}\n\nconst password = new Password('r0sebud');\nconsole.log(password);\n// Prints Password <xxxxxxxx>\n</code></pre>\n<p>See <a href=\"#util_custom_inspection_functions_on_objects\">Custom inspection functions on Objects</a> for more details.</p>",
"shortDesc": "that can be used to declare custom inspect functions."
},
{
"textRaw": "`util.inspect.defaultOptions`",
"name": "defaultOptions",
"meta": {
"added": [
"v6.4.0"
],
"changes": []
},
"desc": "<p>The <code>defaultOptions</code> value allows customization of the default options used by\n<code>util.inspect</code>. This is useful for functions like <code>console.log</code> or\n<code>util.format</code> which implicitly call into <code>util.inspect</code>. It shall be set to an\nobject containing one or more valid <a href=\"#util_util_inspect_object_options\"><code>util.inspect()</code></a> options. Setting\noption properties directly is also supported.</p>\n<pre><code class=\"language-js\">const util = require('util');\nconst arr = Array(101).fill(0);\n\nconsole.log(arr); // Logs the truncated array\nutil.inspect.defaultOptions.maxArrayLength = null;\nconsole.log(arr); // logs the full array\n</code></pre>"
}
]
},
{
"textRaw": "`util.isDeepStrictEqual(val1, val2)`",
"type": "method",
"name": "isDeepStrictEqual",
"meta": {
"added": [
"v9.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`val1` {any}",
"name": "val1",
"type": "any"
},
{
"textRaw": "`val2` {any}",
"name": "val2",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if there is deep strict equality between <code>val1</code> and <code>val2</code>.\nOtherwise, returns <code>false</code>.</p>\n<p>See <a href=\"assert.html#assert_assert_deepstrictequal_actual_expected_message\"><code>assert.deepStrictEqual()</code></a> for more information about deep strict\nequality.</p>"
},
{
"textRaw": "`util.promisify(original)`",
"type": "method",
"name": "promisify",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Function}",
"name": "return",
"type": "Function"
},
"params": [
{
"textRaw": "`original` {Function}",
"name": "original",
"type": "Function"
}
]
}
],
"desc": "<p>Takes a function following the common error-first callback style, i.e. taking\nan <code>(err, value) => ...</code> callback as the last argument, and returns a version\nthat returns promises.</p>\n<pre><code class=\"language-js\">const util = require('util');\nconst fs = require('fs');\n\nconst stat = util.promisify(fs.stat);\nstat('.').then((stats) => {\n // Do something with `stats`\n}).catch((error) => {\n // Handle the error.\n});\n</code></pre>\n<p>Or, equivalently using <code>async function</code>s:</p>\n<pre><code class=\"language-js\">const util = require('util');\nconst fs = require('fs');\n\nconst stat = util.promisify(fs.stat);\n\nasync function callStat() {\n const stats = await stat('.');\n console.log(`This directory is owned by ${stats.uid}`);\n}\n</code></pre>\n<p>If there is an <code>original[util.promisify.custom]</code> property present, <code>promisify</code>\nwill return its value, see <a href=\"#util_custom_promisified_functions\">Custom promisified functions</a>.</p>\n<p><code>promisify()</code> assumes that <code>original</code> is a function taking a callback as its\nfinal argument in all cases. If <code>original</code> is not a function, <code>promisify()</code>\nwill throw an error. If <code>original</code> is a function but its last argument is not\nan error-first callback, it will still be passed an error-first\ncallback as its last argument.</p>\n<p>Using <code>promisify()</code> on class methods or other methods that use <code>this</code> may not\nwork as expected unless handled specially:</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nclass Foo {\n constructor() {\n this.a = 42;\n }\n\n bar(callback) {\n callback(null, this.a);\n }\n}\n\nconst foo = new Foo();\n\nconst naiveBar = util.promisify(foo.bar);\n// TypeError: Cannot read property 'a' of undefined\n// naiveBar().then(a => console.log(a));\n\nnaiveBar.call(foo).then((a) => console.log(a)); // '42'\n\nconst bindBar = naiveBar.bind(foo);\nbindBar().then((a) => console.log(a)); // '42'\n</code></pre>",
"modules": [
{
"textRaw": "Custom promisified functions",
"name": "custom_promisified_functions",
"desc": "<p>Using the <code>util.promisify.custom</code> symbol one can override the return value of\n<a href=\"#util_util_promisify_original\"><code>util.promisify()</code></a>:</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nfunction doSomething(foo, callback) {\n // ...\n}\n\ndoSomething[util.promisify.custom] = (foo) => {\n return getPromiseSomehow();\n};\n\nconst promisified = util.promisify(doSomething);\nconsole.log(promisified === doSomething[util.promisify.custom]);\n// prints 'true'\n</code></pre>\n<p>This can be useful for cases where the original function does not follow the\nstandard format of taking an error-first callback as the last argument.</p>\n<p>For example, with a function that takes in\n<code>(foo, onSuccessCallback, onErrorCallback)</code>:</p>\n<pre><code class=\"language-js\">doSomething[util.promisify.custom] = (foo) => {\n return new Promise((resolve, reject) => {\n doSomething(foo, resolve, reject);\n });\n};\n</code></pre>\n<p>If <code>promisify.custom</code> is defined but is not a function, <code>promisify()</code> will\nthrow an error.</p>",
"type": "module",
"displayName": "Custom promisified functions"
}
],
"properties": [
{
"textRaw": "`custom` {symbol} that can be used to declare custom promisified variants of functions, see [Custom promisified functions][].",
"type": "symbol",
"name": "custom",
"meta": {
"added": [
"v8.0.0"
],
"changes": [
{
"version": "v12.16.2",
"pr-url": "https://github.com/nodejs/node/pull/31672",
"description": "This is now defined as a shared symbol."
}
]
},
"desc": "<p>In addition to being accessible through <code>util.promisify.custom</code>, this\nsymbol is <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for\">registered globally</a> and can be\naccessed in any environment as <code>Symbol.for('nodejs.util.promisify.custom')</code>.</p>\n<p>For example, with a function that takes in\n<code>(foo, onSuccessCallback, onErrorCallback)</code>:</p>\n<pre><code class=\"language-js\">const kCustomPromisifiedSymbol = Symbol.for('nodejs.util.promisify.custom');\n\ndoSomething[kCustomPromisifiedSymbol] = (foo) => {\n return new Promise((resolve, reject) => {\n doSomething(foo, resolve, reject);\n });\n};\n</code></pre>",
"shortDesc": "that can be used to declare custom promisified variants of functions, see [Custom promisified functions][]."
}
]
}
],
"classes": [
{
"textRaw": "Class: `util.TextDecoder`",
"type": "class",
"name": "util.TextDecoder",
"meta": {
"added": [
"v8.3.0"
],
"changes": []
},
"desc": "<p>An implementation of the <a href=\"https://encoding.spec.whatwg.org/\">WHATWG Encoding Standard</a> <code>TextDecoder</code> API.</p>\n<pre><code class=\"language-js\">const decoder = new TextDecoder('shift_jis');\nlet string = '';\nlet buffer;\nwhile (buffer = getNextChunkSomehow()) {\n string += decoder.decode(buffer, { stream: true });\n}\nstring += decoder.decode(); // end-of-stream\n</code></pre>",
"modules": [
{
"textRaw": "WHATWG supported encodings",
"name": "whatwg_supported_encodings",
"desc": "<p>Per the <a href=\"https://encoding.spec.whatwg.org/\">WHATWG Encoding Standard</a>, the encodings supported by the\n<code>TextDecoder</code> API are outlined in the tables below. For each encoding,\none or more aliases may be used.</p>\n<p>Different Node.js build configurations support different sets of encodings.\nWhile a very basic set of encodings is supported even on Node.js builds without\nICU enabled, support for some encodings is provided only when Node.js is built\nwith ICU and using the full ICU data (see <a href=\"intl.html\">Internationalization</a>).</p>",
"modules": [
{
"textRaw": "Encodings Supported Without ICU",
"name": "encodings_supported_without_icu",
"desc": "<table>\n<thead>\n<tr>\n<th>Encoding</th>\n<th>Aliases</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>'utf-8'</code></td>\n<td><code>'unicode-1-1-utf-8'</code>, <code>'utf8'</code></td>\n</tr>\n<tr>\n<td><code>'utf-16le'</code></td>\n<td><code>'utf-16'</code></td>\n</tr>\n</tbody>\n</table>",
"type": "module",
"displayName": "Encodings Supported Without ICU"
},
{
"textRaw": "Encodings Supported by Default (With ICU)",
"name": "encodings_supported_by_default_(with_icu)",
"desc": "<table>\n<thead>\n<tr>\n<th>Encoding</th>\n<th>Aliases</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>'utf-8'</code></td>\n<td><code>'unicode-1-1-utf-8'</code>, <code>'utf8'</code></td>\n</tr>\n<tr>\n<td><code>'utf-16le'</code></td>\n<td><code>'utf-16'</code></td>\n</tr>\n<tr>\n<td><code>'utf-16be'</code></td>\n<td></td>\n</tr>\n</tbody>\n</table>",
"type": "module",
"displayName": "Encodings Supported by Default (With ICU)"
},
{
"textRaw": "Encodings requiring full ICU data",
"name": "encodings_requiring_full_icu_data",
"desc": "<table>\n<thead>\n<tr>\n<th>Encoding</th>\n<th>Aliases</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>'ibm866'</code></td>\n<td><code>'866'</code>, <code>'cp866'</code>, <code>'csibm866'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-2'</code></td>\n<td><code>'csisolatin2'</code>, <code>'iso-ir-101'</code>, <code>'iso8859-2'</code>, <code>'iso88592'</code>, <code>'iso_8859-2'</code>, <code>'iso_8859-2:1987'</code>, <code>'l2'</code>, <code>'latin2'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-3'</code></td>\n<td><code>'csisolatin3'</code>, <code>'iso-ir-109'</code>, <code>'iso8859-3'</code>, <code>'iso88593'</code>, <code>'iso_8859-3'</code>, <code>'iso_8859-3:1988'</code>, <code>'l3'</code>, <code>'latin3'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-4'</code></td>\n<td><code>'csisolatin4'</code>, <code>'iso-ir-110'</code>, <code>'iso8859-4'</code>, <code>'iso88594'</code>, <code>'iso_8859-4'</code>, <code>'iso_8859-4:1988'</code>, <code>'l4'</code>, <code>'latin4'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-5'</code></td>\n<td><code>'csisolatincyrillic'</code>, <code>'cyrillic'</code>, <code>'iso-ir-144'</code>, <code>'iso8859-5'</code>, <code>'iso88595'</code>, <code>'iso_8859-5'</code>, <code>'iso_8859-5:1988'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-6'</code></td>\n<td><code>'arabic'</code>, <code>'asmo-708'</code>, <code>'csiso88596e'</code>, <code>'csiso88596i'</code>, <code>'csisolatinarabic'</code>, <code>'ecma-114'</code>, <code>'iso-8859-6-e'</code>, <code>'iso-8859-6-i'</code>, <code>'iso-ir-127'</code>, <code>'iso8859-6'</code>, <code>'iso88596'</code>, <code>'iso_8859-6'</code>, <code>'iso_8859-6:1987'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-7'</code></td>\n<td><code>'csisolatingreek'</code>, <code>'ecma-118'</code>, <code>'elot_928'</code>, <code>'greek'</code>, <code>'greek8'</code>, <code>'iso-ir-126'</code>, <code>'iso8859-7'</code>, <code>'iso88597'</code>, <code>'iso_8859-7'</code>, <code>'iso_8859-7:1987'</code>, <code>'sun_eu_greek'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-8'</code></td>\n<td><code>'csiso88598e'</code>, <code>'csisolatinhebrew'</code>, <code>'hebrew'</code>, <code>'iso-8859-8-e'</code>, <code>'iso-ir-138'</code>, <code>'iso8859-8'</code>, <code>'iso88598'</code>, <code>'iso_8859-8'</code>, <code>'iso_8859-8:1988'</code>, <code>'visual'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-8-i'</code></td>\n<td><code>'csiso88598i'</code>, <code>'logical'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-10'</code></td>\n<td><code>'csisolatin6'</code>, <code>'iso-ir-157'</code>, <code>'iso8859-10'</code>, <code>'iso885910'</code>, <code>'l6'</code>, <code>'latin6'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-13'</code></td>\n<td><code>'iso8859-13'</code>, <code>'iso885913'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-14'</code></td>\n<td><code>'iso8859-14'</code>, <code>'iso885914'</code></td>\n</tr>\n<tr>\n<td><code>'iso-8859-15'</code></td>\n<td><code>'csisolatin9'</code>, <code>'iso8859-15'</code>, <code>'iso885915'</code>, <code>'iso_8859-15'</code>, <code>'l9'</code></td>\n</tr>\n<tr>\n<td><code>'koi8-r'</code></td>\n<td><code>'cskoi8r'</code>, <code>'koi'</code>, <code>'koi8'</code>, <code>'koi8_r'</code></td>\n</tr>\n<tr>\n<td><code>'koi8-u'</code></td>\n<td><code>'koi8-ru'</code></td>\n</tr>\n<tr>\n<td><code>'macintosh'</code></td>\n<td><code>'csmacintosh'</code>, <code>'mac'</code>, <code>'x-mac-roman'</code></td>\n</tr>\n<tr>\n<td><code>'windows-874'</code></td>\n<td><code>'dos-874'</code>, <code>'iso-8859-11'</code>, <code>'iso8859-11'</code>, <code>'iso885911'</code>, <code>'tis-620'</code></td>\n</tr>\n<tr>\n<td><code>'windows-1250'</code></td>\n<td><code>'cp1250'</code>, <code>'x-cp1250'</code></td>\n</tr>\n<tr>\n<td><code>'windows-1251'</code></td>\n<td><code>'cp1251'</code>, <code>'x-cp1251'</code></td>\n</tr>\n<tr>\n<td><code>'windows-1252'</code></td>\n<td><code>'ansi_x3.4-1968'</code>, <code>'ascii'</code>, <code>'cp1252'</code>, <code>'cp819'</code>, <code>'csisolatin1'</code>, <code>'ibm819'</code>, <code>'iso-8859-1'</code>, <code>'iso-ir-100'</code>, <code>'iso8859-1'</code>, <code>'iso88591'</code>, <code>'iso_8859-1'</code>, <code>'iso_8859-1:1987'</code>, <code>'l1'</code>, <code>'latin1'</code>, <code>'us-ascii'</code>, <code>'x-cp1252'</code></td>\n</tr>\n<tr>\n<td><code>'windows-1253'</code></td>\n<td><code>'cp1253'</code>, <code>'x-cp1253'</code></td>\n</tr>\n<tr>\n<td><code>'windows-1254'</code></td>\n<td><code>'cp1254'</code>, <code>'csisolatin5'</code>, <code>'iso-8859-9'</code>, <code>'iso-ir-148'</code>, <code>'iso8859-9'</code>, <code>'iso88599'</code>, <code>'iso_8859-9'</code>, <code>'iso_8859-9:1989'</code>, <code>'l5'</code>, <code>'latin5'</code>, <code>'x-cp1254'</code></td>\n</tr>\n<tr>\n<td><code>'windows-1255'</code></td>\n<td><code>'cp1255'</code>, <code>'x-cp1255'</code></td>\n</tr>\n<tr>\n<td><code>'windows-1256'</code></td>\n<td><code>'cp1256'</code>, <code>'x-cp1256'</code></td>\n</tr>\n<tr>\n<td><code>'windows-1257'</code></td>\n<td><code>'cp1257'</code>, <code>'x-cp1257'</code></td>\n</tr>\n<tr>\n<td><code>'windows-1258'</code></td>\n<td><code>'cp1258'</code>, <code>'x-cp1258'</code></td>\n</tr>\n<tr>\n<td><code>'x-mac-cyrillic'</code></td>\n<td><code>'x-mac-ukrainian'</code></td>\n</tr>\n<tr>\n<td><code>'gbk'</code></td>\n<td><code>'chinese'</code>, <code>'csgb2312'</code>, <code>'csiso58gb231280'</code>, <code>'gb2312'</code>, <code>'gb_2312'</code>, <code>'gb_2312-80'</code>, <code>'iso-ir-58'</code>, <code>'x-gbk'</code></td>\n</tr>\n<tr>\n<td><code>'gb18030'</code></td>\n<td></td>\n</tr>\n<tr>\n<td><code>'big5'</code></td>\n<td><code>'big5-hkscs'</code>, <code>'cn-big5'</code>, <code>'csbig5'</code>, <code>'x-x-big5'</code></td>\n</tr>\n<tr>\n<td><code>'euc-jp'</code></td>\n<td><code>'cseucpkdfmtjapanese'</code>, <code>'x-euc-jp'</code></td>\n</tr>\n<tr>\n<td><code>'iso-2022-jp'</code></td>\n<td><code>'csiso2022jp'</code></td>\n</tr>\n<tr>\n<td><code>'shift_jis'</code></td>\n<td><code>'csshiftjis'</code>, <code>'ms932'</code>, <code>'ms_kanji'</code>, <code>'shift-jis'</code>, <code>'sjis'</code>, <code>'windows-31j'</code>, <code>'x-sjis'</code></td>\n</tr>\n<tr>\n<td><code>'euc-kr'</code></td>\n<td><code>'cseuckr'</code>, <code>'csksc56011987'</code>, <code>'iso-ir-149'</code>, <code>'korean'</code>, <code>'ks_c_5601-1987'</code>, <code>'ks_c_5601-1989'</code>, <code>'ksc5601'</code>, <code>'ksc_5601'</code>, <code>'windows-949'</code></td>\n</tr>\n</tbody>\n</table>\n<p>The <code>'iso-8859-16'</code> encoding listed in the <a href=\"https://encoding.spec.whatwg.org/\">WHATWG Encoding Standard</a>\nis not supported.</p>",
"type": "module",
"displayName": "Encodings requiring full ICU data"
}
],
"type": "module",
"displayName": "WHATWG supported encodings"
}
],
"methods": [
{
"textRaw": "`textDecoder.decode([input[, options]])`",
"type": "method",
"name": "decode",
"signatures": [
{
"return": {
"textRaw": "Returns: {string}",
"name": "return",
"type": "string"
},
"params": [
{
"textRaw": "`input` {ArrayBuffer|DataView|TypedArray} An `ArrayBuffer`, `DataView` or `TypedArray` instance containing the encoded data.",
"name": "input",
"type": "ArrayBuffer|DataView|TypedArray",
"desc": "An `ArrayBuffer`, `DataView` or `TypedArray` instance containing the encoded data."
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`stream` {boolean} `true` if additional chunks of data are expected. **Default:** `false`.",
"name": "stream",
"type": "boolean",
"default": "`false`",
"desc": "`true` if additional chunks of data are expected."
}
]
}
]
}
],
"desc": "<p>Decodes the <code>input</code> and returns a string. If <code>options.stream</code> is <code>true</code>, any\nincomplete byte sequences occurring at the end of the <code>input</code> are buffered\ninternally and emitted after the next call to <code>textDecoder.decode()</code>.</p>\n<p>If <code>textDecoder.fatal</code> is <code>true</code>, decoding errors that occur will result in a\n<code>TypeError</code> being thrown.</p>"
}
],
"properties": [
{
"textRaw": "`encoding` {string}",
"type": "string",
"name": "encoding",
"desc": "<p>The encoding supported by the <code>TextDecoder</code> instance.</p>"
},
{
"textRaw": "`fatal` {boolean}",
"type": "boolean",
"name": "fatal",
"desc": "<p>The value will be <code>true</code> if decoding errors result in a <code>TypeError</code> being\nthrown.</p>"
},
{
"textRaw": "`ignoreBOM` {boolean}",
"type": "boolean",
"name": "ignoreBOM",
"desc": "<p>The value will be <code>true</code> if the decoding result will include the byte order\nmark.</p>"
}
],
"signatures": [
{
"params": [
{
"textRaw": "`encoding` {string} Identifies the `encoding` that this `TextDecoder` instance supports. **Default:** `'utf-8'`.",
"name": "encoding",
"type": "string",
"default": "`'utf-8'`",
"desc": "Identifies the `encoding` that this `TextDecoder` instance supports."
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`fatal` {boolean} `true` if decoding failures are fatal. This option is only supported when ICU is enabled (see [Internationalization][]). **Default:** `false`.",
"name": "fatal",
"type": "boolean",
"default": "`false`",
"desc": "`true` if decoding failures are fatal. This option is only supported when ICU is enabled (see [Internationalization][])."
},
{
"textRaw": "`ignoreBOM` {boolean} When `true`, the `TextDecoder` will include the byte order mark in the decoded result. When `false`, the byte order mark will be removed from the output. This option is only used when `encoding` is `'utf-8'`, `'utf-16be'` or `'utf-16le'`. **Default:** `false`.",
"name": "ignoreBOM",
"type": "boolean",
"default": "`false`",
"desc": "When `true`, the `TextDecoder` will include the byte order mark in the decoded result. When `false`, the byte order mark will be removed from the output. This option is only used when `encoding` is `'utf-8'`, `'utf-16be'` or `'utf-16le'`."
}
]
}
],
"desc": "<p>Creates an new <code>TextDecoder</code> instance. The <code>encoding</code> may specify one of the\nsupported encodings or an alias.</p>\n<p>The <code>TextDecoder</code> class is also available on the global object.</p>"
}
]
},
{
"textRaw": "Class: `util.TextEncoder`",
"type": "class",
"name": "util.TextEncoder",
"meta": {
"added": [
"v8.3.0"
],
"changes": [
{
"version": "v11.0.0",
"pr-url": "v11.0.0",
"description": "The class is now available on the global object."
}
]
},
"desc": "<p>An implementation of the <a href=\"https://encoding.spec.whatwg.org/\">WHATWG Encoding Standard</a> <code>TextEncoder</code> API. All\ninstances of <code>TextEncoder</code> only support UTF-8 encoding.</p>\n<pre><code class=\"language-js\">const encoder = new TextEncoder();\nconst uint8array = encoder.encode('this is some data');\n</code></pre>\n<p>The <code>TextEncoder</code> class is also available on the global object.</p>",
"methods": [
{
"textRaw": "`textEncoder.encode([input])`",
"type": "method",
"name": "encode",
"signatures": [
{
"return": {
"textRaw": "Returns: {Uint8Array}",
"name": "return",
"type": "Uint8Array"
},
"params": [
{
"textRaw": "`input` {string} The text to encode. **Default:** an empty string.",
"name": "input",
"type": "string",
"default": "an empty string",
"desc": "The text to encode."
}
]
}
],
"desc": "<p>UTF-8 encodes the <code>input</code> string and returns a <code>Uint8Array</code> containing the\nencoded bytes.</p>"
},
{
"textRaw": "`textEncoder.encodeInto(src, dest)`",
"type": "method",
"name": "encodeInto",
"signatures": [
{
"return": {
"textRaw": "Returns: {Object}",
"name": "return",
"type": "Object",
"options": [
{
"textRaw": "`read` {number} The read Unicode code units of src.",
"name": "read",
"type": "number",
"desc": "The read Unicode code units of src."
},
{
"textRaw": "`written` {number} The written UTF-8 bytes of dest.",
"name": "written",
"type": "number",
"desc": "The written UTF-8 bytes of dest."
}
]
},
"params": [
{
"textRaw": "`src` {string} The text to encode.",
"name": "src",
"type": "string",
"desc": "The text to encode."
},
{
"textRaw": "`dest` {Uint8Array} The array to hold the encode result.",
"name": "dest",
"type": "Uint8Array",
"desc": "The array to hold the encode result."
}
]
}
],
"desc": "<p>UTF-8 encodes the <code>src</code> string to the <code>dest</code> Uint8Array and returns an object\ncontaining the read Unicode code units and written UTF-8 bytes.</p>\n<pre><code class=\"language-js\">const encoder = new TextEncoder();\nconst src = 'this is some data';\nconst dest = new Uint8Array(10);\nconst { read, written } = encoder.encodeInto(src, dest);\n</code></pre>"
}
],
"properties": [
{
"textRaw": "`encoding` {string}",
"type": "string",
"name": "encoding",
"desc": "<p>The encoding supported by the <code>TextEncoder</code> instance. Always set to <code>'utf-8'</code>.</p>"
}
]
}
],
"properties": [
{
"textRaw": "`util.types`",
"name": "types",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"desc": "<p><code>util.types</code> provides type checks for different kinds of built-in objects.\nUnlike <code>instanceof</code> or <code>Object.prototype.toString.call(value)</code>, these checks do\nnot inspect properties of the object that are accessible from JavaScript (like\ntheir prototype), and usually have the overhead of calling into C++.</p>\n<p>The result generally does not make any guarantees about what kinds of\nproperties or behavior a value exposes in JavaScript. They are primarily\nuseful for addon developers who prefer to do type checking in JavaScript.</p>",
"methods": [
{
"textRaw": "`util.types.isAnyArrayBuffer(value)`",
"type": "method",
"name": "isAnyArrayBuffer",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a> or\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer\"><code>SharedArrayBuffer</code></a> instance.</p>\n<p>See also <a href=\"#util_util_types_isarraybuffer_value\"><code>util.types.isArrayBuffer()</code></a> and\n<a href=\"#util_util_types_issharedarraybuffer_value\"><code>util.types.isSharedArrayBuffer()</code></a>.</p>\n<pre><code class=\"language-js\">util.types.isAnyArrayBuffer(new ArrayBuffer()); // Returns true\nutil.types.isAnyArrayBuffer(new SharedArrayBuffer()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isArrayBufferView(value)`",
"type": "method",
"name": "isArrayBufferView",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is an instance of one of the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a>\nviews, such as typed array objects or <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView\"><code>DataView</code></a>. Equivalent to\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView\"><code>ArrayBuffer.isView()</code></a>.</p>\n<pre><code class=\"language-js\">util.types.isArrayBufferView(new Int8Array()); // true\nutil.types.isArrayBufferView(Buffer.from('hello world')); // true\nutil.types.isArrayBufferView(new DataView(new ArrayBuffer(16))); // true\nutil.types.isArrayBufferView(new ArrayBuffer()); // false\n</code></pre>"
},
{
"textRaw": "`util.types.isArgumentsObject(value)`",
"type": "method",
"name": "isArgumentsObject",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is an <code>arguments</code> object.</p>\n<!-- eslint-disable prefer-rest-params -->\n<pre><code class=\"language-js\">function foo() {\n util.types.isArgumentsObject(arguments); // Returns true\n}\n</code></pre>"
},
{
"textRaw": "`util.types.isArrayBuffer(value)`",
"type": "method",
"name": "isArrayBuffer",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a> instance.\nThis does <em>not</em> include <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer\"><code>SharedArrayBuffer</code></a> instances. Usually, it is\ndesirable to test for both; See <a href=\"#util_util_types_isanyarraybuffer_value\"><code>util.types.isAnyArrayBuffer()</code></a> for that.</p>\n<pre><code class=\"language-js\">util.types.isArrayBuffer(new ArrayBuffer()); // Returns true\nutil.types.isArrayBuffer(new SharedArrayBuffer()); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isAsyncFunction(value)`",
"type": "method",
"name": "isAsyncFunction",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function\">async function</a>.\nThis only reports back what the JavaScript engine is seeing;\nin particular, the return value may not match the original source code if\na transpilation tool was used.</p>\n<pre><code class=\"language-js\">util.types.isAsyncFunction(function foo() {}); // Returns false\nutil.types.isAsyncFunction(async function foo() {}); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isBigInt64Array(value)`",
"type": "method",
"name": "isBigInt64Array",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a <code>BigInt64Array</code> instance.</p>\n<pre><code class=\"language-js\">util.types.isBigInt64Array(new BigInt64Array()); // Returns true\nutil.types.isBigInt64Array(new BigUint64Array()); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isBigUint64Array(value)`",
"type": "method",
"name": "isBigUint64Array",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a <code>BigUint64Array</code> instance.</p>\n<pre><code class=\"language-js\">util.types.isBigUint64Array(new BigInt64Array()); // Returns false\nutil.types.isBigUint64Array(new BigUint64Array()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isBooleanObject(value)`",
"type": "method",
"name": "isBooleanObject",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a boolean object, e.g. created\nby <code>new Boolean()</code>.</p>\n<pre><code class=\"language-js\">util.types.isBooleanObject(false); // Returns false\nutil.types.isBooleanObject(true); // Returns false\nutil.types.isBooleanObject(new Boolean(false)); // Returns true\nutil.types.isBooleanObject(new Boolean(true)); // Returns true\nutil.types.isBooleanObject(Boolean(false)); // Returns false\nutil.types.isBooleanObject(Boolean(true)); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isBoxedPrimitive(value)`",
"type": "method",
"name": "isBoxedPrimitive",
"meta": {
"added": [
"v10.11.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is any boxed primitive object, e.g. created\nby <code>new Boolean()</code>, <code>new String()</code> or <code>Object(Symbol())</code>.</p>\n<p>For example:</p>\n<pre><code class=\"language-js\">util.types.isBoxedPrimitive(false); // Returns false\nutil.types.isBoxedPrimitive(new Boolean(false)); // Returns true\nutil.types.isBoxedPrimitive(Symbol('foo')); // Returns false\nutil.types.isBoxedPrimitive(Object(Symbol('foo'))); // Returns true\nutil.types.isBoxedPrimitive(Object(BigInt(5))); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isDataView(value)`",
"type": "method",
"name": "isDataView",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView\"><code>DataView</code></a> instance.</p>\n<pre><code class=\"language-js\">const ab = new ArrayBuffer(20);\nutil.types.isDataView(new DataView(ab)); // Returns true\nutil.types.isDataView(new Float64Array()); // Returns false\n</code></pre>\n<p>See also <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView\"><code>ArrayBuffer.isView()</code></a>.</p>"
},
{
"textRaw": "`util.types.isDate(value)`",
"type": "method",
"name": "isDate",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date\"><code>Date</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isDate(new Date()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isExternal(value)`",
"type": "method",
"name": "isExternal",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a native <code>External</code> value.</p>\n<p>A native <code>External</code> value is a special type of object that contains a\nraw C++ pointer (<code>void*</code>) for access from native code, and has no other\nproperties. Such objects are created either by Node.js internals or native\naddons. In JavaScript, they are <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze\">frozen</a> objects with a\n<code>null</code> prototype.</p>\n<pre><code class=\"language-c\">#include <js_native_api.h>\n#include <stdlib.h>\nnapi_value result;\nstatic napi_value MyNapi(napi_env env, napi_callback_info info) {\n int* raw = (int*) malloc(1024);\n napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &result);\n if (status != napi_ok) {\n napi_throw_error(env, NULL, \"napi_create_external failed\");\n return NULL;\n }\n return result;\n}\n...\nDECLARE_NAPI_PROPERTY(\"myNapi\", MyNapi)\n...\n</code></pre>\n<pre><code class=\"language-js\">const native = require('napi_addon.node');\nconst data = native.myNapi();\nutil.types.isExternal(data); // returns true\nutil.types.isExternal(0); // returns false\nutil.types.isExternal(new String('foo')); // returns false\n</code></pre>\n<p>For further information on <code>napi_create_external</code>, refer to\n<a href=\"n-api.html#n_api_napi_create_external\"><code>napi_create_external()</code></a>.</p>"
},
{
"textRaw": "`util.types.isFloat32Array(value)`",
"type": "method",
"name": "isFloat32Array",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array\"><code>Float32Array</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isFloat32Array(new ArrayBuffer()); // Returns false\nutil.types.isFloat32Array(new Float32Array()); // Returns true\nutil.types.isFloat32Array(new Float64Array()); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isFloat64Array(value)`",
"type": "method",
"name": "isFloat64Array",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array\"><code>Float64Array</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isFloat64Array(new ArrayBuffer()); // Returns false\nutil.types.isFloat64Array(new Uint8Array()); // Returns false\nutil.types.isFloat64Array(new Float64Array()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isGeneratorFunction(value)`",
"type": "method",
"name": "isGeneratorFunction",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a generator function.\nThis only reports back what the JavaScript engine is seeing;\nin particular, the return value may not match the original source code if\na transpilation tool was used.</p>\n<pre><code class=\"language-js\">util.types.isGeneratorFunction(function foo() {}); // Returns false\nutil.types.isGeneratorFunction(function* foo() {}); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isGeneratorObject(value)`",
"type": "method",
"name": "isGeneratorObject",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a generator object as returned from a\nbuilt-in generator function.\nThis only reports back what the JavaScript engine is seeing;\nin particular, the return value may not match the original source code if\na transpilation tool was used.</p>\n<pre><code class=\"language-js\">function* foo() {}\nconst generator = foo();\nutil.types.isGeneratorObject(generator); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isInt8Array(value)`",
"type": "method",
"name": "isInt8Array",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array\"><code>Int8Array</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isInt8Array(new ArrayBuffer()); // Returns false\nutil.types.isInt8Array(new Int8Array()); // Returns true\nutil.types.isInt8Array(new Float64Array()); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isInt16Array(value)`",
"type": "method",
"name": "isInt16Array",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array\"><code>Int16Array</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isInt16Array(new ArrayBuffer()); // Returns false\nutil.types.isInt16Array(new Int16Array()); // Returns true\nutil.types.isInt16Array(new Float64Array()); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isInt32Array(value)`",
"type": "method",
"name": "isInt32Array",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array\"><code>Int32Array</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isInt32Array(new ArrayBuffer()); // Returns false\nutil.types.isInt32Array(new Int32Array()); // Returns true\nutil.types.isInt32Array(new Float64Array()); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isMap(value)`",
"type": "method",
"name": "isMap",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\"><code>Map</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isMap(new Map()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isMapIterator(value)`",
"type": "method",
"name": "isMapIterator",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is an iterator returned for a built-in\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\"><code>Map</code></a> instance.</p>\n<pre><code class=\"language-js\">const map = new Map();\nutil.types.isMapIterator(map.keys()); // Returns true\nutil.types.isMapIterator(map.values()); // Returns true\nutil.types.isMapIterator(map.entries()); // Returns true\nutil.types.isMapIterator(map[Symbol.iterator]()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isModuleNamespaceObject(value)`",
"type": "method",
"name": "isModuleNamespaceObject",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is an instance of a <a href=\"https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects\">Module Namespace Object</a>.</p>\n<!-- eslint-skip -->\n<pre><code class=\"language-js\">import * as ns from './a.js';\n\nutil.types.isModuleNamespaceObject(ns); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isNativeError(value)`",
"type": "method",
"name": "isNativeError",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is an instance of a built-in <a href=\"errors.html#errors_class_error\"><code>Error</code></a> type.</p>\n<pre><code class=\"language-js\">util.types.isNativeError(new Error()); // Returns true\nutil.types.isNativeError(new TypeError()); // Returns true\nutil.types.isNativeError(new RangeError()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isNumberObject(value)`",
"type": "method",
"name": "isNumberObject",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a number object, e.g. created\nby <code>new Number()</code>.</p>\n<pre><code class=\"language-js\">util.types.isNumberObject(0); // Returns false\nutil.types.isNumberObject(new Number(0)); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isPromise(value)`",
"type": "method",
"name": "isPromise",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise\"><code>Promise</code></a>.</p>\n<pre><code class=\"language-js\">util.types.isPromise(Promise.resolve(42)); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isProxy(value)`",
"type": "method",
"name": "isProxy",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy\"><code>Proxy</code></a> instance.</p>\n<pre><code class=\"language-js\">const target = {};\nconst proxy = new Proxy(target, {});\nutil.types.isProxy(target); // Returns false\nutil.types.isProxy(proxy); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isRegExp(value)`",
"type": "method",
"name": "isRegExp",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a regular expression object.</p>\n<pre><code class=\"language-js\">util.types.isRegExp(/abc/); // Returns true\nutil.types.isRegExp(new RegExp('abc')); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isSet(value)`",
"type": "method",
"name": "isSet",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set\"><code>Set</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isSet(new Set()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isSetIterator(value)`",
"type": "method",
"name": "isSetIterator",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is an iterator returned for a built-in\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set\"><code>Set</code></a> instance.</p>\n<pre><code class=\"language-js\">const set = new Set();\nutil.types.isSetIterator(set.keys()); // Returns true\nutil.types.isSetIterator(set.values()); // Returns true\nutil.types.isSetIterator(set.entries()); // Returns true\nutil.types.isSetIterator(set[Symbol.iterator]()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isSharedArrayBuffer(value)`",
"type": "method",
"name": "isSharedArrayBuffer",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer\"><code>SharedArrayBuffer</code></a> instance.\nThis does <em>not</em> include <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a> instances. Usually, it is\ndesirable to test for both; See <a href=\"#util_util_types_isanyarraybuffer_value\"><code>util.types.isAnyArrayBuffer()</code></a> for that.</p>\n<pre><code class=\"language-js\">util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false\nutil.types.isSharedArrayBuffer(new SharedArrayBuffer()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isStringObject(value)`",
"type": "method",
"name": "isStringObject",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a string object, e.g. created\nby <code>new String()</code>.</p>\n<pre><code class=\"language-js\">util.types.isStringObject('foo'); // Returns false\nutil.types.isStringObject(new String('foo')); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isSymbolObject(value)`",
"type": "method",
"name": "isSymbolObject",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a symbol object, created\nby calling <code>Object()</code> on a <code>Symbol</code> primitive.</p>\n<pre><code class=\"language-js\">const symbol = Symbol('foo');\nutil.types.isSymbolObject(symbol); // Returns false\nutil.types.isSymbolObject(Object(symbol)); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isTypedArray(value)`",
"type": "method",
"name": "isTypedArray",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isTypedArray(new ArrayBuffer()); // Returns false\nutil.types.isTypedArray(new Uint8Array()); // Returns true\nutil.types.isTypedArray(new Float64Array()); // Returns true\n</code></pre>\n<p>See also <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView\"><code>ArrayBuffer.isView()</code></a>.</p>"
},
{
"textRaw": "`util.types.isUint8Array(value)`",
"type": "method",
"name": "isUint8Array",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\"><code>Uint8Array</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isUint8Array(new ArrayBuffer()); // Returns false\nutil.types.isUint8Array(new Uint8Array()); // Returns true\nutil.types.isUint8Array(new Float64Array()); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isUint8ClampedArray(value)`",
"type": "method",
"name": "isUint8ClampedArray",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray\"><code>Uint8ClampedArray</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isUint8ClampedArray(new ArrayBuffer()); // Returns false\nutil.types.isUint8ClampedArray(new Uint8ClampedArray()); // Returns true\nutil.types.isUint8ClampedArray(new Float64Array()); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isUint16Array(value)`",
"type": "method",
"name": "isUint16Array",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array\"><code>Uint16Array</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isUint16Array(new ArrayBuffer()); // Returns false\nutil.types.isUint16Array(new Uint16Array()); // Returns true\nutil.types.isUint16Array(new Float64Array()); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isUint32Array(value)`",
"type": "method",
"name": "isUint32Array",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array\"><code>Uint32Array</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isUint32Array(new ArrayBuffer()); // Returns false\nutil.types.isUint32Array(new Uint32Array()); // Returns true\nutil.types.isUint32Array(new Float64Array()); // Returns false\n</code></pre>"
},
{
"textRaw": "`util.types.isWeakMap(value)`",
"type": "method",
"name": "isWeakMap",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap\"><code>WeakMap</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isWeakMap(new WeakMap()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isWeakSet(value)`",
"type": "method",
"name": "isWeakSet",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet\"><code>WeakSet</code></a> instance.</p>\n<pre><code class=\"language-js\">util.types.isWeakSet(new WeakSet()); // Returns true\n</code></pre>"
},
{
"textRaw": "`util.types.isWebAssemblyCompiledModule(value)`",
"type": "method",
"name": "isWebAssemblyCompiledModule",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`value` {any}",
"name": "value",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the value is a built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module\"><code>WebAssembly.Module</code></a> instance.</p>\n<pre><code class=\"language-js\">const module = new WebAssembly.Module(wasmBuffer);\nutil.types.isWebAssemblyCompiledModule(module); // Returns true\n</code></pre>"
}
]
}
],
"modules": [
{
"textRaw": "Deprecated APIs",
"name": "deprecated_apis",
"desc": "<p>The following APIs are deprecated and should no longer be used. Existing\napplications and modules should be updated to find alternative approaches.</p>",
"methods": [
{
"textRaw": "`util._extend(target, source)`",
"type": "method",
"name": "_extend",
"meta": {
"added": [
"v0.7.5"
],
"deprecated": [
"v6.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use [`Object.assign()`][] instead.",
"signatures": [
{
"params": [
{
"textRaw": "`target` {Object}",
"name": "target",
"type": "Object"
},
{
"textRaw": "`source` {Object}",
"name": "source",
"type": "Object"
}
]
}
],
"desc": "<p>The <code>util._extend()</code> method was never intended to be used outside of internal\nNode.js modules. The community found and used it anyway.</p>\n<p>It is deprecated and should not be used in new code. JavaScript comes with very\nsimilar built-in functionality through <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign\"><code>Object.assign()</code></a>.</p>"
},
{
"textRaw": "`util.isArray(object)`",
"type": "method",
"name": "isArray",
"meta": {
"added": [
"v0.6.0"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use [`Array.isArray()`][] instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Alias for <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray\"><code>Array.isArray()</code></a>.</p>\n<p>Returns <code>true</code> if the given <code>object</code> is an <code>Array</code>. Otherwise, returns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isArray([]);\n// Returns: true\nutil.isArray(new Array());\n// Returns: true\nutil.isArray({});\n// Returns: false\n</code></pre>"
},
{
"textRaw": "`util.isBoolean(object)`",
"type": "method",
"name": "isBoolean",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use `typeof value === 'boolean'` instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is a <code>Boolean</code>. Otherwise, returns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isBoolean(1);\n// Returns: false\nutil.isBoolean(0);\n// Returns: false\nutil.isBoolean(false);\n// Returns: true\n</code></pre>"
},
{
"textRaw": "`util.isBuffer(object)`",
"type": "method",
"name": "isBuffer",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use [`Buffer.isBuffer()`][] instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is a <code>Buffer</code>. Otherwise, returns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isBuffer({ length: 0 });\n// Returns: false\nutil.isBuffer([]);\n// Returns: false\nutil.isBuffer(Buffer.from('hello world'));\n// Returns: true\n</code></pre>"
},
{
"textRaw": "`util.isDate(object)`",
"type": "method",
"name": "isDate",
"meta": {
"added": [
"v0.6.0"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use [`util.types.isDate()`][] instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is a <code>Date</code>. Otherwise, returns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isDate(new Date());\n// Returns: true\nutil.isDate(Date());\n// false (without 'new' returns a String)\nutil.isDate({});\n// Returns: false\n</code></pre>"
},
{
"textRaw": "`util.isError(object)`",
"type": "method",
"name": "isError",
"meta": {
"added": [
"v0.6.0"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use [`util.types.isNativeError()`][] instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is an <a href=\"errors.html#errors_class_error\"><code>Error</code></a>. Otherwise, returns\n<code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isError(new Error());\n// Returns: true\nutil.isError(new TypeError());\n// Returns: true\nutil.isError({ name: 'Error', message: 'an error occurred' });\n// Returns: false\n</code></pre>\n<p>This method relies on <code>Object.prototype.toString()</code> behavior. It is\npossible to obtain an incorrect result when the <code>object</code> argument manipulates\n<code>@@toStringTag</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\nconst obj = { name: 'Error', message: 'an error occurred' };\n\nutil.isError(obj);\n// Returns: false\nobj[Symbol.toStringTag] = 'Error';\nutil.isError(obj);\n// Returns: true\n</code></pre>"
},
{
"textRaw": "`util.isFunction(object)`",
"type": "method",
"name": "isFunction",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use `typeof value === 'function'` instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is a <code>Function</code>. Otherwise, returns\n<code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nfunction Foo() {}\nconst Bar = () => {};\n\nutil.isFunction({});\n// Returns: false\nutil.isFunction(Foo);\n// Returns: true\nutil.isFunction(Bar);\n// Returns: true\n</code></pre>"
},
{
"textRaw": "`util.isNull(object)`",
"type": "method",
"name": "isNull",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use `value === null` instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is strictly <code>null</code>. Otherwise, returns\n<code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isNull(0);\n// Returns: false\nutil.isNull(undefined);\n// Returns: false\nutil.isNull(null);\n// Returns: true\n</code></pre>"
},
{
"textRaw": "`util.isNullOrUndefined(object)`",
"type": "method",
"name": "isNullOrUndefined",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use\n`value === undefined || value === null` instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is <code>null</code> or <code>undefined</code>. Otherwise,\nreturns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isNullOrUndefined(0);\n// Returns: false\nutil.isNullOrUndefined(undefined);\n// Returns: true\nutil.isNullOrUndefined(null);\n// Returns: true\n</code></pre>"
},
{
"textRaw": "`util.isNumber(object)`",
"type": "method",
"name": "isNumber",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use `typeof value === 'number'` instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is a <code>Number</code>. Otherwise, returns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isNumber(false);\n// Returns: false\nutil.isNumber(Infinity);\n// Returns: true\nutil.isNumber(0);\n// Returns: true\nutil.isNumber(NaN);\n// Returns: true\n</code></pre>"
},
{
"textRaw": "`util.isObject(object)`",
"type": "method",
"name": "isObject",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated:\nUse `value !== null && typeof value === 'object'` instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is strictly an <code>Object</code> <strong>and</strong> not a\n<code>Function</code> (even though functions are objects in JavaScript).\nOtherwise, returns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isObject(5);\n// Returns: false\nutil.isObject(null);\n// Returns: false\nutil.isObject({});\n// Returns: true\nutil.isObject(() => {});\n// Returns: false\n</code></pre>"
},
{
"textRaw": "`util.isPrimitive(object)`",
"type": "method",
"name": "isPrimitive",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use\n`(typeof value !== 'object' && typeof value !== 'function') || value === null`\ninstead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is a primitive type. Otherwise, returns\n<code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isPrimitive(5);\n// Returns: true\nutil.isPrimitive('foo');\n// Returns: true\nutil.isPrimitive(false);\n// Returns: true\nutil.isPrimitive(null);\n// Returns: true\nutil.isPrimitive(undefined);\n// Returns: true\nutil.isPrimitive({});\n// Returns: false\nutil.isPrimitive(() => {});\n// Returns: false\nutil.isPrimitive(/^$/);\n// Returns: false\nutil.isPrimitive(new Date());\n// Returns: false\n</code></pre>"
},
{
"textRaw": "`util.isRegExp(object)`",
"type": "method",
"name": "isRegExp",
"meta": {
"added": [
"v0.6.0"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is a <code>RegExp</code>. Otherwise, returns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isRegExp(/some regexp/);\n// Returns: true\nutil.isRegExp(new RegExp('another regexp'));\n// Returns: true\nutil.isRegExp({});\n// Returns: false\n</code></pre>"
},
{
"textRaw": "`util.isString(object)`",
"type": "method",
"name": "isString",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use `typeof value === 'string'` instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is a <code>string</code>. Otherwise, returns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isString('');\n// Returns: true\nutil.isString('foo');\n// Returns: true\nutil.isString(String('foo'));\n// Returns: true\nutil.isString(5);\n// Returns: false\n</code></pre>"
},
{
"textRaw": "`util.isSymbol(object)`",
"type": "method",
"name": "isSymbol",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use `typeof value === 'symbol'` instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is a <code>Symbol</code>. Otherwise, returns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.isSymbol(5);\n// Returns: false\nutil.isSymbol('foo');\n// Returns: false\nutil.isSymbol(Symbol('foo'));\n// Returns: true\n</code></pre>"
},
{
"textRaw": "`util.isUndefined(object)`",
"type": "method",
"name": "isUndefined",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use `value === undefined` instead.",
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`object` {any}",
"name": "object",
"type": "any"
}
]
}
],
"desc": "<p>Returns <code>true</code> if the given <code>object</code> is <code>undefined</code>. Otherwise, returns <code>false</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nconst foo = undefined;\nutil.isUndefined(5);\n// Returns: false\nutil.isUndefined(foo);\n// Returns: true\nutil.isUndefined(null);\n// Returns: false\n</code></pre>"
},
{
"textRaw": "`util.log(string)`",
"type": "method",
"name": "log",
"meta": {
"added": [
"v0.3.0"
],
"deprecated": [
"v6.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use a third party module instead.",
"signatures": [
{
"params": [
{
"textRaw": "`string` {string}",
"name": "string",
"type": "string"
}
]
}
],
"desc": "<p>The <code>util.log()</code> method prints the given <code>string</code> to <code>stdout</code> with an included\ntimestamp.</p>\n<pre><code class=\"language-js\">const util = require('util');\n\nutil.log('Timestamped message.');\n</code></pre>"
}
],
"type": "module",
"displayName": "Deprecated APIs"
}
],
"type": "module",
"displayName": "Util"
}
]
}