{
  "source": "doc/api/util.markdown",
  "modules": [
    {
      "textRaw": "util",
      "name": "util",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>These functions are in the module <code>&#39;util&#39;</code>. Use <code>require(&#39;util&#39;)</code> to\naccess them.\n\n</p>\n<p>The <code>util</code> module is primarily designed to support the needs of Node.js&#39;s\ninternal APIs.  Many of these utilities are useful for your own\nprograms.  If you find that these functions are lacking for your\npurposes, however, you are encouraged to write your own utilities.  We\nare not interested in any future additions to the <code>util</code> module that\nare unnecessary for Node.js&#39;s internal functionality.\n\n</p>\n",
      "methods": [
        {
          "textRaw": "util.debug(string)",
          "type": "method",
          "name": "debug",
          "stability": 0,
          "stabilityText": "Deprecated: use console.error() instead.",
          "desc": "<p>Deprecated predecessor of <code>console.error</code>.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "string"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.debuglog(section)",
          "type": "method",
          "name": "debuglog",
          "signatures": [
            {
              "return": {
                "textRaw": "Returns: {Function} The logging function ",
                "name": "return",
                "type": "Function",
                "desc": "The logging function"
              },
              "params": [
                {
                  "textRaw": "`section` {String} The section of the program to be debugged ",
                  "name": "section",
                  "type": "String",
                  "desc": "The section of the program to be debugged"
                }
              ]
            },
            {
              "params": [
                {
                  "name": "section"
                }
              ]
            }
          ],
          "desc": "<p>This is used to create a function which conditionally writes to stderr\nbased on the existence of a <code>NODE_DEBUG</code> environment variable.  If the\n<code>section</code> name appears in that environment variable, then the returned\nfunction will be similar to <code>console.error()</code>.  If not, then the\nreturned function is a no-op.\n\n</p>\n<p>For example:\n\n</p>\n<pre><code class=\"javascript\">var debuglog = util.debuglog(&#39;foo&#39;);\n\nvar bar = 123;\ndebuglog(&#39;hello from foo [%d]&#39;, bar);</code></pre>\n<p>If this program is run with <code>NODE_DEBUG=foo</code> in the environment, then\nit will output something like:\n\n</p>\n<pre><code>FOO 3245: hello from foo [123]</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.\n\n</p>\n<p>You may separate multiple <code>NODE_DEBUG</code> environment variables with a\ncomma.  For example, <code>NODE_DEBUG=fs,net,tls</code>.\n\n</p>\n"
        },
        {
          "textRaw": "util.deprecate(function, string)",
          "type": "method",
          "name": "deprecate",
          "desc": "<p>Marks that a method should not be used any more.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nexports.puts = util.deprecate(function() {\n  for (var i = 0, len = arguments.length; i &lt; len; ++i) {\n    process.stdout.write(arguments[i] + &#39;\\n&#39;);\n  }\n}, &#39;util.puts: Use console.log instead&#39;);</code></pre>\n<p>It returns a modified function which warns once by default.\n\n</p>\n<p>If <code>--no-deprecation</code> is set then this function is a NO-OP.  Configurable\nat run-time through the <code>process.noDeprecation</code> boolean (only effective\nwhen set before a module is loaded.)\n\n</p>\n<p>If <code>--trace-deprecation</code> is set, a warning and a stack trace are logged\nto the console the first time the deprecated API is used.  Configurable\nat run-time through the <code>process.traceDeprecation</code> boolean.\n\n</p>\n<p>If <code>--throw-deprecation</code> is set then the application throws an exception\nwhen the deprecated API is used.  Configurable at run-time through the\n<code>process.throwDeprecation</code> boolean.\n\n</p>\n<p><code>process.throwDeprecation</code> takes precedence over <code>process.traceDeprecation</code>.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "function"
                },
                {
                  "name": "string"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.error([...])",
          "type": "method",
          "name": "error",
          "stability": 0,
          "stabilityText": "Deprecated: Use console.error() instead.",
          "desc": "<p>Deprecated predecessor of <code>console.error</code>.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "...",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.format(format[, ...])",
          "type": "method",
          "name": "format",
          "desc": "<p>Returns a formatted string using the first argument as a <code>printf</code>-like format.\n\n</p>\n<p>The first argument is a string that contains zero or more <em>placeholders</em>.\nEach placeholder is replaced with the converted value from its corresponding\nargument. Supported placeholders are:\n\n</p>\n<ul>\n<li><code>%s</code> - String.</li>\n<li><code>%d</code> - Number (both integer and float).</li>\n<li><code>%j</code> - JSON.  Replaced with the string <code>&#39;[Circular]&#39;</code> if the argument\ncontains circular references.</li>\n<li><code>%%</code> - single percent sign (<code>&#39;%&#39;</code>). This does not consume an argument.</li>\n</ul>\n<p>If the placeholder does not have a corresponding argument, the placeholder is\nnot replaced.\n\n</p>\n<pre><code>util.format(&#39;%s:%s&#39;, &#39;foo&#39;); // &#39;foo:%s&#39;</code></pre>\n<p>If there are more arguments than placeholders, the extra arguments are\ncoerced to strings (for objects and symbols, <code>util.inspect()</code> is used)\nand then concatenated, delimited by a space.\n\n</p>\n<pre><code>util.format(&#39;%s:%s&#39;, &#39;foo&#39;, &#39;bar&#39;, &#39;baz&#39;); // &#39;foo:bar baz&#39;</code></pre>\n<p>If the first argument is not a format string then <code>util.format()</code> returns\na string that is the concatenation of all its arguments separated by spaces.\nEach argument is converted to a string with <code>util.inspect()</code>.\n\n</p>\n<pre><code>util.format(1, 2, 3); // &#39;1 2 3&#39;</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "format"
                },
                {
                  "name": "...",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.inherits(constructor, superConstructor)",
          "type": "method",
          "name": "inherits",
          "desc": "<p>Inherit the prototype methods from one [constructor][] into another.  The\nprototype of <code>constructor</code> will be set to a new object created from\n<code>superConstructor</code>.\n\n</p>\n<p>As an additional convenience, <code>superConstructor</code> will be accessible\nthrough the <code>constructor.super_</code> property.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\nconst EventEmitter = require(&#39;events&#39;);\n\nfunction MyStream() {\n    EventEmitter.call(this);\n}\n\nutil.inherits(MyStream, EventEmitter);\n\nMyStream.prototype.write = function(data) {\n    this.emit(&#39;data&#39;, data);\n}\n\nvar stream = new MyStream();\n\nconsole.log(stream instanceof EventEmitter); // true\nconsole.log(MyStream.super_ === EventEmitter); // true\n\nstream.on(&#39;data&#39;, (data) =&gt; {\n  console.log(`Received data: &quot;${data}&quot;`);\n})\nstream.write(&#39;It works!&#39;); // Received data: &quot;It works!&quot;</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "constructor"
                },
                {
                  "name": "superConstructor"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.inspect(object[, options])",
          "type": "method",
          "name": "inspect",
          "desc": "<p>Return a string representation of <code>object</code>, which is useful for debugging.\n\n</p>\n<p>An optional <em>options</em> object may be passed that alters certain aspects of the\nformatted string:\n\n</p>\n<ul>\n<li><p><code>showHidden</code> - if <code>true</code> then the object&#39;s non-enumerable and symbol\nproperties will be shown too. Defaults to <code>false</code>.</p>\n</li>\n<li><p><code>depth</code> - tells <code>inspect</code> how many times to recurse while formatting the\nobject. This is useful for inspecting large complicated objects. Defaults to\n<code>2</code>. To make it recurse indefinitely pass <code>null</code>.</p>\n</li>\n<li><p><code>colors</code> - if <code>true</code>, then the output will be styled with ANSI color codes.\nDefaults to <code>false</code>. Colors are customizable, see below.</p>\n</li>\n<li><p><code>customInspect</code> - if <code>false</code>, then custom <code>inspect(depth, opts)</code> functions\ndefined on the objects being inspected won&#39;t be called. Defaults to <code>true</code>.</p>\n</li>\n</ul>\n<p>Example of inspecting all properties of the <code>util</code> object:\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nconsole.log(util.inspect(util, { showHidden: true, depth: null }));</code></pre>\n<p>Values may supply their own custom <code>inspect(depth, opts)</code> functions, when\ncalled they receive the current depth in the recursive inspection, as well as\nthe options object passed to <code>util.inspect()</code>.\n\n</p>\n",
          "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 <code>util.inspect.styles</code> and <code>util.inspect.colors</code> objects.\n\n</p>\n<p><code>util.inspect.styles</code> is a map assigning each style a color\nfrom <code>util.inspect.colors</code>.\nHighlighted styles and their default values are:\n <em> <code>number</code> (yellow)\n </em> <code>boolean</code> (yellow)\n <em> <code>string</code> (green)\n </em> <code>date</code> (magenta)\n <em> <code>regexp</code> (red)\n </em> <code>null</code> (bold)\n <em> <code>undefined</code> (grey)\n </em> <code>special</code> - only function at this time (cyan)\n * <code>name</code> (intentionally no styling)\n\n</p>\n<p>Predefined color codes are: <code>white</code>, <code>grey</code>, <code>black</code>, <code>blue</code>, <code>cyan</code>,\n<code>green</code>, <code>magenta</code>, <code>red</code> and <code>yellow</code>.\nThere are also <code>bold</code>, <code>italic</code>, <code>underline</code> and <code>inverse</code> codes.\n\n</p>\n"
            },
            {
              "textRaw": "Custom `inspect()` function on Objects",
              "name": "Custom `inspect()` function on Objects",
              "type": "misc",
              "desc": "<p>Objects also may define their own <code>inspect(depth)</code> function which <code>util.inspect()</code>\nwill invoke and use the result of when inspecting the object:\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nvar obj = { name: &#39;nate&#39; };\nobj.inspect = function(depth) {\n  return `{${this.name}}`;\n};\n\nutil.inspect(obj);\n  // &quot;{nate}&quot;</code></pre>\n<p>You may also return another Object entirely, and the returned String will be\nformatted according to the returned Object. This is similar to how\n<code>JSON.stringify()</code> works:\n\n</p>\n<pre><code>var obj = { foo: &#39;this will not show up in the inspect() output&#39; };\nobj.inspect = function(depth) {\n  return { bar: &#39;baz&#39; };\n};\n\nutil.inspect(obj);\n  // &quot;{ bar: &#39;baz&#39; }&quot;</code></pre>\n"
            }
          ],
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                },
                {
                  "name": "options",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isArray(object)",
          "type": "method",
          "name": "isArray",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Internal alias for [<code>Array.isArray</code>][].\n\n</p>\n<p>Returns <code>true</code> if the given &quot;object&quot; is an <code>Array</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isArray([])\n  // true\nutil.isArray(new Array)\n  // true\nutil.isArray({})\n  // false</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isBoolean(object)",
          "type": "method",
          "name": "isBoolean",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is a <code>Boolean</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isBoolean(1)\n  // false\nutil.isBoolean(0)\n  // false\nutil.isBoolean(false)\n  // true</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isBuffer(object)",
          "type": "method",
          "name": "isBuffer",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Use <code>Buffer.isBuffer()</code> instead.\n\n</p>\n<p>Returns <code>true</code> if the given &quot;object&quot; is a <code>Buffer</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isBuffer({ length: 0 })\n  // false\nutil.isBuffer([])\n  // false\nutil.isBuffer(new Buffer(&#39;hello world&#39;))\n  // true</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isDate(object)",
          "type": "method",
          "name": "isDate",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is a <code>Date</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isDate(new Date())\n  // true\nutil.isDate(Date())\n  // false (without &#39;new&#39; returns a String)\nutil.isDate({})\n  // false</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isError(object)",
          "type": "method",
          "name": "isError",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is an [<code>Error</code>][]. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isError(new Error())\n  // true\nutil.isError(new TypeError())\n  // true\nutil.isError({ name: &#39;Error&#39;, message: &#39;an error occurred&#39; })\n  // false</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isFunction(object)",
          "type": "method",
          "name": "isFunction",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is a <code>Function</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nfunction Foo() {}\nvar Bar = function() {};\n\nutil.isFunction({})\n  // false\nutil.isFunction(Foo)\n  // true\nutil.isFunction(Bar)\n  // true</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isNull(object)",
          "type": "method",
          "name": "isNull",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is strictly <code>null</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isNull(0)\n  // false\nutil.isNull(undefined)\n  // false\nutil.isNull(null)\n  // true</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isNullOrUndefined(object)",
          "type": "method",
          "name": "isNullOrUndefined",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is <code>null</code> or <code>undefined</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isNullOrUndefined(0)\n  // false\nutil.isNullOrUndefined(undefined)\n  // true\nutil.isNullOrUndefined(null)\n  // true</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isNumber(object)",
          "type": "method",
          "name": "isNumber",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is a <code>Number</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isNumber(false)\n  // false\nutil.isNumber(Infinity)\n  // true\nutil.isNumber(0)\n  // true\nutil.isNumber(NaN)\n  // true</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isObject(object)",
          "type": "method",
          "name": "isObject",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is strictly an <code>Object</code> <strong>and</strong> not a\n<code>Function</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isObject(5)\n  // false\nutil.isObject(null)\n  // false\nutil.isObject({})\n  // true\nutil.isObject(function(){})\n  // false</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isPrimitive(object)",
          "type": "method",
          "name": "isPrimitive",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is a primitive type. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isPrimitive(5)\n  // true\nutil.isPrimitive(&#39;foo&#39;)\n  // true\nutil.isPrimitive(false)\n  // true\nutil.isPrimitive(null)\n  // true\nutil.isPrimitive(undefined)\n  // true\nutil.isPrimitive({})\n  // false\nutil.isPrimitive(function() {})\n  // false\nutil.isPrimitive(/^$/)\n  // false\nutil.isPrimitive(new Date())\n  // false</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isRegExp(object)",
          "type": "method",
          "name": "isRegExp",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is a <code>RegExp</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isRegExp(/some regexp/)\n  // true\nutil.isRegExp(new RegExp(&#39;another regexp&#39;))\n  // true\nutil.isRegExp({})\n  // false</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isString(object)",
          "type": "method",
          "name": "isString",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is a <code>String</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isString(&#39;&#39;)\n  // true\nutil.isString(&#39;foo&#39;)\n  // true\nutil.isString(String(&#39;foo&#39;))\n  // true\nutil.isString(5)\n  // false</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isSymbol(object)",
          "type": "method",
          "name": "isSymbol",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is a <code>Symbol</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nutil.isSymbol(5)\n  // false\nutil.isSymbol(&#39;foo&#39;)\n  // false\nutil.isSymbol(Symbol(&#39;foo&#39;))\n  // true</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.isUndefined(object)",
          "type": "method",
          "name": "isUndefined",
          "stability": 0,
          "stabilityText": "Deprecated",
          "desc": "<p>Returns <code>true</code> if the given &quot;object&quot; is <code>undefined</code>. <code>false</code> otherwise.\n\n</p>\n<pre><code>const util = require(&#39;util&#39;);\n\nvar foo;\nutil.isUndefined(5)\n  // false\nutil.isUndefined(foo)\n  // true\nutil.isUndefined(null)\n  // false</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "object"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.log(string)",
          "type": "method",
          "name": "log",
          "desc": "<p>Output with timestamp on <code>stdout</code>.\n\n</p>\n<pre><code>require(&#39;util&#39;).log(&#39;Timestamped message.&#39;);</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "string"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.print([...])",
          "type": "method",
          "name": "print",
          "stability": 0,
          "stabilityText": "Deprecated: Use `console.log` instead.",
          "desc": "<p>Deprecated predecessor of <code>console.log</code>.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "...",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.pump(readableStream, writableStream[, callback])",
          "type": "method",
          "name": "pump",
          "stability": 0,
          "stabilityText": "Deprecated: Use readableStream.pipe(writableStream)",
          "desc": "<p>Deprecated predecessor of <code>stream.pipe()</code>.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "readableStream"
                },
                {
                  "name": "writableStream"
                },
                {
                  "name": "callback",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "util.puts([...])",
          "type": "method",
          "name": "puts",
          "stability": 0,
          "stabilityText": "Deprecated: Use console.log() instead.",
          "desc": "<p>Deprecated predecessor of <code>console.log</code>.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "...",
                  "optional": true
                }
              ]
            }
          ]
        }
      ],
      "type": "module",
      "displayName": "util"
    }
  ]
}
