%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/doc/nodejs/api/
Upload File :
Create Path :
Current File : //usr/share/doc/nodejs/api/util.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <meta name="nodejs.org:node-version" content="v18.19.1">
  <title>Util | Node.js v18.19.1 Documentation</title>
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/hljs.css">
  <script async defer src="assets/api.js" type="text/javascript"></script>
  __JS_FLAVORED_DYNAMIC_CSS__
</head>
<body class="alt apidoc" id="api-section-util">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="index.html" title="Go back to the home page">
          Node.js
        </a>
      </div>
      <ul>
<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
</ul>
<hr class="line"/>

<ul>
<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
<li><a href="console.html" class="nav-console">Console</a></li>
<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
<li><a href="dns.html" class="nav-dns">DNS</a></li>
<li><a href="domain.html" class="nav-domain">Domain</a></li>
<li><a href="errors.html" class="nav-errors">Errors</a></li>
<li><a href="events.html" class="nav-events">Events</a></li>
<li><a href="fs.html" class="nav-fs">File system</a></li>
<li><a href="globals.html" class="nav-globals">Globals</a></li>
<li><a href="http.html" class="nav-http">HTTP</a></li>
<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https.html" class="nav-https">HTTPS</a></li>
<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
<li><a href="net.html" class="nav-net">Net</a></li>
<li><a href="os.html" class="nav-os">OS</a></li>
<li><a href="path.html" class="nav-path">Path</a></li>
<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
<li><a href="process.html" class="nav-process">Process</a></li>
<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
<li><a href="readline.html" class="nav-readline">Readline</a></li>
<li><a href="repl.html" class="nav-repl">REPL</a></li>
<li><a href="report.html" class="nav-report">Report</a></li>
<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
<li><a href="stream.html" class="nav-stream">Stream</a></li>
<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
<li><a href="test.html" class="nav-test">Test runner</a></li>
<li><a href="timers.html" class="nav-timers">Timers</a></li>
<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
<li><a href="tty.html" class="nav-tty">TTY</a></li>
<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
<li><a href="url.html" class="nav-url">URL</a></li>
<li><a href="util.html" class="nav-util active">Utilities</a></li>
<li><a href="v8.html" class="nav-v8">V8</a></li>
<li><a href="vm.html" class="nav-vm">VM</a></li>
<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
</ul>
<hr class="line"/>

<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
</ul>

    </div>

    <div id="column1" data-id="util" class="interior">
      <header class="header">
        <div class="header-container">
          <h1>Node.js v18.19.1 documentation</h1>
          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
              <path fill="none" d="M0 0h24v24H0z" />
              <path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/>
              <path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/>
            </svg>
            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
              <path d="M0 0h24v24H0z" fill="none" />
              <path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/>
            </svg>
          </button>
        </div>
        <div id="gtoc">
          <ul>
            <li class="pinned-header">Node.js v18.19.1</li>
            
    <li class="picker-header">
      <a href="#">
        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
        Table of contents
      </a>

      <div class="picker"><div class="toc"><ul>
<li><a href="#util">Util</a><ul>
<li><a href="#utilcallbackifyoriginal"><code>util.callbackify(original)</code></a></li>
<li><a href="#utildebuglogsection-callback"><code>util.debuglog(section[, callback])</code></a><ul>
<li><a href="#debuglogenabled"><code>debuglog().enabled</code></a></li>
</ul>
</li>
<li><a href="#utildebugsection"><code>util.debug(section)</code></a></li>
<li><a href="#utildeprecatefn-msg-code"><code>util.deprecate(fn, msg[, code])</code></a></li>
<li><a href="#utilformatformat-args"><code>util.format(format[, ...args])</code></a></li>
<li><a href="#utilformatwithoptionsinspectoptions-format-args"><code>util.formatWithOptions(inspectOptions, format[, ...args])</code></a></li>
<li><a href="#utilgetsystemerrornameerr"><code>util.getSystemErrorName(err)</code></a></li>
<li><a href="#utilgetsystemerrormap"><code>util.getSystemErrorMap()</code></a></li>
<li><a href="#utilinheritsconstructor-superconstructor"><code>util.inherits(constructor, superConstructor)</code></a></li>
<li><a href="#utilinspectobject-options"><code>util.inspect(object[, options])</code></a></li>
<li><a href="#utilinspectobject-showhidden-depth-colors"><code>util.inspect(object[, showHidden[, depth[, colors]]])</code></a><ul>
<li><a href="#customizing-utilinspect-colors">Customizing <code>util.inspect</code> colors</a><ul>
<li><a href="#modifiers">Modifiers</a></li>
<li><a href="#foreground-colors">Foreground colors</a></li>
<li><a href="#background-colors">Background colors</a></li>
</ul>
</li>
<li><a href="#custom-inspection-functions-on-objects">Custom inspection functions on objects</a></li>
<li><a href="#utilinspectcustom"><code>util.inspect.custom</code></a></li>
<li><a href="#utilinspectdefaultoptions"><code>util.inspect.defaultOptions</code></a></li>
</ul>
</li>
<li><a href="#utilisdeepstrictequalval1-val2"><code>util.isDeepStrictEqual(val1, val2)</code></a></li>
<li><a href="#class-utilmimetype">Class: <code>util.MIMEType</code></a><ul>
<li><a href="#constructor-new-mimetypeinput">Constructor: <code>new MIMEType(input)</code></a></li>
<li><a href="#mimetype"><code>mime.type</code></a></li>
<li><a href="#mimesubtype"><code>mime.subtype</code></a></li>
<li><a href="#mimeessence"><code>mime.essence</code></a></li>
<li><a href="#mimeparams"><code>mime.params</code></a></li>
<li><a href="#mimetostring"><code>mime.toString()</code></a></li>
<li><a href="#mimetojson"><code>mime.toJSON()</code></a></li>
</ul>
</li>
<li><a href="#class-utilmimeparams">Class: <code>util.MIMEParams</code></a><ul>
<li><a href="#constructor-new-mimeparams">Constructor: <code>new MIMEParams()</code></a></li>
<li><a href="#mimeparamsdeletename"><code>mimeParams.delete(name)</code></a></li>
<li><a href="#mimeparamsentries"><code>mimeParams.entries()</code></a></li>
<li><a href="#mimeparamsgetname"><code>mimeParams.get(name)</code></a></li>
<li><a href="#mimeparamshasname"><code>mimeParams.has(name)</code></a></li>
<li><a href="#mimeparamskeys"><code>mimeParams.keys()</code></a></li>
<li><a href="#mimeparamssetname-value"><code>mimeParams.set(name, value)</code></a></li>
<li><a href="#mimeparamsvalues"><code>mimeParams.values()</code></a></li>
<li><a href="#mimeparamsiterator"><code>mimeParams[@@iterator]()</code></a></li>
</ul>
</li>
<li><a href="#utilparseargsconfig"><code>util.parseArgs([config])</code></a><ul>
<li><a href="#parseargs-tokens"><code>parseArgs</code> <code>tokens</code></a></li>
</ul>
</li>
<li><a href="#utilpromisifyoriginal"><code>util.promisify(original)</code></a><ul>
<li><a href="#custom-promisified-functions">Custom promisified functions</a></li>
<li><a href="#utilpromisifycustom"><code>util.promisify.custom</code></a></li>
</ul>
</li>
<li><a href="#utilstripvtcontrolcharactersstr"><code>util.stripVTControlCharacters(str)</code></a></li>
<li><a href="#class-utiltextdecoder">Class: <code>util.TextDecoder</code></a><ul>
<li><a href="#whatwg-supported-encodings">WHATWG supported encodings</a><ul>
<li><a href="#encodings-supported-by-default-with-full-icu-data">Encodings supported by default (with full ICU data)</a></li>
<li><a href="#encodings-supported-when-nodejs-is-built-with-the-small-icu-option">Encodings supported when Node.js is built with the <code>small-icu</code> option</a></li>
<li><a href="#encodings-supported-when-icu-is-disabled">Encodings supported when ICU is disabled</a></li>
</ul>
</li>
<li><a href="#new-textdecoderencoding-options"><code>new TextDecoder([encoding[, options]])</code></a></li>
<li><a href="#textdecoderdecodeinput-options"><code>textDecoder.decode([input[, options]])</code></a></li>
<li><a href="#textdecoderencoding"><code>textDecoder.encoding</code></a></li>
<li><a href="#textdecoderfatal"><code>textDecoder.fatal</code></a></li>
<li><a href="#textdecoderignorebom"><code>textDecoder.ignoreBOM</code></a></li>
</ul>
</li>
<li><a href="#class-utiltextencoder">Class: <code>util.TextEncoder</code></a><ul>
<li><a href="#textencoderencodeinput"><code>textEncoder.encode([input])</code></a></li>
<li><a href="#textencoderencodeintosrc-dest"><code>textEncoder.encodeInto(src, dest)</code></a></li>
<li><a href="#textencoderencoding"><code>textEncoder.encoding</code></a></li>
</ul>
</li>
<li><a href="#utiltousvstringstring"><code>util.toUSVString(string)</code></a></li>
<li><a href="#utiltransferableabortcontroller"><code>util.transferableAbortController()</code></a></li>
<li><a href="#utiltransferableabortsignalsignal"><code>util.transferableAbortSignal(signal)</code></a></li>
<li><a href="#utilabortedsignal-resource"><code>util.aborted(signal, resource)</code></a></li>
<li><a href="#utiltypes"><code>util.types</code></a><ul>
<li><a href="#utiltypesisanyarraybuffervalue"><code>util.types.isAnyArrayBuffer(value)</code></a></li>
<li><a href="#utiltypesisarraybufferviewvalue"><code>util.types.isArrayBufferView(value)</code></a></li>
<li><a href="#utiltypesisargumentsobjectvalue"><code>util.types.isArgumentsObject(value)</code></a></li>
<li><a href="#utiltypesisarraybuffervalue"><code>util.types.isArrayBuffer(value)</code></a></li>
<li><a href="#utiltypesisasyncfunctionvalue"><code>util.types.isAsyncFunction(value)</code></a></li>
<li><a href="#utiltypesisbigint64arrayvalue"><code>util.types.isBigInt64Array(value)</code></a></li>
<li><a href="#utiltypesisbiguint64arrayvalue"><code>util.types.isBigUint64Array(value)</code></a></li>
<li><a href="#utiltypesisbooleanobjectvalue"><code>util.types.isBooleanObject(value)</code></a></li>
<li><a href="#utiltypesisboxedprimitivevalue"><code>util.types.isBoxedPrimitive(value)</code></a></li>
<li><a href="#utiltypesiscryptokeyvalue"><code>util.types.isCryptoKey(value)</code></a></li>
<li><a href="#utiltypesisdataviewvalue"><code>util.types.isDataView(value)</code></a></li>
<li><a href="#utiltypesisdatevalue"><code>util.types.isDate(value)</code></a></li>
<li><a href="#utiltypesisexternalvalue"><code>util.types.isExternal(value)</code></a></li>
<li><a href="#utiltypesisfloat32arrayvalue"><code>util.types.isFloat32Array(value)</code></a></li>
<li><a href="#utiltypesisfloat64arrayvalue"><code>util.types.isFloat64Array(value)</code></a></li>
<li><a href="#utiltypesisgeneratorfunctionvalue"><code>util.types.isGeneratorFunction(value)</code></a></li>
<li><a href="#utiltypesisgeneratorobjectvalue"><code>util.types.isGeneratorObject(value)</code></a></li>
<li><a href="#utiltypesisint8arrayvalue"><code>util.types.isInt8Array(value)</code></a></li>
<li><a href="#utiltypesisint16arrayvalue"><code>util.types.isInt16Array(value)</code></a></li>
<li><a href="#utiltypesisint32arrayvalue"><code>util.types.isInt32Array(value)</code></a></li>
<li><a href="#utiltypesiskeyobjectvalue"><code>util.types.isKeyObject(value)</code></a></li>
<li><a href="#utiltypesismapvalue"><code>util.types.isMap(value)</code></a></li>
<li><a href="#utiltypesismapiteratorvalue"><code>util.types.isMapIterator(value)</code></a></li>
<li><a href="#utiltypesismodulenamespaceobjectvalue"><code>util.types.isModuleNamespaceObject(value)</code></a></li>
<li><a href="#utiltypesisnativeerrorvalue"><code>util.types.isNativeError(value)</code></a></li>
<li><a href="#utiltypesisnumberobjectvalue"><code>util.types.isNumberObject(value)</code></a></li>
<li><a href="#utiltypesispromisevalue"><code>util.types.isPromise(value)</code></a></li>
<li><a href="#utiltypesisproxyvalue"><code>util.types.isProxy(value)</code></a></li>
<li><a href="#utiltypesisregexpvalue"><code>util.types.isRegExp(value)</code></a></li>
<li><a href="#utiltypesissetvalue"><code>util.types.isSet(value)</code></a></li>
<li><a href="#utiltypesissetiteratorvalue"><code>util.types.isSetIterator(value)</code></a></li>
<li><a href="#utiltypesissharedarraybuffervalue"><code>util.types.isSharedArrayBuffer(value)</code></a></li>
<li><a href="#utiltypesisstringobjectvalue"><code>util.types.isStringObject(value)</code></a></li>
<li><a href="#utiltypesissymbolobjectvalue"><code>util.types.isSymbolObject(value)</code></a></li>
<li><a href="#utiltypesistypedarrayvalue"><code>util.types.isTypedArray(value)</code></a></li>
<li><a href="#utiltypesisuint8arrayvalue"><code>util.types.isUint8Array(value)</code></a></li>
<li><a href="#utiltypesisuint8clampedarrayvalue"><code>util.types.isUint8ClampedArray(value)</code></a></li>
<li><a href="#utiltypesisuint16arrayvalue"><code>util.types.isUint16Array(value)</code></a></li>
<li><a href="#utiltypesisuint32arrayvalue"><code>util.types.isUint32Array(value)</code></a></li>
<li><a href="#utiltypesisweakmapvalue"><code>util.types.isWeakMap(value)</code></a></li>
<li><a href="#utiltypesisweaksetvalue"><code>util.types.isWeakSet(value)</code></a></li>
<li><a href="#utiltypesiswebassemblycompiledmodulevalue"><code>util.types.isWebAssemblyCompiledModule(value)</code></a></li>
</ul>
</li>
<li><a href="#deprecated-apis">Deprecated APIs</a><ul>
<li><a href="#util_extendtarget-source"><code>util._extend(target, source)</code></a></li>
<li><a href="#utilisarrayobject"><code>util.isArray(object)</code></a></li>
<li><a href="#utilisbooleanobject"><code>util.isBoolean(object)</code></a></li>
<li><a href="#utilisbufferobject"><code>util.isBuffer(object)</code></a></li>
<li><a href="#utilisdateobject"><code>util.isDate(object)</code></a></li>
<li><a href="#utiliserrorobject"><code>util.isError(object)</code></a></li>
<li><a href="#utilisfunctionobject"><code>util.isFunction(object)</code></a></li>
<li><a href="#utilisnullobject"><code>util.isNull(object)</code></a></li>
<li><a href="#utilisnullorundefinedobject"><code>util.isNullOrUndefined(object)</code></a></li>
<li><a href="#utilisnumberobject"><code>util.isNumber(object)</code></a></li>
<li><a href="#utilisobjectobject"><code>util.isObject(object)</code></a></li>
<li><a href="#utilisprimitiveobject"><code>util.isPrimitive(object)</code></a></li>
<li><a href="#utilisregexpobject"><code>util.isRegExp(object)</code></a></li>
<li><a href="#utilisstringobject"><code>util.isString(object)</code></a></li>
<li><a href="#utilissymbolobject"><code>util.isSymbol(object)</code></a></li>
<li><a href="#utilisundefinedobject"><code>util.isUndefined(object)</code></a></li>
<li><a href="#utillogstring"><code>util.log(string)</code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div></div>
    </li>
  
            
    <li class="picker-header">
      <a href="#">
        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
        Index
      </a>

      <div class="picker"><ul>
<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>

      <li>
        <a href="index.html">Index</a>
      </li>
    </ul>
  
<hr class="line"/>

<ul>
<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
<li><a href="console.html" class="nav-console">Console</a></li>
<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
<li><a href="dns.html" class="nav-dns">DNS</a></li>
<li><a href="domain.html" class="nav-domain">Domain</a></li>
<li><a href="errors.html" class="nav-errors">Errors</a></li>
<li><a href="events.html" class="nav-events">Events</a></li>
<li><a href="fs.html" class="nav-fs">File system</a></li>
<li><a href="globals.html" class="nav-globals">Globals</a></li>
<li><a href="http.html" class="nav-http">HTTP</a></li>
<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https.html" class="nav-https">HTTPS</a></li>
<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
<li><a href="net.html" class="nav-net">Net</a></li>
<li><a href="os.html" class="nav-os">OS</a></li>
<li><a href="path.html" class="nav-path">Path</a></li>
<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
<li><a href="process.html" class="nav-process">Process</a></li>
<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
<li><a href="readline.html" class="nav-readline">Readline</a></li>
<li><a href="repl.html" class="nav-repl">REPL</a></li>
<li><a href="report.html" class="nav-report">Report</a></li>
<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
<li><a href="stream.html" class="nav-stream">Stream</a></li>
<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
<li><a href="test.html" class="nav-test">Test runner</a></li>
<li><a href="timers.html" class="nav-timers">Timers</a></li>
<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
<li><a href="tty.html" class="nav-tty">TTY</a></li>
<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
<li><a href="url.html" class="nav-url">URL</a></li>
<li><a href="util.html" class="nav-util active">Utilities</a></li>
<li><a href="v8.html" class="nav-v8">V8</a></li>
<li><a href="vm.html" class="nav-vm">VM</a></li>
<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
</ul>
<hr class="line"/>

<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
</ul>
</div>
    </li>
  
            
    <li class="picker-header">
      <a href="#">
        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
        Other versions
      </a>
      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v18.x/api/util.html">18.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v17.x/api/util.html">17.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v16.x/api/util.html">16.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v15.x/api/util.html">15.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v14.x/api/util.html">14.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v13.x/api/util.html">13.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v12.x/api/util.html">12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v11.x/api/util.html">11.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v10.x/api/util.html">10.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v9.x/api/util.html">9.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v8.x/api/util.html">8.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v7.x/api/util.html">7.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v6.x/api/util.html">6.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v5.x/api/util.html">5.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v4.x/api/util.html">4.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/util.html">0.12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/util.html">0.10.x</a></li></ol></div>
    </li>
  
            <li class="picker-header">
              <a href="#">
                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
                Options
              </a>
        
              <div class="picker">
                <ul>
                  <li>
                    <a href="all.html">View on single page</a>
                  </li>
                  <li>
                    <a href="util.json">View as JSON</a>
                  </li>
                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/util.md">Edit on GitHub</a></li>    
                </ul>
              </div>
            </li>
          </ul>
        </div>
        <hr>
      </header>

      <details id="toc" open><summary>Table of contents</summary><ul>
<li><a href="#util">Util</a><ul>
<li><a href="#utilcallbackifyoriginal"><code>util.callbackify(original)</code></a></li>
<li><a href="#utildebuglogsection-callback"><code>util.debuglog(section[, callback])</code></a><ul>
<li><a href="#debuglogenabled"><code>debuglog().enabled</code></a></li>
</ul>
</li>
<li><a href="#utildebugsection"><code>util.debug(section)</code></a></li>
<li><a href="#utildeprecatefn-msg-code"><code>util.deprecate(fn, msg[, code])</code></a></li>
<li><a href="#utilformatformat-args"><code>util.format(format[, ...args])</code></a></li>
<li><a href="#utilformatwithoptionsinspectoptions-format-args"><code>util.formatWithOptions(inspectOptions, format[, ...args])</code></a></li>
<li><a href="#utilgetsystemerrornameerr"><code>util.getSystemErrorName(err)</code></a></li>
<li><a href="#utilgetsystemerrormap"><code>util.getSystemErrorMap()</code></a></li>
<li><a href="#utilinheritsconstructor-superconstructor"><code>util.inherits(constructor, superConstructor)</code></a></li>
<li><a href="#utilinspectobject-options"><code>util.inspect(object[, options])</code></a></li>
<li><a href="#utilinspectobject-showhidden-depth-colors"><code>util.inspect(object[, showHidden[, depth[, colors]]])</code></a><ul>
<li><a href="#customizing-utilinspect-colors">Customizing <code>util.inspect</code> colors</a><ul>
<li><a href="#modifiers">Modifiers</a></li>
<li><a href="#foreground-colors">Foreground colors</a></li>
<li><a href="#background-colors">Background colors</a></li>
</ul>
</li>
<li><a href="#custom-inspection-functions-on-objects">Custom inspection functions on objects</a></li>
<li><a href="#utilinspectcustom"><code>util.inspect.custom</code></a></li>
<li><a href="#utilinspectdefaultoptions"><code>util.inspect.defaultOptions</code></a></li>
</ul>
</li>
<li><a href="#utilisdeepstrictequalval1-val2"><code>util.isDeepStrictEqual(val1, val2)</code></a></li>
<li><a href="#class-utilmimetype">Class: <code>util.MIMEType</code></a><ul>
<li><a href="#constructor-new-mimetypeinput">Constructor: <code>new MIMEType(input)</code></a></li>
<li><a href="#mimetype"><code>mime.type</code></a></li>
<li><a href="#mimesubtype"><code>mime.subtype</code></a></li>
<li><a href="#mimeessence"><code>mime.essence</code></a></li>
<li><a href="#mimeparams"><code>mime.params</code></a></li>
<li><a href="#mimetostring"><code>mime.toString()</code></a></li>
<li><a href="#mimetojson"><code>mime.toJSON()</code></a></li>
</ul>
</li>
<li><a href="#class-utilmimeparams">Class: <code>util.MIMEParams</code></a><ul>
<li><a href="#constructor-new-mimeparams">Constructor: <code>new MIMEParams()</code></a></li>
<li><a href="#mimeparamsdeletename"><code>mimeParams.delete(name)</code></a></li>
<li><a href="#mimeparamsentries"><code>mimeParams.entries()</code></a></li>
<li><a href="#mimeparamsgetname"><code>mimeParams.get(name)</code></a></li>
<li><a href="#mimeparamshasname"><code>mimeParams.has(name)</code></a></li>
<li><a href="#mimeparamskeys"><code>mimeParams.keys()</code></a></li>
<li><a href="#mimeparamssetname-value"><code>mimeParams.set(name, value)</code></a></li>
<li><a href="#mimeparamsvalues"><code>mimeParams.values()</code></a></li>
<li><a href="#mimeparamsiterator"><code>mimeParams[@@iterator]()</code></a></li>
</ul>
</li>
<li><a href="#utilparseargsconfig"><code>util.parseArgs([config])</code></a><ul>
<li><a href="#parseargs-tokens"><code>parseArgs</code> <code>tokens</code></a></li>
</ul>
</li>
<li><a href="#utilpromisifyoriginal"><code>util.promisify(original)</code></a><ul>
<li><a href="#custom-promisified-functions">Custom promisified functions</a></li>
<li><a href="#utilpromisifycustom"><code>util.promisify.custom</code></a></li>
</ul>
</li>
<li><a href="#utilstripvtcontrolcharactersstr"><code>util.stripVTControlCharacters(str)</code></a></li>
<li><a href="#class-utiltextdecoder">Class: <code>util.TextDecoder</code></a><ul>
<li><a href="#whatwg-supported-encodings">WHATWG supported encodings</a><ul>
<li><a href="#encodings-supported-by-default-with-full-icu-data">Encodings supported by default (with full ICU data)</a></li>
<li><a href="#encodings-supported-when-nodejs-is-built-with-the-small-icu-option">Encodings supported when Node.js is built with the <code>small-icu</code> option</a></li>
<li><a href="#encodings-supported-when-icu-is-disabled">Encodings supported when ICU is disabled</a></li>
</ul>
</li>
<li><a href="#new-textdecoderencoding-options"><code>new TextDecoder([encoding[, options]])</code></a></li>
<li><a href="#textdecoderdecodeinput-options"><code>textDecoder.decode([input[, options]])</code></a></li>
<li><a href="#textdecoderencoding"><code>textDecoder.encoding</code></a></li>
<li><a href="#textdecoderfatal"><code>textDecoder.fatal</code></a></li>
<li><a href="#textdecoderignorebom"><code>textDecoder.ignoreBOM</code></a></li>
</ul>
</li>
<li><a href="#class-utiltextencoder">Class: <code>util.TextEncoder</code></a><ul>
<li><a href="#textencoderencodeinput"><code>textEncoder.encode([input])</code></a></li>
<li><a href="#textencoderencodeintosrc-dest"><code>textEncoder.encodeInto(src, dest)</code></a></li>
<li><a href="#textencoderencoding"><code>textEncoder.encoding</code></a></li>
</ul>
</li>
<li><a href="#utiltousvstringstring"><code>util.toUSVString(string)</code></a></li>
<li><a href="#utiltransferableabortcontroller"><code>util.transferableAbortController()</code></a></li>
<li><a href="#utiltransferableabortsignalsignal"><code>util.transferableAbortSignal(signal)</code></a></li>
<li><a href="#utilabortedsignal-resource"><code>util.aborted(signal, resource)</code></a></li>
<li><a href="#utiltypes"><code>util.types</code></a><ul>
<li><a href="#utiltypesisanyarraybuffervalue"><code>util.types.isAnyArrayBuffer(value)</code></a></li>
<li><a href="#utiltypesisarraybufferviewvalue"><code>util.types.isArrayBufferView(value)</code></a></li>
<li><a href="#utiltypesisargumentsobjectvalue"><code>util.types.isArgumentsObject(value)</code></a></li>
<li><a href="#utiltypesisarraybuffervalue"><code>util.types.isArrayBuffer(value)</code></a></li>
<li><a href="#utiltypesisasyncfunctionvalue"><code>util.types.isAsyncFunction(value)</code></a></li>
<li><a href="#utiltypesisbigint64arrayvalue"><code>util.types.isBigInt64Array(value)</code></a></li>
<li><a href="#utiltypesisbiguint64arrayvalue"><code>util.types.isBigUint64Array(value)</code></a></li>
<li><a href="#utiltypesisbooleanobjectvalue"><code>util.types.isBooleanObject(value)</code></a></li>
<li><a href="#utiltypesisboxedprimitivevalue"><code>util.types.isBoxedPrimitive(value)</code></a></li>
<li><a href="#utiltypesiscryptokeyvalue"><code>util.types.isCryptoKey(value)</code></a></li>
<li><a href="#utiltypesisdataviewvalue"><code>util.types.isDataView(value)</code></a></li>
<li><a href="#utiltypesisdatevalue"><code>util.types.isDate(value)</code></a></li>
<li><a href="#utiltypesisexternalvalue"><code>util.types.isExternal(value)</code></a></li>
<li><a href="#utiltypesisfloat32arrayvalue"><code>util.types.isFloat32Array(value)</code></a></li>
<li><a href="#utiltypesisfloat64arrayvalue"><code>util.types.isFloat64Array(value)</code></a></li>
<li><a href="#utiltypesisgeneratorfunctionvalue"><code>util.types.isGeneratorFunction(value)</code></a></li>
<li><a href="#utiltypesisgeneratorobjectvalue"><code>util.types.isGeneratorObject(value)</code></a></li>
<li><a href="#utiltypesisint8arrayvalue"><code>util.types.isInt8Array(value)</code></a></li>
<li><a href="#utiltypesisint16arrayvalue"><code>util.types.isInt16Array(value)</code></a></li>
<li><a href="#utiltypesisint32arrayvalue"><code>util.types.isInt32Array(value)</code></a></li>
<li><a href="#utiltypesiskeyobjectvalue"><code>util.types.isKeyObject(value)</code></a></li>
<li><a href="#utiltypesismapvalue"><code>util.types.isMap(value)</code></a></li>
<li><a href="#utiltypesismapiteratorvalue"><code>util.types.isMapIterator(value)</code></a></li>
<li><a href="#utiltypesismodulenamespaceobjectvalue"><code>util.types.isModuleNamespaceObject(value)</code></a></li>
<li><a href="#utiltypesisnativeerrorvalue"><code>util.types.isNativeError(value)</code></a></li>
<li><a href="#utiltypesisnumberobjectvalue"><code>util.types.isNumberObject(value)</code></a></li>
<li><a href="#utiltypesispromisevalue"><code>util.types.isPromise(value)</code></a></li>
<li><a href="#utiltypesisproxyvalue"><code>util.types.isProxy(value)</code></a></li>
<li><a href="#utiltypesisregexpvalue"><code>util.types.isRegExp(value)</code></a></li>
<li><a href="#utiltypesissetvalue"><code>util.types.isSet(value)</code></a></li>
<li><a href="#utiltypesissetiteratorvalue"><code>util.types.isSetIterator(value)</code></a></li>
<li><a href="#utiltypesissharedarraybuffervalue"><code>util.types.isSharedArrayBuffer(value)</code></a></li>
<li><a href="#utiltypesisstringobjectvalue"><code>util.types.isStringObject(value)</code></a></li>
<li><a href="#utiltypesissymbolobjectvalue"><code>util.types.isSymbolObject(value)</code></a></li>
<li><a href="#utiltypesistypedarrayvalue"><code>util.types.isTypedArray(value)</code></a></li>
<li><a href="#utiltypesisuint8arrayvalue"><code>util.types.isUint8Array(value)</code></a></li>
<li><a href="#utiltypesisuint8clampedarrayvalue"><code>util.types.isUint8ClampedArray(value)</code></a></li>
<li><a href="#utiltypesisuint16arrayvalue"><code>util.types.isUint16Array(value)</code></a></li>
<li><a href="#utiltypesisuint32arrayvalue"><code>util.types.isUint32Array(value)</code></a></li>
<li><a href="#utiltypesisweakmapvalue"><code>util.types.isWeakMap(value)</code></a></li>
<li><a href="#utiltypesisweaksetvalue"><code>util.types.isWeakSet(value)</code></a></li>
<li><a href="#utiltypesiswebassemblycompiledmodulevalue"><code>util.types.isWebAssemblyCompiledModule(value)</code></a></li>
</ul>
</li>
<li><a href="#deprecated-apis">Deprecated APIs</a><ul>
<li><a href="#util_extendtarget-source"><code>util._extend(target, source)</code></a></li>
<li><a href="#utilisarrayobject"><code>util.isArray(object)</code></a></li>
<li><a href="#utilisbooleanobject"><code>util.isBoolean(object)</code></a></li>
<li><a href="#utilisbufferobject"><code>util.isBuffer(object)</code></a></li>
<li><a href="#utilisdateobject"><code>util.isDate(object)</code></a></li>
<li><a href="#utiliserrorobject"><code>util.isError(object)</code></a></li>
<li><a href="#utilisfunctionobject"><code>util.isFunction(object)</code></a></li>
<li><a href="#utilisnullobject"><code>util.isNull(object)</code></a></li>
<li><a href="#utilisnullorundefinedobject"><code>util.isNullOrUndefined(object)</code></a></li>
<li><a href="#utilisnumberobject"><code>util.isNumber(object)</code></a></li>
<li><a href="#utilisobjectobject"><code>util.isObject(object)</code></a></li>
<li><a href="#utilisprimitiveobject"><code>util.isPrimitive(object)</code></a></li>
<li><a href="#utilisregexpobject"><code>util.isRegExp(object)</code></a></li>
<li><a href="#utilisstringobject"><code>util.isString(object)</code></a></li>
<li><a href="#utilissymbolobject"><code>util.isSymbol(object)</code></a></li>
<li><a href="#utilisundefinedobject"><code>util.isUndefined(object)</code></a></li>
<li><a href="#utillogstring"><code>util.log(string)</code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</details>

      <div id="apicontent">
        <h2>Util<span><a class="mark" href="#util" id="util">#</a></span><a aria-hidden="true" class="legacy" id="util_util"></a></h2>
<!--introduced_in=v0.10.0-->

<blockquote>
<p>Stability: 2 - Stable</p>
</blockquote>
<!-- source_link=lib/util.js -->

<p>The <code>node:util</code> module supports the needs of Node.js internal APIs. Many of the
utilities are useful for application and module developers as well. To access
it:</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);
</code></pre>
<section><h3><code>util.callbackify(original)</code><span><a class="mark" href="#utilcallbackifyoriginal" id="utilcallbackifyoriginal">#</a></span><a aria-hidden="true" class="legacy" id="util_util_callbackify_original"></a></h3>
<div class="api_metadata">
<span>Added in: v8.2.0</span>
</div><ul>
<li><code>original</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> An <code>async</code> function</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> a callback style function</li>
</ul>
<p>Takes an <code>async</code> function (or a function that returns a <code>Promise</code>) and returns a
function following the error-first callback style, i.e. taking
an <code>(err, value) =&gt; ...</code> callback as the last argument. In the callback, the
first argument will be the rejection reason (or <code>null</code> if the <code>Promise</code>
resolved), and the second argument will be the resolved value.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

async function fn() {
  return &#39;hello world&#39;;
}
const callbackFunction = util.callbackify(fn);

callbackFunction((err, ret) =&gt; {
  if (err) throw err;
  console.log(ret);
});
</code></pre>
<p>Will print:</p>
<pre><code class="language-text">hello world
</code></pre>
<p>The callback is executed asynchronously, and will have a limited stack trace.
If the callback throws, the process will emit an <a href="process.html#event-uncaughtexception"><code>&#39;uncaughtException&#39;</code></a>
event, and if not handled will exit.</p>
<p>Since <code>null</code> has a special meaning as the first argument to a callback, if a
wrapped function rejects a <code>Promise</code> with a falsy value as a reason, the value
is wrapped in an <code>Error</code> with the original value stored in a field named
<code>reason</code>.</p>
<pre><code class="language-js">function fn() {
  return Promise.reject(null);
}
const callbackFunction = util.callbackify(fn);

callbackFunction((err, ret) =&gt; {
  // When the Promise was rejected with `null` it is wrapped with an Error and
  // the original value is stored in `reason`.
  err &amp;&amp; Object.hasOwn(err, &#39;reason&#39;) &amp;&amp; err.reason === null;  // true
});
</code></pre>
</section><section><h3><code>util.debuglog(section[, callback])</code><span><a class="mark" href="#utildebuglogsection-callback" id="utildebuglogsection-callback">#</a></span><a aria-hidden="true" class="legacy" id="util_util_debuglog_section_callback"></a></h3>
<div class="api_metadata">
<span>Added in: v0.11.3</span>
</div><ul>
<li><code>section</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> A string identifying the portion of the application for
which the <code>debuglog</code> function is being created.</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> A callback invoked the first time the logging function
is called with a function argument that is a more optimized logging function.</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> The logging function</li>
</ul>
<p>The <code>util.debuglog()</code> method is used to create a function that conditionally
writes debug messages to <code>stderr</code> based on the existence of the <code>NODE_DEBUG</code>
environment variable. If the <code>section</code> name appears within the value of that
environment variable, then the returned function operates similar to
<a href="console.html#consoleerrordata-args"><code>console.error()</code></a>. If not, then the returned function is a no-op.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);
const debuglog = util.debuglog(&#39;foo&#39;);

debuglog(&#39;hello from foo [%d]&#39;, 123);
</code></pre>
<p>If this program is run with <code>NODE_DEBUG=foo</code> in the environment, then
it will output something like:</p>
<pre><code class="language-console">FOO 3245: hello from foo [123]
</code></pre>
<p>where <code>3245</code> is the process id. If it is not run with that
environment variable set, then it will not print anything.</p>
<p>The <code>section</code> supports wildcard also:</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);
const debuglog = util.debuglog(&#39;foo-bar&#39;);

debuglog(&#39;hi there, it\&#39;s foo-bar [%d]&#39;, 2333);
</code></pre>
<p>if it is run with <code>NODE_DEBUG=foo*</code> in the environment, then it will output
something like:</p>
<pre><code class="language-console">FOO-BAR 3257: hi there, it&#39;s foo-bar [2333]
</code></pre>
<p>Multiple comma-separated <code>section</code> names may be specified in the <code>NODE_DEBUG</code>
environment variable: <code>NODE_DEBUG=fs,net,tls</code>.</p>
<p>The optional <code>callback</code> argument can be used to replace the logging function
with a different function that doesn&#39;t have any initialization or
unnecessary wrapping.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);
let debuglog = util.debuglog(&#39;internals&#39;, (debug) =&gt; {
  // Replace with a logging function that optimizes out
  // testing if the section is enabled
  debuglog = debug;
});
</code></pre>
<h4><code>debuglog().enabled</code><span><a class="mark" href="#debuglogenabled" id="debuglogenabled">#</a></span><a aria-hidden="true" class="legacy" id="util_debuglog_enabled"></a></h4>
<div class="api_metadata">
<span>Added in: v14.9.0</span>
</div><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>The <code>util.debuglog().enabled</code> getter is used to create a test that can be used
in conditionals based on the existence of the <code>NODE_DEBUG</code> environment variable.
If the <code>section</code> name appears within the value of that environment variable,
then the returned value will be <code>true</code>. If not, then the returned value will be
<code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);
const enabled = util.debuglog(&#39;foo&#39;).enabled;
if (enabled) {
  console.log(&#39;hello from foo [%d]&#39;, 123);
}
</code></pre>
<p>If this program is run with <code>NODE_DEBUG=foo</code> in the environment, then it will
output something like:</p>
<pre><code class="language-console">hello from foo [123]
</code></pre>
</section><section><h3><code>util.debug(section)</code><span><a class="mark" href="#utildebugsection" id="utildebugsection">#</a></span><a aria-hidden="true" class="legacy" id="util_util_debug_section"></a></h3>
<div class="api_metadata">
<span>Added in: v14.9.0</span>
</div><p>Alias for <code>util.debuglog</code>. Usage allows for readability of that doesn&#39;t imply
logging when only using <code>util.debuglog().enabled</code>.</p>
</section><section><h3><code>util.deprecate(fn, msg[, code])</code><span><a class="mark" href="#utildeprecatefn-msg-code" id="utildeprecatefn-msg-code">#</a></span><a aria-hidden="true" class="legacy" id="util_util_deprecate_fn_msg_code"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v10.0.0</td>
<td><p>Deprecation warnings are only emitted once for each code.</p>
</td></tr>
<tr><td>v0.8.0</td>
<td><p><span>Added in: v0.8.0</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> The function that is being deprecated.</li>
<li><code>msg</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> A warning message to display when the deprecated function is
invoked.</li>
<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> A deprecation code. See the <a href="deprecations.html#list-of-deprecated-apis">list of deprecated APIs</a> for a
list of codes.</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> The deprecated function wrapped to emit a warning.</li>
</ul>
<p>The <code>util.deprecate()</code> method wraps <code>fn</code> (which may be a function or class) in
such a way that it is marked as deprecated.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

exports.obsoleteFunction = util.deprecate(() =&gt; {
  // Do something here.
}, &#39;obsoleteFunction() is deprecated. Use newShinyFunction() instead.&#39;);
</code></pre>
<p>When called, <code>util.deprecate()</code> will return a function that will emit a
<code>DeprecationWarning</code> using the <a href="process.html#event-warning"><code>&#39;warning&#39;</code></a> event. The warning will
be emitted and printed to <code>stderr</code> the first time the returned function is
called. After the warning is emitted, the wrapped function is called without
emitting a warning.</p>
<p>If the same optional <code>code</code> is supplied in multiple calls to <code>util.deprecate()</code>,
the warning will be emitted only once for that <code>code</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

const fn1 = util.deprecate(someFunction, someMessage, &#39;DEP0001&#39;);
const fn2 = util.deprecate(someOtherFunction, someOtherMessage, &#39;DEP0001&#39;);
fn1(); // Emits a deprecation warning with code DEP0001
fn2(); // Does not emit a deprecation warning because it has the same code
</code></pre>
<p>If either the <code>--no-deprecation</code> or <code>--no-warnings</code> command-line flags are
used, or if the <code>process.noDeprecation</code> property is set to <code>true</code> <em>prior</em> to
the first deprecation warning, the <code>util.deprecate()</code> method does nothing.</p>
<p>If the <code>--trace-deprecation</code> or <code>--trace-warnings</code> command-line flags are set,
or the <code>process.traceDeprecation</code> property is set to <code>true</code>, a warning and a
stack trace are printed to <code>stderr</code> the first time the deprecated function is
called.</p>
<p>If the <code>--throw-deprecation</code> command-line flag is set, or the
<code>process.throwDeprecation</code> property is set to <code>true</code>, then an exception will be
thrown when the deprecated function is called.</p>
<p>The <code>--throw-deprecation</code> command-line flag and <code>process.throwDeprecation</code>
property take precedence over <code>--trace-deprecation</code> and
<code>process.traceDeprecation</code>.</p>
</section><section><h3><code>util.format(format[, ...args])</code><span><a class="mark" href="#utilformatformat-args" id="utilformatformat-args">#</a></span><a aria-hidden="true" class="legacy" id="util_util_format_format_args"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v12.11.0</td>
<td><p>The <code>%c</code> specifier is ignored now.</p>
</td></tr>
<tr><td>v12.0.0</td>
<td><p>The <code>format</code> argument is now only taken as such if it actually contains format specifiers.</p>
</td></tr>
<tr><td>v12.0.0</td>
<td><p>If the <code>format</code> argument is not a format string, the output string&#39;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.</p>
</td></tr>
<tr><td>v11.4.0</td>
<td><p>The <code>%d</code>, <code>%f</code>, and <code>%i</code> specifiers now support Symbols properly.</p>
</td></tr>
<tr><td>v11.4.0</td>
<td><p>The <code>%o</code> specifier&#39;s <code>depth</code> has default depth of 4 again.</p>
</td></tr>
<tr><td>v11.0.0</td>
<td><p>The <code>%o</code> specifier&#39;s <code>depth</code> option will now fall back to the default depth.</p>
</td></tr>
<tr><td>v10.12.0</td>
<td><p>The <code>%d</code> and <code>%i</code> specifiers now support BigInt.</p>
</td></tr>
<tr><td>v8.4.0</td>
<td><p>The <code>%o</code> and <code>%O</code> specifiers are supported now.</p>
</td></tr>
<tr><td>v0.5.3</td>
<td><p><span>Added in: v0.5.3</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>format</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> A <code>printf</code>-like format string.</li>
</ul>
<p>The <code>util.format()</code> method returns a formatted string using the first argument
as a <code>printf</code>-like format string which can contain zero or more format
specifiers. Each specifier is replaced with the converted value from the
corresponding argument. Supported specifiers are:</p>
<ul>
<li><code>%s</code>: <code>String</code> will be used to convert all values except <code>BigInt</code>, <code>Object</code>
and <code>-0</code>. <code>BigInt</code> values will be represented with an <code>n</code> and Objects that
have no user defined <code>toString</code> function are inspected using <code>util.inspect()</code>
with options <code>{ depth: 0, colors: false, compact: 3 }</code>.</li>
<li><code>%d</code>: <code>Number</code> will be used to convert all values except <code>BigInt</code> and
<code>Symbol</code>.</li>
<li><code>%i</code>: <code>parseInt(value, 10)</code> is used for all values except <code>BigInt</code> and
<code>Symbol</code>.</li>
<li><code>%f</code>: <code>parseFloat(value)</code> is used for all values expect <code>Symbol</code>.</li>
<li><code>%j</code>: JSON. Replaced with the string <code>&#39;[Circular]&#39;</code> if the argument contains
circular references.</li>
<li><code>%o</code>: <code>Object</code>. A string representation of an object with generic JavaScript
object formatting. Similar to <code>util.inspect()</code> with options
<code>{ showHidden: true, showProxy: true }</code>. This will show the full object
including non-enumerable properties and proxies.</li>
<li><code>%O</code>: <code>Object</code>. A string representation of an object with generic JavaScript
object formatting. Similar to <code>util.inspect()</code> without options. This will show
the full object not including non-enumerable properties and proxies.</li>
<li><code>%c</code>: <code>CSS</code>. This specifier is ignored and will skip any CSS passed in.</li>
<li><code>%%</code>: single percent sign (<code>&#39;%&#39;</code>). This does not consume an argument.</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The formatted string</li>
</ul>
<p>If a specifier does not have a corresponding argument, it is not replaced:</p>
<pre><code class="language-js">util.format(&#39;%s:%s&#39;, &#39;foo&#39;);
// Returns: &#39;foo:%s&#39;
</code></pre>
<p>Values that are not part of the format string are formatted using
<code>util.inspect()</code> if their type is not <code>string</code>.</p>
<p>If there are more arguments passed to the <code>util.format()</code> method than the
number of specifiers, the extra arguments are concatenated to the returned
string, separated by spaces:</p>
<pre><code class="language-js">util.format(&#39;%s:%s&#39;, &#39;foo&#39;, &#39;bar&#39;, &#39;baz&#39;);
// Returns: &#39;foo:bar baz&#39;
</code></pre>
<p>If the first argument does not contain a valid format specifier, <code>util.format()</code>
returns a string that is the concatenation of all arguments separated by spaces:</p>
<pre><code class="language-js">util.format(1, 2, 3);
// Returns: &#39;1 2 3&#39;
</code></pre>
<p>If only one argument is passed to <code>util.format()</code>, it is returned as it is
without any formatting:</p>
<pre><code class="language-js">util.format(&#39;%% %s&#39;);
// Returns: &#39;%% %s&#39;
</code></pre>
<p><code>util.format()</code> is a synchronous method that is intended as a debugging tool.
Some input values can have a significant performance overhead that can block the
event loop. Use this function with care and never in a hot code path.</p>
</section><section><h3><code>util.formatWithOptions(inspectOptions, format[, ...args])</code><span><a class="mark" href="#utilformatwithoptionsinspectoptions-format-args" id="utilformatwithoptionsinspectoptions-format-args">#</a></span><a aria-hidden="true" class="legacy" id="util_util_formatwithoptions_inspectoptions_format_args"></a></h3>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>inspectOptions</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
<li><code>format</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>This function is identical to <a href="#utilformatformat-args"><code>util.format()</code></a>, except in that it takes
an <code>inspectOptions</code> argument which specifies options that are passed along to
<a href="#utilinspectobject-options"><code>util.inspect()</code></a>.</p>
<pre><code class="language-js">util.formatWithOptions({ colors: true }, &#39;See object %O&#39;, { foo: 42 });
// Returns &#39;See object { foo: 42 }&#39;, where `42` is colored as a number
// when printed to a terminal.
</code></pre>
</section><section><h3><code>util.getSystemErrorName(err)</code><span><a class="mark" href="#utilgetsystemerrornameerr" id="utilgetsystemerrornameerr">#</a></span><a aria-hidden="true" class="legacy" id="util_util_getsystemerrorname_err"></a></h3>
<div class="api_metadata">
<span>Added in: v9.7.0</span>
</div><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Returns the string name for a numeric error code that comes from a Node.js API.
The mapping between error codes and error names is platform-dependent.
See <a href="errors.html#common-system-errors">Common System Errors</a> for the names of common errors.</p>
<pre><code class="language-js">fs.access(&#39;file/that/does/not/exist&#39;, (err) =&gt; {
  const name = util.getSystemErrorName(err.errno);
  console.error(name);  // ENOENT
});
</code></pre>
</section><section><h3><code>util.getSystemErrorMap()</code><span><a class="mark" href="#utilgetsystemerrormap" id="utilgetsystemerrormap">#</a></span><a aria-hidden="true" class="legacy" id="util_util_getsystemerrormap"></a></h3>
<div class="api_metadata">
<span>Added in: v16.0.0, v14.17.0</span>
</div><ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map" class="type">&lt;Map&gt;</a></li>
</ul>
<p>Returns a Map of all system error codes available from the Node.js API.
The mapping between error codes and error names is platform-dependent.
See <a href="errors.html#common-system-errors">Common System Errors</a> for the names of common errors.</p>
<pre><code class="language-js">fs.access(&#39;file/that/does/not/exist&#39;, (err) =&gt; {
  const errorMap = util.getSystemErrorMap();
  const name = errorMap.get(err.errno);
  console.error(name);  // ENOENT
});
</code></pre>
</section><section><h3><code>util.inherits(constructor, superConstructor)</code><span><a class="mark" href="#utilinheritsconstructor-superconstructor" id="utilinheritsconstructor-superconstructor">#</a></span><a aria-hidden="true" class="legacy" id="util_util_inherits_constructor_superconstructor"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v5.0.0</td>
<td><p>The <code>constructor</code> parameter can refer to an ES6 class now.</p>
</td></tr>
<tr><td>v0.3.0</td>
<td><p><span>Added in: v0.3.0</span></p>
</td></tr>
</table>
</details>
</div><blockquote>
<p>Stability: 3 - Legacy: Use ES2015 class syntax and <code>extends</code> keyword instead.</p>
</blockquote>
<ul>
<li><code>constructor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
<li><code>superConstructor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>Usage of <code>util.inherits()</code> is discouraged. Please use the ES6 <code>class</code> and
<code>extends</code> keywords to get language level inheritance support. Also note
that the two styles are <a href="https://github.com/nodejs/node/issues/4179">semantically incompatible</a>.</p>
<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
prototype of <code>constructor</code> will be set to a new object created from
<code>superConstructor</code>.</p>
<p>This mainly adds some input validation on top of
<code>Object.setPrototypeOf(constructor.prototype, superConstructor.prototype)</code>.
As an additional convenience, <code>superConstructor</code> will be accessible
through the <code>constructor.super_</code> property.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);
const EventEmitter = require(&#39;node:events&#39;);

function MyStream() {
  EventEmitter.call(this);
}

util.inherits(MyStream, EventEmitter);

MyStream.prototype.write = function(data) {
  this.emit(&#39;data&#39;, data);
};

const stream = new MyStream();

console.log(stream instanceof EventEmitter); // true
console.log(MyStream.super_ === EventEmitter); // true

stream.on(&#39;data&#39;, (data) =&gt; {
  console.log(`Received data: &quot;${data}&quot;`);
});
stream.write(&#39;It works!&#39;); // Received data: &quot;It works!&quot;
</code></pre>
<p>ES6 example using <code>class</code> and <code>extends</code>:</p>
<pre><code class="language-js">const EventEmitter = require(&#39;node:events&#39;);

class MyStream extends EventEmitter {
  write(data) {
    this.emit(&#39;data&#39;, data);
  }
}

const stream = new MyStream();

stream.on(&#39;data&#39;, (data) =&gt; {
  console.log(`Received data: &quot;${data}&quot;`);
});
stream.write(&#39;With ES6&#39;);
</code></pre>
</section><section><h3><code>util.inspect(object[, options])</code><span><a class="mark" href="#utilinspectobject-options" id="utilinspectobject-options">#</a></span><a aria-hidden="true" class="legacy" id="util_util_inspect_object_options"></a></h3>
</section><section><h3><code>util.inspect(object[, showHidden[, depth[, colors]]])</code><span><a class="mark" href="#utilinspectobject-showhidden-depth-colors" id="utilinspectobject-showhidden-depth-colors">#</a></span><a aria-hidden="true" class="legacy" id="util_util_inspect_object_showhidden_depth_colors"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v17.3.0, v16.14.0</td>
<td><p>The <code>numericSeparator</code> option is supported now.</p>
</td></tr>
<tr><td>v13.0.0</td>
<td><p>Circular references now include a marker to the reference.</p>
</td></tr>
<tr><td>v14.6.0, v12.19.0</td>
<td><p>If <code>object</code> is from a different <code>vm.Context</code> now, a custom inspection function on it will not receive context-specific arguments anymore.</p>
</td></tr>
<tr><td>v13.13.0, v12.17.0</td>
<td><p>The <code>maxStringLength</code> option is supported now.</p>
</td></tr>
<tr><td>v13.5.0, v12.16.0</td>
<td><p>User defined prototype properties are inspected in case <code>showHidden</code> is <code>true</code>.</p>
</td></tr>
<tr><td>v12.0.0</td>
<td><p>The <code>compact</code> options default is changed to <code>3</code> and the <code>breakLength</code> options default is changed to <code>80</code>.</p>
</td></tr>
<tr><td>v12.0.0</td>
<td><p>Internal properties no longer appear in the context argument of a custom inspection function.</p>
</td></tr>
<tr><td>v11.11.0</td>
<td><p>The <code>compact</code> option accepts numbers for a new output mode.</p>
</td></tr>
<tr><td>v11.7.0</td>
<td><p>ArrayBuffers now also show their binary contents.</p>
</td></tr>
<tr><td>v11.5.0</td>
<td><p>The <code>getters</code> option is supported now.</p>
</td></tr>
<tr><td>v11.4.0</td>
<td><p>The <code>depth</code> default changed back to <code>2</code>.</p>
</td></tr>
<tr><td>v11.0.0</td>
<td><p>The <code>depth</code> default changed to <code>20</code>.</p>
</td></tr>
<tr><td>v11.0.0</td>
<td><p>The inspection output is now limited to about 128 MiB. Data above that size will not be fully inspected.</p>
</td></tr>
<tr><td>v10.12.0</td>
<td><p>The <code>sorted</code> option is supported now.</p>
</td></tr>
<tr><td>v10.6.0</td>
<td><p>Inspecting linked lists and similar objects is now possible up to the maximum call stack size.</p>
</td></tr>
<tr><td>v10.0.0</td>
<td><p>The <code>WeakMap</code> and <code>WeakSet</code> entries can now be inspected as well.</p>
</td></tr>
<tr><td>v9.9.0</td>
<td><p>The <code>compact</code> option is supported now.</p>
</td></tr>
<tr><td>v6.6.0</td>
<td><p>Custom inspection functions can now return <code>this</code>.</p>
</td></tr>
<tr><td>v6.3.0</td>
<td><p>The <code>breakLength</code> option is supported now.</p>
</td></tr>
<tr><td>v6.1.0</td>
<td><p>The <code>maxArrayLength</code> option is supported now; in particular, long arrays are truncated by default.</p>
</td></tr>
<tr><td>v6.1.0</td>
<td><p>The <code>showProxy</code> option is supported now.</p>
</td></tr>
<tr><td>v0.3.0</td>
<td><p><span>Added in: v0.3.0</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a> Any JavaScript primitive or <code>Object</code>.</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>showHidden</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If <code>true</code>, <code>object</code>&#39;s non-enumerable symbols and
properties are included in the formatted result. <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 are also included as well as user defined prototype
properties (excluding method properties). <strong>Default:</strong> <code>false</code>.</li>
<li><code>depth</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Specifies the number of times to recurse while formatting
<code>object</code>. This is useful for inspecting large objects. To recurse up to
the maximum call stack size pass <code>Infinity</code> or <code>null</code>.
<strong>Default:</strong> <code>2</code>.</li>
<li><code>colors</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If <code>true</code>, the output is styled with ANSI color
codes. Colors are customizable. See <a href="#customizing-utilinspect-colors">Customizing <code>util.inspect</code> colors</a>.
<strong>Default:</strong> <code>false</code>.</li>
<li><code>customInspect</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If <code>false</code>,
<code>[util.inspect.custom](depth, opts, inspect)</code> functions are not invoked.
<strong>Default:</strong> <code>true</code>.</li>
<li><code>showProxy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If <code>true</code>, <code>Proxy</code> inspection includes
the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#Terminology"><code>target</code> and <code>handler</code></a> objects. <strong>Default:</strong> <code>false</code>.</li>
<li><code>maxArrayLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> Specifies the maximum number of <code>Array</code>,
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray"><code>TypedArray</code></a>, <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> elements to include when
formatting. Set to <code>null</code> or <code>Infinity</code> to show all elements. Set to <code>0</code> or
negative to show no elements. <strong>Default:</strong> <code>100</code>.</li>
<li><code>maxStringLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> Specifies the maximum number of characters to
include when formatting. Set to <code>null</code> or <code>Infinity</code> to show all elements.
Set to <code>0</code> or negative to show no characters. <strong>Default:</strong> <code>10000</code>.</li>
<li><code>breakLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> The length at which input values are split across
multiple lines. Set to <code>Infinity</code> to format the input as a single line
(in combination with <code>compact</code> set to <code>true</code> or any number &gt;= <code>1</code>).
<strong>Default:</strong> <code>80</code>.</li>
<li><code>compact</code> {boolean|integer} Setting this to <code>false</code> causes each object key
to be displayed on a new line. It will break on new lines in text that is
longer than <code>breakLength</code>. If set to a number, the most <code>n</code> inner elements
are united on a single line as long as all properties fit into
<code>breakLength</code>. Short array elements are also grouped together. For more
information, see the example below. <strong>Default:</strong> <code>3</code>.</li>
<li><code>sorted</code> {boolean|Function} If set to <code>true</code> or a function, all properties
of an object, and <code>Set</code> and <code>Map</code> entries are sorted in the resulting
string. If set to <code>true</code> the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort">default sort</a> is used. If set to a function,
it is used as a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters">compare function</a>.</li>
<li><code>getters</code> {boolean|string} If set to <code>true</code>, getters are inspected. If set
to <code>&#39;get&#39;</code>, only getters without a corresponding setter are inspected. If
set to <code>&#39;set&#39;</code>, only getters with a corresponding setter are inspected.
This might cause side effects depending on the getter function.
<strong>Default:</strong> <code>false</code>.</li>
<li><code>numericSeparator</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If set to <code>true</code>, an underscore is used to
separate every three digits in all bigints and numbers.
<strong>Default:</strong> <code>false</code>.</li>
</ul>
</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The representation of <code>object</code>.</li>
</ul>
<p>The <code>util.inspect()</code> method returns a string representation of <code>object</code> that is
intended for debugging. The output of <code>util.inspect</code> may change at any time
and should not be depended upon programmatically. Additional <code>options</code> may be
passed that alter the result.
<code>util.inspect()</code> will use the constructor&#39;s name and/or <code>@@toStringTag</code> to make
an identifiable tag for an inspected value.</p>
<pre><code class="language-js">class Foo {
  get [Symbol.toStringTag]() {
    return &#39;bar&#39;;
  }
}

class Bar {}

const baz = Object.create(null, { [Symbol.toStringTag]: { value: &#39;foo&#39; } });

util.inspect(new Foo()); // &#39;Foo [bar] {}&#39;
util.inspect(new Bar()); // &#39;Bar {}&#39;
util.inspect(baz);       // &#39;[foo] {}&#39;
</code></pre>
<p>Circular references point to their anchor by using a reference index:</p>
<pre><code class="language-js">const { inspect } = require(&#39;node:util&#39;);

const obj = {};
obj.a = [obj];
obj.b = {};
obj.b.inner = obj.b;
obj.b.obj = obj;

console.log(inspect(obj));
// &lt;ref *1&gt; {
//   a: [ [Circular *1] ],
//   b: &lt;ref *2&gt; { inner: [Circular *2], obj: [Circular *1] }
// }
</code></pre>
<p>The following example inspects all properties of the <code>util</code> object:</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

console.log(util.inspect(util, { showHidden: true, depth: null }));
</code></pre>
<p>The following example highlights the effect of the <code>compact</code> option:</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

const o = {
  a: [1, 2, [[
    &#39;Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit, sed do &#39; +
      &#39;eiusmod \ntempor incididunt ut labore et dolore magna aliqua.&#39;,
    &#39;test&#39;,
    &#39;foo&#39;]], 4],
  b: new Map([[&#39;za&#39;, 1], [&#39;zb&#39;, &#39;test&#39;]]),
};
console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));

// { a:
//   [ 1,
//     2,
//     [ [ &#39;Lorem ipsum dolor sit amet,\nconsectetur [...]&#39;, // A long line
//           &#39;test&#39;,
//           &#39;foo&#39; ] ],
//     4 ],
//   b: Map(2) { &#39;za&#39; =&gt; 1, &#39;zb&#39; =&gt; &#39;test&#39; } }

// Setting `compact` to false or an integer creates more reader friendly output.
console.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 }));

// {
//   a: [
//     1,
//     2,
//     [
//       [
//         &#39;Lorem ipsum dolor sit amet,\n&#39; +
//           &#39;consectetur adipiscing elit, sed do eiusmod \n&#39; +
//           &#39;tempor incididunt ut labore et dolore magna aliqua.&#39;,
//         &#39;test&#39;,
//         &#39;foo&#39;
//       ]
//     ],
//     4
//   ],
//   b: Map(2) {
//     &#39;za&#39; =&gt; 1,
//     &#39;zb&#39; =&gt; &#39;test&#39;
//   }
// }

// Setting `breakLength` to e.g. 150 will print the &quot;Lorem ipsum&quot; text in a
// single line.
</code></pre>
<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
inspected. If there are more entries than <code>maxArrayLength</code>, there is no
guarantee which entries are displayed. That means retrieving the same
<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
with no remaining strong references may be garbage collected at any time.</p>
<pre><code class="language-js">const { inspect } = require(&#39;node:util&#39;);

const obj = { a: 1 };
const obj2 = { b: 2 };
const weakSet = new WeakSet([obj, obj2]);

console.log(inspect(weakSet, { showHidden: true }));
// WeakSet { { a: 1 }, { b: 2 } }
</code></pre>
<p>The <code>sorted</code> option ensures that an object&#39;s property insertion order does not
impact the result of <code>util.inspect()</code>.</p>
<pre><code class="language-js">const { inspect } = require(&#39;node:util&#39;);
const assert = require(&#39;node:assert&#39;);

const o1 = {
  b: [2, 3, 1],
  a: &#39;`a` comes before `b`&#39;,
  c: new Set([2, 3, 1]),
};
console.log(inspect(o1, { sorted: true }));
// { a: &#39;`a` comes before `b`&#39;, b: [ 2, 3, 1 ], c: Set(3) { 1, 2, 3 } }
console.log(inspect(o1, { sorted: (a, b) =&gt; b.localeCompare(a) }));
// { c: Set(3) { 3, 2, 1 }, b: [ 2, 3, 1 ], a: &#39;`a` comes before `b`&#39; }

const o2 = {
  c: new Set([2, 1, 3]),
  a: &#39;`a` comes before `b`&#39;,
  b: [2, 3, 1],
};
assert.strict.equal(
  inspect(o1, { sorted: true }),
  inspect(o2, { sorted: true }),
);
</code></pre>
<p>The <code>numericSeparator</code> option adds an underscore every three digits to all
numbers.</p>
<pre><code class="language-js">const { inspect } = require(&#39;node:util&#39;);

const thousand = 1_000;
const million = 1_000_000;
const bigNumber = 123_456_789n;
const bigDecimal = 1_234.123_45;

console.log(thousand, million, bigNumber, bigDecimal);
// 1_000 1_000_000 123_456_789n 1_234.123_45
</code></pre>
<p><code>util.inspect()</code> is a synchronous method intended for debugging. Its maximum
output length is approximately 128 MiB. Inputs that result in longer output will
be truncated.</p>
<h4>Customizing <code>util.inspect</code> colors<span><a class="mark" href="#customizing-utilinspect-colors" id="customizing-utilinspect-colors">#</a></span><a aria-hidden="true" class="legacy" id="util_customizing_util_inspect_colors"></a></h4>
<!-- type=misc -->

<p>Color output (if enabled) of <code>util.inspect</code> is customizable globally
via the <code>util.inspect.styles</code> and <code>util.inspect.colors</code> properties.</p>
<p><code>util.inspect.styles</code> is a map associating a style name to a color from
<code>util.inspect.colors</code>.</p>
<p>The default styles and associated colors are:</p>
<ul>
<li><code>bigint</code>: <code>yellow</code></li>
<li><code>boolean</code>: <code>yellow</code></li>
<li><code>date</code>: <code>magenta</code></li>
<li><code>module</code>: <code>underline</code></li>
<li><code>name</code>: (no styling)</li>
<li><code>null</code>: <code>bold</code></li>
<li><code>number</code>: <code>yellow</code></li>
<li><code>regexp</code>: <code>red</code></li>
<li><code>special</code>: <code>cyan</code> (e.g., <code>Proxies</code>)</li>
<li><code>string</code>: <code>green</code></li>
<li><code>symbol</code>: <code>green</code></li>
<li><code>undefined</code>: <code>grey</code></li>
</ul>
<p>Color styling uses ANSI control codes that may not be supported on all
terminals. To verify color support use <a href="tty.html#writestreamhascolorscount-env"><code>tty.hasColors()</code></a>.</p>
<p>Predefined control codes are listed below (grouped as &quot;Modifiers&quot;, &quot;Foreground
colors&quot;, and &quot;Background colors&quot;).</p>
<h5>Modifiers<span><a class="mark" href="#modifiers" id="modifiers">#</a></span><a aria-hidden="true" class="legacy" id="util_modifiers"></a></h5>
<p>Modifier support varies throughout different terminals. They will mostly be
ignored, if not supported.</p>
<ul>
<li><code>reset</code> - Resets all (color) modifiers to their defaults</li>
<li><strong>bold</strong> - Make text bold</li>
<li><em>italic</em> - Make text italic</li>
<li><span style="border-bottom: 1px;">underline</span> - Make text underlined</li>
<li><del>strikethrough</del> - Puts a horizontal line through the center of the text
(Alias: <code>strikeThrough</code>, <code>crossedout</code>, <code>crossedOut</code>)</li>
<li><code>hidden</code> - Prints the text, but makes it invisible (Alias: conceal)</li>
<li><span style="opacity: 0.5;">dim</span> - Decreased color intensity (Alias:
<code>faint</code>)</li>
<li><span style="border-top: 1px">overlined</span> - Make text overlined</li>
<li>blink - Hides and shows the text in an interval</li>
<li><span style="filter: invert(100%)">inverse</span> - Swap foreground and
background colors (Alias: <code>swapcolors</code>, <code>swapColors</code>)</li>
<li><span style="border-bottom: 1px double;">doubleunderline</span> - Make text
double underlined (Alias: <code>doubleUnderline</code>)</li>
<li><span style="border: 1px">framed</span> - Draw a frame around the text</li>
</ul>
<h5>Foreground colors<span><a class="mark" href="#foreground-colors" id="foreground-colors">#</a></span><a aria-hidden="true" class="legacy" id="util_foreground_colors"></a></h5>
<ul>
<li><code>black</code></li>
<li><code>red</code></li>
<li><code>green</code></li>
<li><code>yellow</code></li>
<li><code>blue</code></li>
<li><code>magenta</code></li>
<li><code>cyan</code></li>
<li><code>white</code></li>
<li><code>gray</code> (alias: <code>grey</code>, <code>blackBright</code>)</li>
<li><code>redBright</code></li>
<li><code>greenBright</code></li>
<li><code>yellowBright</code></li>
<li><code>blueBright</code></li>
<li><code>magentaBright</code></li>
<li><code>cyanBright</code></li>
<li><code>whiteBright</code></li>
</ul>
<h5>Background colors<span><a class="mark" href="#background-colors" id="background-colors">#</a></span><a aria-hidden="true" class="legacy" id="util_background_colors"></a></h5>
<ul>
<li><code>bgBlack</code></li>
<li><code>bgRed</code></li>
<li><code>bgGreen</code></li>
<li><code>bgYellow</code></li>
<li><code>bgBlue</code></li>
<li><code>bgMagenta</code></li>
<li><code>bgCyan</code></li>
<li><code>bgWhite</code></li>
<li><code>bgGray</code> (alias: <code>bgGrey</code>, <code>bgBlackBright</code>)</li>
<li><code>bgRedBright</code></li>
<li><code>bgGreenBright</code></li>
<li><code>bgYellowBright</code></li>
<li><code>bgBlueBright</code></li>
<li><code>bgMagentaBright</code></li>
<li><code>bgCyanBright</code></li>
<li><code>bgWhiteBright</code></li>
</ul>
<h4>Custom inspection functions on objects<span><a class="mark" href="#custom-inspection-functions-on-objects" id="custom-inspection-functions-on-objects">#</a></span><a aria-hidden="true" class="legacy" id="util_custom_inspection_functions_on_objects"></a></h4>
<!-- type=misc -->

<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v17.3.0, v16.14.0</td>
<td><p>The inspect argument is added for more interoperability.</p>
</td></tr>
<tr><td>v0.1.97</td>
<td><p><span>Added in: v0.1.97</span></p>
</td></tr>
</table>
</details>
</div><p>Objects may also define their own
<a href="#utilinspectcustom"><code>[util.inspect.custom](depth, opts, inspect)</code></a> function,
which <code>util.inspect()</code> will invoke and use the result of when inspecting
the object.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

class Box {
  constructor(value) {
    this.value = value;
  }

  [util.inspect.custom](depth, options, inspect) {
    if (depth &lt; 0) {
      return options.stylize(&#39;[Box]&#39;, &#39;special&#39;);
    }

    const newOptions = Object.assign({}, options, {
      depth: options.depth === null ? null : options.depth - 1,
    });

    // Five space padding because that&#39;s the size of &quot;Box&lt; &quot;.
    const padding = &#39; &#39;.repeat(5);
    const inner = inspect(this.value, newOptions)
                  .replace(/\n/g, `\n${padding}`);
    return `${options.stylize(&#39;Box&#39;, &#39;special&#39;)}&lt; ${inner} &gt;`;
  }
}

const box = new Box(true);

util.inspect(box);
// Returns: &quot;Box&lt; true &gt;&quot;
</code></pre>
<p>Custom <code>[util.inspect.custom](depth, opts, inspect)</code> functions typically return
a string but may return a value of any type that will be formatted accordingly
by <code>util.inspect()</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

const obj = { foo: &#39;this will not show up in the inspect() output&#39; };
obj[util.inspect.custom] = (depth) =&gt; {
  return { bar: &#39;baz&#39; };
};

util.inspect(obj);
// Returns: &quot;{ bar: &#39;baz&#39; }&quot;
</code></pre>
<h4><code>util.inspect.custom</code><span><a class="mark" href="#utilinspectcustom" id="utilinspectcustom">#</a></span><a aria-hidden="true" class="legacy" id="util_util_inspect_custom"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v10.12.0</td>
<td><p>This is now defined as a shared symbol.</p>
</td></tr>
<tr><td>v6.6.0</td>
<td><p><span>Added in: v6.6.0</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&lt;symbol&gt;</a> that can be used to declare custom inspect functions.</li>
</ul>
<p>In addition to being accessible through <code>util.inspect.custom</code>, this
symbol is <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for">registered globally</a> and can be
accessed in any environment as <code>Symbol.for(&#39;nodejs.util.inspect.custom&#39;)</code>.</p>
<p>Using this allows code to be written in a portable fashion, so that the custom
inspect function is used in an Node.js environment and ignored in the browser.
The <code>util.inspect()</code> function itself is passed as third argument to the custom
inspect function to allow further portability.</p>
<pre><code class="language-js">const customInspectSymbol = Symbol.for(&#39;nodejs.util.inspect.custom&#39;);

class Password {
  constructor(value) {
    this.value = value;
  }

  toString() {
    return &#39;xxxxxxxx&#39;;
  }

  [customInspectSymbol](depth, inspectOptions, inspect) {
    return `Password &lt;${this.toString()}&gt;`;
  }
}

const password = new Password(&#39;r0sebud&#39;);
console.log(password);
// Prints Password &lt;xxxxxxxx&gt;
</code></pre>
<p>See <a href="#custom-inspection-functions-on-objects">Custom inspection functions on Objects</a> for more details.</p>
<h4><code>util.inspect.defaultOptions</code><span><a class="mark" href="#utilinspectdefaultoptions" id="utilinspectdefaultoptions">#</a></span><a aria-hidden="true" class="legacy" id="util_util_inspect_defaultoptions"></a></h4>
<div class="api_metadata">
<span>Added in: v6.4.0</span>
</div><p>The <code>defaultOptions</code> value allows customization of the default options used by
<code>util.inspect</code>. This is useful for functions like <code>console.log</code> or
<code>util.format</code> which implicitly call into <code>util.inspect</code>. It shall be set to an
object containing one or more valid <a href="#utilinspectobject-options"><code>util.inspect()</code></a> options. Setting
option properties directly is also supported.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);
const arr = Array(101).fill(0);

console.log(arr); // Logs the truncated array
util.inspect.defaultOptions.maxArrayLength = null;
console.log(arr); // logs the full array
</code></pre>
</section><section><h3><code>util.isDeepStrictEqual(val1, val2)</code><span><a class="mark" href="#utilisdeepstrictequalval1-val2" id="utilisdeepstrictequalval1-val2">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isdeepstrictequal_val1_val2"></a></h3>
<div class="api_metadata">
<span>Added in: v9.0.0</span>
</div><ul>
<li><code>val1</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li><code>val2</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if there is deep strict equality between <code>val1</code> and <code>val2</code>.
Otherwise, returns <code>false</code>.</p>
<p>See <a href="assert.html#assertdeepstrictequalactual-expected-message"><code>assert.deepStrictEqual()</code></a> for more information about deep strict
equality.</p>
</section><section><h3>Class: <code>util.MIMEType</code><span><a class="mark" href="#class-utilmimetype" id="class-utilmimetype">#</a></span><a aria-hidden="true" class="legacy" id="util_class_util_mimetype"></a></h3>
<div class="api_metadata">
<span>Added in: v18.13.0</span>
</div><blockquote>
<p>Stability: 1 - Experimental</p>
</blockquote>
<p>An implementation of <a href="https://bmeck.github.io/node-proposal-mime-api/">the MIMEType class</a>.</p>
<p>In accordance with browser conventions, all properties of <code>MIMEType</code> objects
are implemented as getters and setters on the class prototype, rather than as
data properties on the object itself.</p>
<p>A MIME string is a structured string containing multiple meaningful
components. When parsed, a <code>MIMEType</code> object is returned containing
properties for each of these components.</p>
<h4>Constructor: <code>new MIMEType(input)</code><span><a class="mark" href="#constructor-new-mimetypeinput" id="constructor-new-mimetypeinput">#</a></span><a aria-hidden="true" class="legacy" id="util_constructor_new_mimetype_input"></a></h4>
<ul>
<li><code>input</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The input MIME to parse</li>
</ul>
<p>Creates a new <code>MIMEType</code> object by parsing the <code>input</code>.</p>
<pre><code class="language-mjs">import { MIMEType } from &#39;node:util&#39;;

const myMIME = new MIMEType(&#39;text/plain&#39;);
</code></pre>
<pre><code class="language-cjs">const { MIMEType } = require(&#39;node:util&#39;);

const myMIME = new MIMEType(&#39;text/plain&#39;);
</code></pre>
<p>A <code>TypeError</code> will be thrown if the <code>input</code> is not a valid MIME. Note
that an effort will be made to coerce the given values into strings. For
instance:</p>
<pre><code class="language-mjs">import { MIMEType } from &#39;node:util&#39;;
const myMIME = new MIMEType({ toString: () =&gt; &#39;text/plain&#39; });
console.log(String(myMIME));
// Prints: text/plain
</code></pre>
<pre><code class="language-cjs">const { MIMEType } = require(&#39;node:util&#39;);
const myMIME = new MIMEType({ toString: () =&gt; &#39;text/plain&#39; });
console.log(String(myMIME));
// Prints: text/plain
</code></pre>
<h4><code>mime.type</code><span><a class="mark" href="#mimetype" id="mimetype">#</a></span><a aria-hidden="true" class="legacy" id="util_mime_type"></a></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Gets and sets the type portion of the MIME.</p>
<pre><code class="language-mjs">import { MIMEType } from &#39;node:util&#39;;

const myMIME = new MIMEType(&#39;text/javascript&#39;);
console.log(myMIME.type);
// Prints: text
myMIME.type = &#39;application&#39;;
console.log(myMIME.type);
// Prints: application
console.log(String(myMIME));
// Prints: application/javascript
</code></pre>
<pre><code class="language-cjs">const { MIMEType } = require(&#39;node:util&#39;);

const myMIME = new MIMEType(&#39;text/javascript&#39;);
console.log(myMIME.type);
// Prints: text
myMIME.type = &#39;application&#39;;
console.log(myMIME.type);
// Prints: application
console.log(String(myMIME));
// Prints: application/javascript
</code></pre>
<h4><code>mime.subtype</code><span><a class="mark" href="#mimesubtype" id="mimesubtype">#</a></span><a aria-hidden="true" class="legacy" id="util_mime_subtype"></a></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Gets and sets the subtype portion of the MIME.</p>
<pre><code class="language-mjs">import { MIMEType } from &#39;node:util&#39;;

const myMIME = new MIMEType(&#39;text/ecmascript&#39;);
console.log(myMIME.subtype);
// Prints: ecmascript
myMIME.subtype = &#39;javascript&#39;;
console.log(myMIME.subtype);
// Prints: javascript
console.log(String(myMIME));
// Prints: text/javascript
</code></pre>
<pre><code class="language-cjs">const { MIMEType } = require(&#39;node:util&#39;);

const myMIME = new MIMEType(&#39;text/ecmascript&#39;);
console.log(myMIME.subtype);
// Prints: ecmascript
myMIME.subtype = &#39;javascript&#39;;
console.log(myMIME.subtype);
// Prints: javascript
console.log(String(myMIME));
// Prints: text/javascript
</code></pre>
<h4><code>mime.essence</code><span><a class="mark" href="#mimeessence" id="mimeessence">#</a></span><a aria-hidden="true" class="legacy" id="util_mime_essence"></a></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Gets the essence of the MIME. This property is read only.
Use <code>mime.type</code> or <code>mime.subtype</code> to alter the MIME.</p>
<pre><code class="language-mjs">import { MIMEType } from &#39;node:util&#39;;

const myMIME = new MIMEType(&#39;text/javascript;key=value&#39;);
console.log(myMIME.essence);
// Prints: text/javascript
myMIME.type = &#39;application&#39;;
console.log(myMIME.essence);
// Prints: application/javascript
console.log(String(myMIME));
// Prints: application/javascript;key=value
</code></pre>
<pre><code class="language-cjs">const { MIMEType } = require(&#39;node:util&#39;);

const myMIME = new MIMEType(&#39;text/javascript;key=value&#39;);
console.log(myMIME.essence);
// Prints: text/javascript
myMIME.type = &#39;application&#39;;
console.log(myMIME.essence);
// Prints: application/javascript
console.log(String(myMIME));
// Prints: application/javascript;key=value
</code></pre>
<h4><code>mime.params</code><span><a class="mark" href="#mimeparams" id="mimeparams">#</a></span><a aria-hidden="true" class="legacy" id="util_mime_params"></a></h4>
<ul>
<li><a href="util.html#class-utilmimeparams" class="type">&lt;MIMEParams&gt;</a></li>
</ul>
<p>Gets the <a href="#class-utilmimeparams"><code>MIMEParams</code></a> object representing the
parameters of the MIME. This property is read-only. See
<a href="#class-utilmimeparams"><code>MIMEParams</code></a> documentation for details.</p>
<h4><code>mime.toString()</code><span><a class="mark" href="#mimetostring" id="mimetostring">#</a></span><a aria-hidden="true" class="legacy" id="util_mime_tostring"></a></h4>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>The <code>toString()</code> method on the <code>MIMEType</code> object returns the serialized MIME.</p>
<p>Because of the need for standard compliance, this method does not allow users
to customize the serialization process of the MIME.</p>
<h4><code>mime.toJSON()</code><span><a class="mark" href="#mimetojson" id="mimetojson">#</a></span><a aria-hidden="true" class="legacy" id="util_mime_tojson"></a></h4>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Alias for <a href="#mimetostring"><code>mime.toString()</code></a>.</p>
<p>This method is automatically called when an <code>MIMEType</code> object is serialized
with <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify"><code>JSON.stringify()</code></a>.</p>
<pre><code class="language-mjs">import { MIMEType } from &#39;node:util&#39;;

const myMIMES = [
  new MIMEType(&#39;image/png&#39;),
  new MIMEType(&#39;image/gif&#39;),
];
console.log(JSON.stringify(myMIMES));
// Prints: [&quot;image/png&quot;, &quot;image/gif&quot;]
</code></pre>
<pre><code class="language-cjs">const { MIMEType } = require(&#39;node:util&#39;);

const myMIMES = [
  new MIMEType(&#39;image/png&#39;),
  new MIMEType(&#39;image/gif&#39;),
];
console.log(JSON.stringify(myMIMES));
// Prints: [&quot;image/png&quot;, &quot;image/gif&quot;]
</code></pre>
</section><section><h3>Class: <code>util.MIMEParams</code><span><a class="mark" href="#class-utilmimeparams" id="class-utilmimeparams">#</a></span><a aria-hidden="true" class="legacy" id="util_class_util_mimeparams"></a></h3>
<div class="api_metadata">
<span>Added in: v18.13.0</span>
</div><p>The <code>MIMEParams</code> API provides read and write access to the parameters of a
<code>MIMEType</code>.</p>
<h4>Constructor: <code>new MIMEParams()</code><span><a class="mark" href="#constructor-new-mimeparams" id="constructor-new-mimeparams">#</a></span><a aria-hidden="true" class="legacy" id="util_constructor_new_mimeparams"></a></h4>
<p>Creates a new <code>MIMEParams</code> object by with empty parameters</p>
<pre><code class="language-mjs">import { MIMEParams } from &#39;node:util&#39;;

const myParams = new MIMEParams();
</code></pre>
<pre><code class="language-cjs">const { MIMEParams } = require(&#39;node:util&#39;);

const myParams = new MIMEParams();
</code></pre>
<h4><code>mimeParams.delete(name)</code><span><a class="mark" href="#mimeparamsdeletename" id="mimeparamsdeletename">#</a></span><a aria-hidden="true" class="legacy" id="util_mimeparams_delete_name"></a></h4>
<ul>
<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Remove all name-value pairs whose name is <code>name</code>.</p>
<h4><code>mimeParams.entries()</code><span><a class="mark" href="#mimeparamsentries" id="mimeparamsentries">#</a></span><a aria-hidden="true" class="legacy" id="util_mimeparams_entries"></a></h4>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol" class="type">&lt;Iterator&gt;</a></li>
</ul>
<p>Returns an iterator over each of the name-value pairs in the parameters.
Each item of the iterator is a JavaScript <code>Array</code>. The first item of the array
is the <code>name</code>, the second item of the array is the <code>value</code>.</p>
<h4><code>mimeParams.get(name)</code><span><a class="mark" href="#mimeparamsgetname" id="mimeparamsgetname">#</a></span><a aria-hidden="true" class="legacy" id="util_mimeparams_get_name"></a></h4>
<ul>
<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> or <code>null</code> if there is no name-value pair with the given
<code>name</code>.</li>
</ul>
<p>Returns the value of the first name-value pair whose name is <code>name</code>. If there
are no such pairs, <code>null</code> is returned.</p>
<h4><code>mimeParams.has(name)</code><span><a class="mark" href="#mimeparamshasname" id="mimeparamshasname">#</a></span><a aria-hidden="true" class="legacy" id="util_mimeparams_has_name"></a></h4>
<ul>
<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if there is at least one name-value pair whose name is <code>name</code>.</p>
<h4><code>mimeParams.keys()</code><span><a class="mark" href="#mimeparamskeys" id="mimeparamskeys">#</a></span><a aria-hidden="true" class="legacy" id="util_mimeparams_keys"></a></h4>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol" class="type">&lt;Iterator&gt;</a></li>
</ul>
<p>Returns an iterator over the names of each name-value pair.</p>
<pre><code class="language-mjs">import { MIMEType } from &#39;node:util&#39;;

const { params } = new MIMEType(&#39;text/plain;foo=0;bar=1&#39;);
for (const name of params.keys()) {
  console.log(name);
}
// Prints:
//   foo
//   bar
</code></pre>
<pre><code class="language-cjs">const { MIMEType } = require(&#39;node:util&#39;);

const { params } = new MIMEType(&#39;text/plain;foo=0;bar=1&#39;);
for (const name of params.keys()) {
  console.log(name);
}
// Prints:
//   foo
//   bar
</code></pre>
<h4><code>mimeParams.set(name, value)</code><span><a class="mark" href="#mimeparamssetname-value" id="mimeparamssetname-value">#</a></span><a aria-hidden="true" class="legacy" id="util_mimeparams_set_name_value"></a></h4>
<ul>
<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Sets the value in the <code>MIMEParams</code> object associated with <code>name</code> to
<code>value</code>. If there are any pre-existing name-value pairs whose names are <code>name</code>,
set the first such pair&#39;s value to <code>value</code>.</p>
<pre><code class="language-mjs">import { MIMEType } from &#39;node:util&#39;;

const { params } = new MIMEType(&#39;text/plain;foo=0;bar=1&#39;);
params.set(&#39;foo&#39;, &#39;def&#39;);
params.set(&#39;baz&#39;, &#39;xyz&#39;);
console.log(params.toString());
// Prints: foo=def&amp;bar=1&amp;baz=xyz
</code></pre>
<pre><code class="language-cjs">const { MIMEType } = require(&#39;node:util&#39;);

const { params } = new MIMEType(&#39;text/plain;foo=0;bar=1&#39;);
params.set(&#39;foo&#39;, &#39;def&#39;);
params.set(&#39;baz&#39;, &#39;xyz&#39;);
console.log(params.toString());
// Prints: foo=def&amp;bar=1&amp;baz=xyz
</code></pre>
<h4><code>mimeParams.values()</code><span><a class="mark" href="#mimeparamsvalues" id="mimeparamsvalues">#</a></span><a aria-hidden="true" class="legacy" id="util_mimeparams_values"></a></h4>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol" class="type">&lt;Iterator&gt;</a></li>
</ul>
<p>Returns an iterator over the values of each name-value pair.</p>
<h4><code>mimeParams[@@iterator]()</code><span><a class="mark" href="#mimeparamsiterator" id="mimeparamsiterator">#</a></span><a aria-hidden="true" class="legacy" id="util_mimeparams_iterator"></a></h4>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol" class="type">&lt;Iterator&gt;</a></li>
</ul>
<p>Alias for <a href="#mimeparamsentries"><code>mimeParams.entries()</code></a>.</p>
<pre><code class="language-mjs">import { MIMEType } from &#39;node:util&#39;;

const { params } = new MIMEType(&#39;text/plain;foo=bar;xyz=baz&#39;);
for (const [name, value] of params) {
  console.log(name, value);
}
// Prints:
//   foo bar
//   xyz baz
</code></pre>
<pre><code class="language-cjs">const { MIMEType } = require(&#39;node:util&#39;);

const { params } = new MIMEType(&#39;text/plain;foo=bar;xyz=baz&#39;);
for (const [name, value] of params) {
  console.log(name, value);
}
// Prints:
//   foo bar
//   xyz baz
</code></pre>
</section><section><h3><code>util.parseArgs([config])</code><span><a class="mark" href="#utilparseargsconfig" id="utilparseargsconfig">#</a></span><a aria-hidden="true" class="legacy" id="util_util_parseargs_config"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.11.0</td>
<td><p>Add support for default values in input <code>config</code>.</p>
</td></tr>
<tr><td>v18.3.0</td>
<td><p><span>Added in: v18.3.0</span></p>
</td></tr>
<tr><td>v18.7.0, v16.17.0</td>
<td><p>add support for returning detailed parse information using <code>tokens</code> in input <code>config</code> and returned properties.</p>
</td></tr>
</table>
</details>
</div><blockquote>
<p>Stability: 1 - Experimental</p>
</blockquote>
<ul>
<li><p><code>config</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> Used to provide arguments for parsing and to configure
the parser. <code>config</code> supports the following properties:</p>
<ul>
<li><code>args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> array of argument strings. <strong>Default:</strong> <code>process.argv</code>
with <code>execPath</code> and <code>filename</code> removed.</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> Used to describe arguments known to the parser.
Keys of <code>options</code> are the long names of options and values are an
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> accepting the following properties:<ul>
<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Type of argument, which must be either <code>boolean</code> or <code>string</code>.</li>
<li><code>multiple</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> Whether this option can be provided multiple
times. If <code>true</code>, all values will be collected in an array. If
<code>false</code>, values for the option are last-wins. <strong>Default:</strong> <code>false</code>.</li>
<li><code>short</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> A single character alias for the option.</li>
<li><code>default</code> {string | boolean | string[] | boolean[]} The default option
value when it is not set by args. It must be of the same type as the
<code>type</code> property. When <code>multiple</code> is <code>true</code>, it must be an array.</li>
</ul>
</li>
<li><code>strict</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> Should an error be thrown when unknown arguments
are encountered, or when arguments are passed that do not match the
<code>type</code> configured in <code>options</code>.
<strong>Default:</strong> <code>true</code>.</li>
<li><code>allowPositionals</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> Whether this command accepts positional
arguments.
<strong>Default:</strong> <code>false</code> if <code>strict</code> is <code>true</code>, otherwise <code>true</code>.</li>
<li><code>tokens</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> Return the parsed tokens. This is useful for extending
the built-in behavior, from adding additional checks through to reprocessing
the tokens in different ways.
<strong>Default:</strong> <code>false</code>.</li>
</ul>
</li>
<li><p>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> The parsed command line arguments:</p>
<ul>
<li><code>values</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> A mapping of parsed option names with their <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a>
or <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> values.</li>
<li><code>positionals</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> Positional arguments.</li>
<li><code>tokens</code> {Object[] | undefined} See <a href="#parseargs-tokens">parseArgs tokens</a>
section. Only returned if <code>config</code> includes <code>tokens: true</code>.</li>
</ul>
</li>
</ul>
<p>Provides a higher level API for command-line argument parsing than interacting
with <code>process.argv</code> directly. Takes a specification for the expected arguments
and returns a structured object with the parsed options and positionals.</p>
<pre><code class="language-mjs">import { parseArgs } from &#39;node:util&#39;;
const args = [&#39;-f&#39;, &#39;--bar&#39;, &#39;b&#39;];
const options = {
  foo: {
    type: &#39;boolean&#39;,
    short: &#39;f&#39;,
  },
  bar: {
    type: &#39;string&#39;,
  },
};
const {
  values,
  positionals,
} = parseArgs({ args, options });
console.log(values, positionals);
// Prints: [Object: null prototype] { foo: true, bar: &#39;b&#39; } []
</code></pre>
<pre><code class="language-cjs">const { parseArgs } = require(&#39;node:util&#39;);
const args = [&#39;-f&#39;, &#39;--bar&#39;, &#39;b&#39;];
const options = {
  foo: {
    type: &#39;boolean&#39;,
    short: &#39;f&#39;,
  },
  bar: {
    type: &#39;string&#39;,
  },
};
const {
  values,
  positionals,
} = parseArgs({ args, options });
console.log(values, positionals);
// Prints: [Object: null prototype] { foo: true, bar: &#39;b&#39; } []
</code></pre>
<p><code>util.parseArgs</code> is experimental and behavior may change. Join the
conversation in <a href="https://github.com/pkgjs/parseargs">pkgjs/parseargs</a> to contribute to the design.</p>
<h4><code>parseArgs</code> <code>tokens</code><span><a class="mark" href="#parseargs-tokens" id="parseargs-tokens">#</a></span><a aria-hidden="true" class="legacy" id="util_parseargs_tokens"></a></h4>
<p>Detailed parse information is available for adding custom behaviors by
specifying <code>tokens: true</code> in the configuration.
The returned tokens have properties describing:</p>
<ul>
<li>all tokens<ul>
<li><code>kind</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> One of &#39;option&#39;, &#39;positional&#39;, or &#39;option-terminator&#39;.</li>
<li><code>index</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Index of element in <code>args</code> containing token. So the
source argument for a token is <code>args[token.index]</code>.</li>
</ul>
</li>
<li>option tokens<ul>
<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Long name of option.</li>
<li><code>rawName</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> How option used in args, like <code>-f</code> of <code>--foo</code>.</li>
<li><code>value</code> {string | undefined} Option value specified in args.
Undefined for boolean options.</li>
<li><code>inlineValue</code> {boolean | undefined} Whether option value specified inline,
like <code>--foo=bar</code>.</li>
</ul>
</li>
<li>positional tokens<ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The value of the positional argument in args (i.e. <code>args[index]</code>).</li>
</ul>
</li>
<li>option-terminator token</li>
</ul>
<p>The returned tokens are in the order encountered in the input args. Options
that appear more than once in args produce a token for each use. Short option
groups like <code>-xy</code> expand to a token for each option. So <code>-xxx</code> produces
three tokens.</p>
<p>For example to use the returned tokens to add support for a negated option
like <code>--no-color</code>, the tokens can be reprocessed to change the value stored
for the negated option.</p>
<pre><code class="language-mjs">import { parseArgs } from &#39;node:util&#39;;

const options = {
  &#39;color&#39;: { type: &#39;boolean&#39; },
  &#39;no-color&#39;: { type: &#39;boolean&#39; },
  &#39;logfile&#39;: { type: &#39;string&#39; },
  &#39;no-logfile&#39;: { type: &#39;boolean&#39; },
};
const { values, tokens } = parseArgs({ options, tokens: true });

// Reprocess the option tokens and overwrite the returned values.
tokens
  .filter((token) =&gt; token.kind === &#39;option&#39;)
  .forEach((token) =&gt; {
    if (token.name.startsWith(&#39;no-&#39;)) {
      // Store foo:false for --no-foo
      const positiveName = token.name.slice(3);
      values[positiveName] = false;
      delete values[token.name];
    } else {
      // Resave value so last one wins if both --foo and --no-foo.
      values[token.name] = token.value ?? true;
    }
  });

const color = values.color;
const logfile = values.logfile ?? &#39;default.log&#39;;

console.log({ logfile, color });
</code></pre>
<pre><code class="language-cjs">const { parseArgs } = require(&#39;node:util&#39;);

const options = {
  &#39;color&#39;: { type: &#39;boolean&#39; },
  &#39;no-color&#39;: { type: &#39;boolean&#39; },
  &#39;logfile&#39;: { type: &#39;string&#39; },
  &#39;no-logfile&#39;: { type: &#39;boolean&#39; },
};
const { values, tokens } = parseArgs({ options, tokens: true });

// Reprocess the option tokens and overwrite the returned values.
tokens
  .filter((token) =&gt; token.kind === &#39;option&#39;)
  .forEach((token) =&gt; {
    if (token.name.startsWith(&#39;no-&#39;)) {
      // Store foo:false for --no-foo
      const positiveName = token.name.slice(3);
      values[positiveName] = false;
      delete values[token.name];
    } else {
      // Resave value so last one wins if both --foo and --no-foo.
      values[token.name] = token.value ?? true;
    }
  });

const color = values.color;
const logfile = values.logfile ?? &#39;default.log&#39;;

console.log({ logfile, color });
</code></pre>
<p>Example usage showing negated options, and when an option is used
multiple ways then last one wins.</p>
<pre><code class="language-console">$ node negate.js
{ logfile: &#39;default.log&#39;, color: undefined }
$ node negate.js --no-logfile --no-color
{ logfile: false, color: false }
$ node negate.js --logfile=test.log --color
{ logfile: &#39;test.log&#39;, color: true }
$ node negate.js --no-logfile --logfile=test.log --color --no-color
{ logfile: &#39;test.log&#39;, color: false }
</code></pre>
</section><section><h3><code>util.promisify(original)</code><span><a class="mark" href="#utilpromisifyoriginal" id="utilpromisifyoriginal">#</a></span><a aria-hidden="true" class="legacy" id="util_util_promisify_original"></a></h3>
<div class="api_metadata">
<span>Added in: v8.0.0</span>
</div><ul>
<li><code>original</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>Takes a function following the common error-first callback style, i.e. taking
an <code>(err, value) =&gt; ...</code> callback as the last argument, and returns a version
that returns promises.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);
const fs = require(&#39;node:fs&#39;);

const stat = util.promisify(fs.stat);
stat(&#39;.&#39;).then((stats) =&gt; {
  // Do something with `stats`
}).catch((error) =&gt; {
  // Handle the error.
});
</code></pre>
<p>Or, equivalently using <code>async function</code>s:</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);
const fs = require(&#39;node:fs&#39;);

const stat = util.promisify(fs.stat);

async function callStat() {
  const stats = await stat(&#39;.&#39;);
  console.log(`This directory is owned by ${stats.uid}`);
}
</code></pre>
<p>If there is an <code>original[util.promisify.custom]</code> property present, <code>promisify</code>
will return its value, see <a href="#custom-promisified-functions">Custom promisified functions</a>.</p>
<p><code>promisify()</code> assumes that <code>original</code> is a function taking a callback as its
final argument in all cases. If <code>original</code> is not a function, <code>promisify()</code>
will throw an error. If <code>original</code> is a function but its last argument is not
an error-first callback, it will still be passed an error-first
callback as its last argument.</p>
<p>Using <code>promisify()</code> on class methods or other methods that use <code>this</code> may not
work as expected unless handled specially:</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

class Foo {
  constructor() {
    this.a = 42;
  }

  bar(callback) {
    callback(null, this.a);
  }
}

const foo = new Foo();

const naiveBar = util.promisify(foo.bar);
// TypeError: Cannot read property &#39;a&#39; of undefined
// naiveBar().then(a =&gt; console.log(a));

naiveBar.call(foo).then((a) =&gt; console.log(a)); // &#39;42&#39;

const bindBar = naiveBar.bind(foo);
bindBar().then((a) =&gt; console.log(a)); // &#39;42&#39;
</code></pre>
<h4>Custom promisified functions<span><a class="mark" href="#custom-promisified-functions" id="custom-promisified-functions">#</a></span><a aria-hidden="true" class="legacy" id="util_custom_promisified_functions"></a></h4>
<p>Using the <code>util.promisify.custom</code> symbol one can override the return value of
<a href="#utilpromisifyoriginal"><code>util.promisify()</code></a>:</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

function doSomething(foo, callback) {
  // ...
}

doSomething[util.promisify.custom] = (foo) =&gt; {
  return getPromiseSomehow();
};

const promisified = util.promisify(doSomething);
console.log(promisified === doSomething[util.promisify.custom]);
// prints &#39;true&#39;
</code></pre>
<p>This can be useful for cases where the original function does not follow the
standard format of taking an error-first callback as the last argument.</p>
<p>For example, with a function that takes in
<code>(foo, onSuccessCallback, onErrorCallback)</code>:</p>
<pre><code class="language-js">doSomething[util.promisify.custom] = (foo) =&gt; {
  return new Promise((resolve, reject) =&gt; {
    doSomething(foo, resolve, reject);
  });
};
</code></pre>
<p>If <code>promisify.custom</code> is defined but is not a function, <code>promisify()</code> will
throw an error.</p>
<h4><code>util.promisify.custom</code><span><a class="mark" href="#utilpromisifycustom" id="utilpromisifycustom">#</a></span><a aria-hidden="true" class="legacy" id="util_util_promisify_custom"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.12.0, v12.16.2</td>
<td><p>This is now defined as a shared symbol.</p>
</td></tr>
<tr><td>v8.0.0</td>
<td><p><span>Added in: v8.0.0</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&lt;symbol&gt;</a> that can be used to declare custom promisified variants of functions,
see <a href="#custom-promisified-functions">Custom promisified functions</a>.</li>
</ul>
<p>In addition to being accessible through <code>util.promisify.custom</code>, this
symbol is <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for">registered globally</a> and can be
accessed in any environment as <code>Symbol.for(&#39;nodejs.util.promisify.custom&#39;)</code>.</p>
<p>For example, with a function that takes in
<code>(foo, onSuccessCallback, onErrorCallback)</code>:</p>
<pre><code class="language-js">const kCustomPromisifiedSymbol = Symbol.for(&#39;nodejs.util.promisify.custom&#39;);

doSomething[kCustomPromisifiedSymbol] = (foo) =&gt; {
  return new Promise((resolve, reject) =&gt; {
    doSomething(foo, resolve, reject);
  });
};
</code></pre>
</section><section><h3><code>util.stripVTControlCharacters(str)</code><span><a class="mark" href="#utilstripvtcontrolcharactersstr" id="utilstripvtcontrolcharactersstr">#</a></span><a aria-hidden="true" class="legacy" id="util_util_stripvtcontrolcharacters_str"></a></h3>
<div class="api_metadata">
<span>Added in: v16.11.0</span>
</div><ul>
<li><code>str</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Returns <code>str</code> with any ANSI escape codes removed.</p>
<pre><code class="language-js">console.log(util.stripVTControlCharacters(&#39;\u001B[4mvalue\u001B[0m&#39;));
// Prints &quot;value&quot;
</code></pre>
</section><section><h3>Class: <code>util.TextDecoder</code><span><a class="mark" href="#class-utiltextdecoder" id="class-utiltextdecoder">#</a></span><a aria-hidden="true" class="legacy" id="util_class_util_textdecoder"></a></h3>
<div class="api_metadata">
<span>Added in: v8.3.0</span>
</div><p>An implementation of the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a> <code>TextDecoder</code> API.</p>
<pre><code class="language-js">const decoder = new TextDecoder();
const u8arr = new Uint8Array([72, 101, 108, 108, 111]);
console.log(decoder.decode(u8arr)); // Hello
</code></pre>
<h4>WHATWG supported encodings<span><a class="mark" href="#whatwg-supported-encodings" id="whatwg-supported-encodings">#</a></span><a aria-hidden="true" class="legacy" id="util_whatwg_supported_encodings"></a></h4>
<p>Per the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a>, the encodings supported by the
<code>TextDecoder</code> API are outlined in the tables below. For each encoding,
one or more aliases may be used.</p>
<p>Different Node.js build configurations support different sets of encodings.
(see <a href="intl.html">Internationalization</a>)</p>
<h5>Encodings supported by default (with full ICU data)<span><a class="mark" href="#encodings-supported-by-default-with-full-icu-data" id="encodings-supported-by-default-with-full-icu-data">#</a></span><a aria-hidden="true" class="legacy" id="util_encodings_supported_by_default_with_full_icu_data"></a></h5>
<table>
<thead>
<tr>
<th>Encoding</th>
<th>Aliases</th>
</tr>
</thead>
<tbody><tr>
<td><code>&#39;ibm866&#39;</code></td>
<td><code>&#39;866&#39;</code>, <code>&#39;cp866&#39;</code>, <code>&#39;csibm866&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-2&#39;</code></td>
<td><code>&#39;csisolatin2&#39;</code>, <code>&#39;iso-ir-101&#39;</code>, <code>&#39;iso8859-2&#39;</code>, <code>&#39;iso88592&#39;</code>, <code>&#39;iso_8859-2&#39;</code>, <code>&#39;iso_8859-2:1987&#39;</code>, <code>&#39;l2&#39;</code>, <code>&#39;latin2&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-3&#39;</code></td>
<td><code>&#39;csisolatin3&#39;</code>, <code>&#39;iso-ir-109&#39;</code>, <code>&#39;iso8859-3&#39;</code>, <code>&#39;iso88593&#39;</code>, <code>&#39;iso_8859-3&#39;</code>, <code>&#39;iso_8859-3:1988&#39;</code>, <code>&#39;l3&#39;</code>, <code>&#39;latin3&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-4&#39;</code></td>
<td><code>&#39;csisolatin4&#39;</code>, <code>&#39;iso-ir-110&#39;</code>, <code>&#39;iso8859-4&#39;</code>, <code>&#39;iso88594&#39;</code>, <code>&#39;iso_8859-4&#39;</code>, <code>&#39;iso_8859-4:1988&#39;</code>, <code>&#39;l4&#39;</code>, <code>&#39;latin4&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-5&#39;</code></td>
<td><code>&#39;csisolatincyrillic&#39;</code>, <code>&#39;cyrillic&#39;</code>, <code>&#39;iso-ir-144&#39;</code>, <code>&#39;iso8859-5&#39;</code>, <code>&#39;iso88595&#39;</code>, <code>&#39;iso_8859-5&#39;</code>, <code>&#39;iso_8859-5:1988&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-6&#39;</code></td>
<td><code>&#39;arabic&#39;</code>, <code>&#39;asmo-708&#39;</code>, <code>&#39;csiso88596e&#39;</code>, <code>&#39;csiso88596i&#39;</code>, <code>&#39;csisolatinarabic&#39;</code>, <code>&#39;ecma-114&#39;</code>, <code>&#39;iso-8859-6-e&#39;</code>, <code>&#39;iso-8859-6-i&#39;</code>, <code>&#39;iso-ir-127&#39;</code>, <code>&#39;iso8859-6&#39;</code>, <code>&#39;iso88596&#39;</code>, <code>&#39;iso_8859-6&#39;</code>, <code>&#39;iso_8859-6:1987&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-7&#39;</code></td>
<td><code>&#39;csisolatingreek&#39;</code>, <code>&#39;ecma-118&#39;</code>, <code>&#39;elot_928&#39;</code>, <code>&#39;greek&#39;</code>, <code>&#39;greek8&#39;</code>, <code>&#39;iso-ir-126&#39;</code>, <code>&#39;iso8859-7&#39;</code>, <code>&#39;iso88597&#39;</code>, <code>&#39;iso_8859-7&#39;</code>, <code>&#39;iso_8859-7:1987&#39;</code>, <code>&#39;sun_eu_greek&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-8&#39;</code></td>
<td><code>&#39;csiso88598e&#39;</code>, <code>&#39;csisolatinhebrew&#39;</code>, <code>&#39;hebrew&#39;</code>, <code>&#39;iso-8859-8-e&#39;</code>, <code>&#39;iso-ir-138&#39;</code>, <code>&#39;iso8859-8&#39;</code>, <code>&#39;iso88598&#39;</code>, <code>&#39;iso_8859-8&#39;</code>, <code>&#39;iso_8859-8:1988&#39;</code>, <code>&#39;visual&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-8-i&#39;</code></td>
<td><code>&#39;csiso88598i&#39;</code>, <code>&#39;logical&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-10&#39;</code></td>
<td><code>&#39;csisolatin6&#39;</code>, <code>&#39;iso-ir-157&#39;</code>, <code>&#39;iso8859-10&#39;</code>, <code>&#39;iso885910&#39;</code>, <code>&#39;l6&#39;</code>, <code>&#39;latin6&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-13&#39;</code></td>
<td><code>&#39;iso8859-13&#39;</code>, <code>&#39;iso885913&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-14&#39;</code></td>
<td><code>&#39;iso8859-14&#39;</code>, <code>&#39;iso885914&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-8859-15&#39;</code></td>
<td><code>&#39;csisolatin9&#39;</code>, <code>&#39;iso8859-15&#39;</code>, <code>&#39;iso885915&#39;</code>, <code>&#39;iso_8859-15&#39;</code>, <code>&#39;l9&#39;</code></td>
</tr>
<tr>
<td><code>&#39;koi8-r&#39;</code></td>
<td><code>&#39;cskoi8r&#39;</code>, <code>&#39;koi&#39;</code>, <code>&#39;koi8&#39;</code>, <code>&#39;koi8_r&#39;</code></td>
</tr>
<tr>
<td><code>&#39;koi8-u&#39;</code></td>
<td><code>&#39;koi8-ru&#39;</code></td>
</tr>
<tr>
<td><code>&#39;macintosh&#39;</code></td>
<td><code>&#39;csmacintosh&#39;</code>, <code>&#39;mac&#39;</code>, <code>&#39;x-mac-roman&#39;</code></td>
</tr>
<tr>
<td><code>&#39;windows-874&#39;</code></td>
<td><code>&#39;dos-874&#39;</code>, <code>&#39;iso-8859-11&#39;</code>, <code>&#39;iso8859-11&#39;</code>, <code>&#39;iso885911&#39;</code>, <code>&#39;tis-620&#39;</code></td>
</tr>
<tr>
<td><code>&#39;windows-1250&#39;</code></td>
<td><code>&#39;cp1250&#39;</code>, <code>&#39;x-cp1250&#39;</code></td>
</tr>
<tr>
<td><code>&#39;windows-1251&#39;</code></td>
<td><code>&#39;cp1251&#39;</code>, <code>&#39;x-cp1251&#39;</code></td>
</tr>
<tr>
<td><code>&#39;windows-1252&#39;</code></td>
<td><code>&#39;ansi_x3.4-1968&#39;</code>, <code>&#39;ascii&#39;</code>, <code>&#39;cp1252&#39;</code>, <code>&#39;cp819&#39;</code>, <code>&#39;csisolatin1&#39;</code>, <code>&#39;ibm819&#39;</code>, <code>&#39;iso-8859-1&#39;</code>, <code>&#39;iso-ir-100&#39;</code>, <code>&#39;iso8859-1&#39;</code>, <code>&#39;iso88591&#39;</code>, <code>&#39;iso_8859-1&#39;</code>, <code>&#39;iso_8859-1:1987&#39;</code>, <code>&#39;l1&#39;</code>, <code>&#39;latin1&#39;</code>, <code>&#39;us-ascii&#39;</code>, <code>&#39;x-cp1252&#39;</code></td>
</tr>
<tr>
<td><code>&#39;windows-1253&#39;</code></td>
<td><code>&#39;cp1253&#39;</code>, <code>&#39;x-cp1253&#39;</code></td>
</tr>
<tr>
<td><code>&#39;windows-1254&#39;</code></td>
<td><code>&#39;cp1254&#39;</code>, <code>&#39;csisolatin5&#39;</code>, <code>&#39;iso-8859-9&#39;</code>, <code>&#39;iso-ir-148&#39;</code>, <code>&#39;iso8859-9&#39;</code>, <code>&#39;iso88599&#39;</code>, <code>&#39;iso_8859-9&#39;</code>, <code>&#39;iso_8859-9:1989&#39;</code>, <code>&#39;l5&#39;</code>, <code>&#39;latin5&#39;</code>, <code>&#39;x-cp1254&#39;</code></td>
</tr>
<tr>
<td><code>&#39;windows-1255&#39;</code></td>
<td><code>&#39;cp1255&#39;</code>, <code>&#39;x-cp1255&#39;</code></td>
</tr>
<tr>
<td><code>&#39;windows-1256&#39;</code></td>
<td><code>&#39;cp1256&#39;</code>, <code>&#39;x-cp1256&#39;</code></td>
</tr>
<tr>
<td><code>&#39;windows-1257&#39;</code></td>
<td><code>&#39;cp1257&#39;</code>, <code>&#39;x-cp1257&#39;</code></td>
</tr>
<tr>
<td><code>&#39;windows-1258&#39;</code></td>
<td><code>&#39;cp1258&#39;</code>, <code>&#39;x-cp1258&#39;</code></td>
</tr>
<tr>
<td><code>&#39;x-mac-cyrillic&#39;</code></td>
<td><code>&#39;x-mac-ukrainian&#39;</code></td>
</tr>
<tr>
<td><code>&#39;gbk&#39;</code></td>
<td><code>&#39;chinese&#39;</code>, <code>&#39;csgb2312&#39;</code>, <code>&#39;csiso58gb231280&#39;</code>, <code>&#39;gb2312&#39;</code>, <code>&#39;gb_2312&#39;</code>, <code>&#39;gb_2312-80&#39;</code>, <code>&#39;iso-ir-58&#39;</code>, <code>&#39;x-gbk&#39;</code></td>
</tr>
<tr>
<td><code>&#39;gb18030&#39;</code></td>
<td></td>
</tr>
<tr>
<td><code>&#39;big5&#39;</code></td>
<td><code>&#39;big5-hkscs&#39;</code>, <code>&#39;cn-big5&#39;</code>, <code>&#39;csbig5&#39;</code>, <code>&#39;x-x-big5&#39;</code></td>
</tr>
<tr>
<td><code>&#39;euc-jp&#39;</code></td>
<td><code>&#39;cseucpkdfmtjapanese&#39;</code>, <code>&#39;x-euc-jp&#39;</code></td>
</tr>
<tr>
<td><code>&#39;iso-2022-jp&#39;</code></td>
<td><code>&#39;csiso2022jp&#39;</code></td>
</tr>
<tr>
<td><code>&#39;shift_jis&#39;</code></td>
<td><code>&#39;csshiftjis&#39;</code>, <code>&#39;ms932&#39;</code>, <code>&#39;ms_kanji&#39;</code>, <code>&#39;shift-jis&#39;</code>, <code>&#39;sjis&#39;</code>, <code>&#39;windows-31j&#39;</code>, <code>&#39;x-sjis&#39;</code></td>
</tr>
<tr>
<td><code>&#39;euc-kr&#39;</code></td>
<td><code>&#39;cseuckr&#39;</code>, <code>&#39;csksc56011987&#39;</code>, <code>&#39;iso-ir-149&#39;</code>, <code>&#39;korean&#39;</code>, <code>&#39;ks_c_5601-1987&#39;</code>, <code>&#39;ks_c_5601-1989&#39;</code>, <code>&#39;ksc5601&#39;</code>, <code>&#39;ksc_5601&#39;</code>, <code>&#39;windows-949&#39;</code></td>
</tr>
</tbody></table>
<h5>Encodings supported when Node.js is built with the <code>small-icu</code> option<span><a class="mark" href="#encodings-supported-when-nodejs-is-built-with-the-small-icu-option" id="encodings-supported-when-nodejs-is-built-with-the-small-icu-option">#</a></span><a aria-hidden="true" class="legacy" id="util_encodings_supported_when_node_js_is_built_with_the_small_icu_option"></a></h5>
<table>
<thead>
<tr>
<th>Encoding</th>
<th>Aliases</th>
</tr>
</thead>
<tbody><tr>
<td><code>&#39;utf-8&#39;</code></td>
<td><code>&#39;unicode-1-1-utf-8&#39;</code>, <code>&#39;utf8&#39;</code></td>
</tr>
<tr>
<td><code>&#39;utf-16le&#39;</code></td>
<td><code>&#39;utf-16&#39;</code></td>
</tr>
<tr>
<td><code>&#39;utf-16be&#39;</code></td>
<td></td>
</tr>
</tbody></table>
<h5>Encodings supported when ICU is disabled<span><a class="mark" href="#encodings-supported-when-icu-is-disabled" id="encodings-supported-when-icu-is-disabled">#</a></span><a aria-hidden="true" class="legacy" id="util_encodings_supported_when_icu_is_disabled"></a></h5>
<table>
<thead>
<tr>
<th>Encoding</th>
<th>Aliases</th>
</tr>
</thead>
<tbody><tr>
<td><code>&#39;utf-8&#39;</code></td>
<td><code>&#39;unicode-1-1-utf-8&#39;</code>, <code>&#39;utf8&#39;</code></td>
</tr>
<tr>
<td><code>&#39;utf-16le&#39;</code></td>
<td><code>&#39;utf-16&#39;</code></td>
</tr>
</tbody></table>
<p>The <code>&#39;iso-8859-16&#39;</code> encoding listed in the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a>
is not supported.</p>
<h4><code>new TextDecoder([encoding[, options]])</code><span><a class="mark" href="#new-textdecoderencoding-options" id="new-textdecoderencoding-options">#</a></span><a aria-hidden="true" class="legacy" id="util_new_textdecoder_encoding_options"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v11.0.0</td>
<td><p>The class is now available on the global object.</p>
</td></tr>
<tr><td>v8.3.0</td>
<td><p><span>Added in: v8.3.0</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Identifies the <code>encoding</code> that this <code>TextDecoder</code> instance
supports. <strong>Default:</strong> <code>&#39;utf-8&#39;</code>.</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>fatal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> <code>true</code> if decoding failures are fatal.
This option is not supported when ICU is disabled
(see <a href="intl.html">Internationalization</a>). <strong>Default:</strong> <code>false</code>.</li>
<li><code>ignoreBOM</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> When <code>true</code>, the <code>TextDecoder</code> will include the byte
order mark in the decoded result. When <code>false</code>, the byte order mark will
be removed from the output. This option is only used when <code>encoding</code> is
<code>&#39;utf-8&#39;</code>, <code>&#39;utf-16be&#39;</code>, or <code>&#39;utf-16le&#39;</code>. <strong>Default:</strong> <code>false</code>.</li>
</ul>
</li>
</ul>
<p>Creates a new <code>TextDecoder</code> instance. The <code>encoding</code> may specify one of the
supported encodings or an alias.</p>
<p>The <code>TextDecoder</code> class is also available on the global object.</p>
<h4><code>textDecoder.decode([input[, options]])</code><span><a class="mark" href="#textdecoderdecodeinput-options" id="textdecoderdecodeinput-options">#</a></span><a aria-hidden="true" class="legacy" id="util_textdecoder_decode_input_options"></a></h4>
<ul>
<li><code>input</code> {ArrayBuffer|DataView|TypedArray} An <code>ArrayBuffer</code>, <code>DataView</code>, or
<code>TypedArray</code> instance containing the encoded data.</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>stream</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> <code>true</code> if additional chunks of data are expected.
<strong>Default:</strong> <code>false</code>.</li>
</ul>
</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Decodes the <code>input</code> and returns a string. If <code>options.stream</code> is <code>true</code>, any
incomplete byte sequences occurring at the end of the <code>input</code> are buffered
internally and emitted after the next call to <code>textDecoder.decode()</code>.</p>
<p>If <code>textDecoder.fatal</code> is <code>true</code>, decoding errors that occur will result in a
<code>TypeError</code> being thrown.</p>
<h4><code>textDecoder.encoding</code><span><a class="mark" href="#textdecoderencoding" id="textdecoderencoding">#</a></span><a aria-hidden="true" class="legacy" id="util_textdecoder_encoding"></a></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>The encoding supported by the <code>TextDecoder</code> instance.</p>
<h4><code>textDecoder.fatal</code><span><a class="mark" href="#textdecoderfatal" id="textdecoderfatal">#</a></span><a aria-hidden="true" class="legacy" id="util_textdecoder_fatal"></a></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>The value will be <code>true</code> if decoding errors result in a <code>TypeError</code> being
thrown.</p>
<h4><code>textDecoder.ignoreBOM</code><span><a class="mark" href="#textdecoderignorebom" id="textdecoderignorebom">#</a></span><a aria-hidden="true" class="legacy" id="util_textdecoder_ignorebom"></a></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>The value will be <code>true</code> if the decoding result will include the byte order
mark.</p>
</section><section><h3>Class: <code>util.TextEncoder</code><span><a class="mark" href="#class-utiltextencoder" id="class-utiltextencoder">#</a></span><a aria-hidden="true" class="legacy" id="util_class_util_textencoder"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v11.0.0</td>
<td><p>The class is now available on the global object.</p>
</td></tr>
<tr><td>v8.3.0</td>
<td><p><span>Added in: v8.3.0</span></p>
</td></tr>
</table>
</details>
</div><p>An implementation of the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a> <code>TextEncoder</code> API. All
instances of <code>TextEncoder</code> only support UTF-8 encoding.</p>
<pre><code class="language-js">const encoder = new TextEncoder();
const uint8array = encoder.encode(&#39;this is some data&#39;);
</code></pre>
<p>The <code>TextEncoder</code> class is also available on the global object.</p>
<h4><code>textEncoder.encode([input])</code><span><a class="mark" href="#textencoderencodeinput" id="textencoderencodeinput">#</a></span><a aria-hidden="true" class="legacy" id="util_textencoder_encode_input"></a></h4>
<ul>
<li><code>input</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The text to encode. <strong>Default:</strong> an empty string.</li>
<li>Returns: {Uint8Array}</li>
</ul>
<p>UTF-8 encodes the <code>input</code> string and returns a <code>Uint8Array</code> containing the
encoded bytes.</p>
<h4><code>textEncoder.encodeInto(src, dest)</code><span><a class="mark" href="#textencoderencodeintosrc-dest" id="textencoderencodeintosrc-dest">#</a></span><a aria-hidden="true" class="legacy" id="util_textencoder_encodeinto_src_dest"></a></h4>
<ul>
<li><code>src</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The text to encode.</li>
<li><code>dest</code> {Uint8Array} The array to hold the encode result.</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>read</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The read Unicode code units of src.</li>
<li><code>written</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The written UTF-8 bytes of dest.</li>
</ul>
</li>
</ul>
<p>UTF-8 encodes the <code>src</code> string to the <code>dest</code> Uint8Array and returns an object
containing the read Unicode code units and written UTF-8 bytes.</p>
<pre><code class="language-js">const encoder = new TextEncoder();
const src = &#39;this is some data&#39;;
const dest = new Uint8Array(10);
const { read, written } = encoder.encodeInto(src, dest);
</code></pre>
<h4><code>textEncoder.encoding</code><span><a class="mark" href="#textencoderencoding" id="textencoderencoding">#</a></span><a aria-hidden="true" class="legacy" id="util_textencoder_encoding"></a></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>The encoding supported by the <code>TextEncoder</code> instance. Always set to <code>&#39;utf-8&#39;</code>.</p>
</section><section><h3><code>util.toUSVString(string)</code><span><a class="mark" href="#utiltousvstringstring" id="utiltousvstringstring">#</a></span><a aria-hidden="true" class="legacy" id="util_util_tousvstring_string"></a></h3>
<div class="api_metadata">
<span>Added in: v16.8.0, v14.18.0</span>
</div><ul>
<li><code>string</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Returns the <code>string</code> after replacing any surrogate code points
(or equivalently, any unpaired surrogate code units) with the
Unicode &quot;replacement character&quot; U+FFFD.</p>
</section><section><h3><code>util.transferableAbortController()</code><span><a class="mark" href="#utiltransferableabortcontroller" id="utiltransferableabortcontroller">#</a></span><a aria-hidden="true" class="legacy" id="util_util_transferableabortcontroller"></a></h3>
<div class="api_metadata">
<span>Added in: v18.11.0</span>
</div><blockquote>
<p>Stability: 1 - Experimental</p>
</blockquote>
<p>Creates and returns an <a href="globals.html#class-abortcontroller" class="type">&lt;AbortController&gt;</a> instance whose <a href="globals.html#class-abortsignal" class="type">&lt;AbortSignal&gt;</a> is marked
as transferable and can be used with <code>structuredClone()</code> or <code>postMessage()</code>.</p>
</section><section><h3><code>util.transferableAbortSignal(signal)</code><span><a class="mark" href="#utiltransferableabortsignalsignal" id="utiltransferableabortsignalsignal">#</a></span><a aria-hidden="true" class="legacy" id="util_util_transferableabortsignal_signal"></a></h3>
<div class="api_metadata">
<span>Added in: v18.11.0</span>
</div><blockquote>
<p>Stability: 1 - Experimental</p>
</blockquote>
<ul>
<li><code>signal</code> <a href="globals.html#class-abortsignal" class="type">&lt;AbortSignal&gt;</a></li>
<li>Returns: <a href="globals.html#class-abortsignal" class="type">&lt;AbortSignal&gt;</a></li>
</ul>
<p>Marks the given <a href="globals.html#class-abortsignal" class="type">&lt;AbortSignal&gt;</a> as transferable so that it can be used with
<code>structuredClone()</code> and <code>postMessage()</code>.</p>
<pre><code class="language-js">const signal = transferableAbortSignal(AbortSignal.timeout(100));
const channel = new MessageChannel();
channel.port2.postMessage(signal, [signal]);
</code></pre>
</section><section><h3><code>util.aborted(signal, resource)</code><span><a class="mark" href="#utilabortedsignal-resource" id="utilabortedsignal-resource">#</a></span><a aria-hidden="true" class="legacy" id="util_util_aborted_signal_resource"></a></h3>
<div class="api_metadata">
<span>Added in: v18.16.0</span>
</div><blockquote>
<p>Stability: 1 - Experimental</p>
</blockquote>
<ul>
<li><code>signal</code> <a href="globals.html#class-abortsignal" class="type">&lt;AbortSignal&gt;</a></li>
<li><code>resource</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> Any non-null entity, reference to which is held weakly.</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&lt;Promise&gt;</a></li>
</ul>
<p>Listens to abort event on the provided <code>signal</code> and
returns a promise that is fulfilled when the <code>signal</code> is
aborted. If the passed <code>resource</code> is garbage collected before the <code>signal</code> is
aborted, the returned promise shall remain pending indefinitely.</p>
<pre><code class="language-cjs">const { aborted } = require(&#39;node:util&#39;);

const dependent = obtainSomethingAbortable();

aborted(dependent.signal, dependent).then(() =&gt; {
  // Do something when dependent is aborted.
});

dependent.on(&#39;event&#39;, () =&gt; {
  dependent.abort();
});
</code></pre>
<pre><code class="language-mjs">import { aborted } from &#39;node:util&#39;;

const dependent = obtainSomethingAbortable();

aborted(dependent.signal, dependent).then(() =&gt; {
  // Do something when dependent is aborted.
});

dependent.on(&#39;event&#39;, () =&gt; {
  dependent.abort();
});
</code></pre>
</section><section><h3><code>util.types</code><span><a class="mark" href="#utiltypes" id="utiltypes">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v15.3.0</td>
<td><p>Exposed as <code>require(&#39;util/types&#39;)</code>.</p>
</td></tr>
<tr><td>v10.0.0</td>
<td><p><span>Added in: v10.0.0</span></p>
</td></tr>
</table>
</details>
</div><p><code>util.types</code> provides type checks for different kinds of built-in objects.
Unlike <code>instanceof</code> or <code>Object.prototype.toString.call(value)</code>, these checks do
not inspect properties of the object that are accessible from JavaScript (like
their prototype), and usually have the overhead of calling into C++.</p>
<p>The result generally does not make any guarantees about what kinds of
properties or behavior a value exposes in JavaScript. They are primarily
useful for addon developers who prefer to do type checking in JavaScript.</p>
<p>The API is accessible via <code>require(&#39;node:util&#39;).types</code> or <code>require(&#39;node:util/types&#39;)</code>.</p>
<h4><code>util.types.isAnyArrayBuffer(value)</code><span><a class="mark" href="#utiltypesisanyarraybuffervalue" id="utiltypesisanyarraybuffervalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isanyarraybuffer_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer"><code>SharedArrayBuffer</code></a> instance.</p>
<p>See also <a href="#utiltypesisarraybuffervalue"><code>util.types.isArrayBuffer()</code></a> and
<a href="#utiltypesissharedarraybuffervalue"><code>util.types.isSharedArrayBuffer()</code></a>.</p>
<pre><code class="language-js">util.types.isAnyArrayBuffer(new ArrayBuffer());  // Returns true
util.types.isAnyArrayBuffer(new SharedArrayBuffer());  // Returns true
</code></pre>
<h4><code>util.types.isArrayBufferView(value)</code><span><a class="mark" href="#utiltypesisarraybufferviewvalue" id="utiltypesisarraybufferviewvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isarraybufferview_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
views, 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
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView"><code>ArrayBuffer.isView()</code></a>.</p>
<pre><code class="language-js">util.types.isArrayBufferView(new Int8Array());  // true
util.types.isArrayBufferView(Buffer.from(&#39;hello world&#39;)); // true
util.types.isArrayBufferView(new DataView(new ArrayBuffer(16)));  // true
util.types.isArrayBufferView(new ArrayBuffer());  // false
</code></pre>
<h4><code>util.types.isArgumentsObject(value)</code><span><a class="mark" href="#utiltypesisargumentsobjectvalue" id="utiltypesisargumentsobjectvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isargumentsobject_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is an <code>arguments</code> object.</p>
<!-- eslint-disable prefer-rest-params -->

<pre><code class="language-js">function foo() {
  util.types.isArgumentsObject(arguments);  // Returns true
}
</code></pre>
<h4><code>util.types.isArrayBuffer(value)</code><span><a class="mark" href="#utiltypesisarraybuffervalue" id="utiltypesisarraybuffervalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isarraybuffer_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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.
This 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
desirable to test for both; See <a href="#utiltypesisanyarraybuffervalue"><code>util.types.isAnyArrayBuffer()</code></a> for that.</p>
<pre><code class="language-js">util.types.isArrayBuffer(new ArrayBuffer());  // Returns true
util.types.isArrayBuffer(new SharedArrayBuffer());  // Returns false
</code></pre>
<h4><code>util.types.isAsyncFunction(value)</code><span><a class="mark" href="#utiltypesisasyncfunctionvalue" id="utiltypesisasyncfunctionvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isasyncfunction_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>.
This only reports back what the JavaScript engine is seeing;
in particular, the return value may not match the original source code if
a transpilation tool was used.</p>
<pre><code class="language-js">util.types.isAsyncFunction(function foo() {});  // Returns false
util.types.isAsyncFunction(async function foo() {});  // Returns true
</code></pre>
<h4><code>util.types.isBigInt64Array(value)</code><span><a class="mark" href="#utiltypesisbigint64arrayvalue" id="utiltypesisbigint64arrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isbigint64array_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is a <code>BigInt64Array</code> instance.</p>
<pre><code class="language-js">util.types.isBigInt64Array(new BigInt64Array());   // Returns true
util.types.isBigInt64Array(new BigUint64Array());  // Returns false
</code></pre>
<h4><code>util.types.isBigUint64Array(value)</code><span><a class="mark" href="#utiltypesisbiguint64arrayvalue" id="utiltypesisbiguint64arrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isbiguint64array_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is a <code>BigUint64Array</code> instance.</p>
<pre><code class="language-js">util.types.isBigUint64Array(new BigInt64Array());   // Returns false
util.types.isBigUint64Array(new BigUint64Array());  // Returns true
</code></pre>
<h4><code>util.types.isBooleanObject(value)</code><span><a class="mark" href="#utiltypesisbooleanobjectvalue" id="utiltypesisbooleanobjectvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isbooleanobject_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is a boolean object, e.g. created
by <code>new Boolean()</code>.</p>
<pre><code class="language-js">util.types.isBooleanObject(false);  // Returns false
util.types.isBooleanObject(true);   // Returns false
util.types.isBooleanObject(new Boolean(false)); // Returns true
util.types.isBooleanObject(new Boolean(true));  // Returns true
util.types.isBooleanObject(Boolean(false)); // Returns false
util.types.isBooleanObject(Boolean(true));  // Returns false
</code></pre>
<h4><code>util.types.isBoxedPrimitive(value)</code><span><a class="mark" href="#utiltypesisboxedprimitivevalue" id="utiltypesisboxedprimitivevalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isboxedprimitive_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.11.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is any boxed primitive object, e.g. created
by <code>new Boolean()</code>, <code>new String()</code> or <code>Object(Symbol())</code>.</p>
<p>For example:</p>
<pre><code class="language-js">util.types.isBoxedPrimitive(false); // Returns false
util.types.isBoxedPrimitive(new Boolean(false)); // Returns true
util.types.isBoxedPrimitive(Symbol(&#39;foo&#39;)); // Returns false
util.types.isBoxedPrimitive(Object(Symbol(&#39;foo&#39;))); // Returns true
util.types.isBoxedPrimitive(Object(BigInt(5))); // Returns true
</code></pre>
<h4><code>util.types.isCryptoKey(value)</code><span><a class="mark" href="#utiltypesiscryptokeyvalue" id="utiltypesiscryptokeyvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_iscryptokey_value"></a></h4>
<div class="api_metadata">
<span>Added in: v16.2.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if <code>value</code> is a <a href="webcrypto.html#class-cryptokey" class="type">&lt;CryptoKey&gt;</a>, <code>false</code> otherwise.</p>
<h4><code>util.types.isDataView(value)</code><span><a class="mark" href="#utiltypesisdataviewvalue" id="utiltypesisdataviewvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isdataview_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">const ab = new ArrayBuffer(20);
util.types.isDataView(new DataView(ab));  // Returns true
util.types.isDataView(new Float64Array());  // Returns false
</code></pre>
<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>
<h4><code>util.types.isDate(value)</code><span><a class="mark" href="#utiltypesisdatevalue" id="utiltypesisdatevalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isdate_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isDate(new Date());  // Returns true
</code></pre>
<h4><code>util.types.isExternal(value)</code><span><a class="mark" href="#utiltypesisexternalvalue" id="utiltypesisexternalvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isexternal_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is a native <code>External</code> value.</p>
<p>A native <code>External</code> value is a special type of object that contains a
raw C++ pointer (<code>void*</code>) for access from native code, and has no other
properties. Such objects are created either by Node.js internals or native
addons. 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
<code>null</code> prototype.</p>
<pre><code class="language-c">#include &lt;js_native_api.h&gt;
#include &lt;stdlib.h&gt;
napi_value result;
static napi_value MyNapi(napi_env env, napi_callback_info info) {
  int* raw = (int*) malloc(1024);
  napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &amp;result);
  if (status != napi_ok) {
    napi_throw_error(env, NULL, &quot;napi_create_external failed&quot;);
    return NULL;
  }
  return result;
}
...
DECLARE_NAPI_PROPERTY(&quot;myNapi&quot;, MyNapi)
...
</code></pre>
<pre><code class="language-js">const native = require(&#39;napi_addon.node&#39;);
const data = native.myNapi();
util.types.isExternal(data); // returns true
util.types.isExternal(0); // returns false
util.types.isExternal(new String(&#39;foo&#39;)); // returns false
</code></pre>
<p>For further information on <code>napi_create_external</code>, refer to
<a href="n-api.html#napi_create_external"><code>napi_create_external()</code></a>.</p>
<h4><code>util.types.isFloat32Array(value)</code><span><a class="mark" href="#utiltypesisfloat32arrayvalue" id="utiltypesisfloat32arrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isfloat32array_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isFloat32Array(new ArrayBuffer());  // Returns false
util.types.isFloat32Array(new Float32Array());  // Returns true
util.types.isFloat32Array(new Float64Array());  // Returns false
</code></pre>
<h4><code>util.types.isFloat64Array(value)</code><span><a class="mark" href="#utiltypesisfloat64arrayvalue" id="utiltypesisfloat64arrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isfloat64array_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isFloat64Array(new ArrayBuffer());  // Returns false
util.types.isFloat64Array(new Uint8Array());  // Returns false
util.types.isFloat64Array(new Float64Array());  // Returns true
</code></pre>
<h4><code>util.types.isGeneratorFunction(value)</code><span><a class="mark" href="#utiltypesisgeneratorfunctionvalue" id="utiltypesisgeneratorfunctionvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isgeneratorfunction_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is a generator function.
This only reports back what the JavaScript engine is seeing;
in particular, the return value may not match the original source code if
a transpilation tool was used.</p>
<pre><code class="language-js">util.types.isGeneratorFunction(function foo() {});  // Returns false
util.types.isGeneratorFunction(function* foo() {});  // Returns true
</code></pre>
<h4><code>util.types.isGeneratorObject(value)</code><span><a class="mark" href="#utiltypesisgeneratorobjectvalue" id="utiltypesisgeneratorobjectvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isgeneratorobject_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is a generator object as returned from a
built-in generator function.
This only reports back what the JavaScript engine is seeing;
in particular, the return value may not match the original source code if
a transpilation tool was used.</p>
<pre><code class="language-js">function* foo() {}
const generator = foo();
util.types.isGeneratorObject(generator);  // Returns true
</code></pre>
<h4><code>util.types.isInt8Array(value)</code><span><a class="mark" href="#utiltypesisint8arrayvalue" id="utiltypesisint8arrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isint8array_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isInt8Array(new ArrayBuffer());  // Returns false
util.types.isInt8Array(new Int8Array());  // Returns true
util.types.isInt8Array(new Float64Array());  // Returns false
</code></pre>
<h4><code>util.types.isInt16Array(value)</code><span><a class="mark" href="#utiltypesisint16arrayvalue" id="utiltypesisint16arrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isint16array_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isInt16Array(new ArrayBuffer());  // Returns false
util.types.isInt16Array(new Int16Array());  // Returns true
util.types.isInt16Array(new Float64Array());  // Returns false
</code></pre>
<h4><code>util.types.isInt32Array(value)</code><span><a class="mark" href="#utiltypesisint32arrayvalue" id="utiltypesisint32arrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isint32array_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isInt32Array(new ArrayBuffer());  // Returns false
util.types.isInt32Array(new Int32Array());  // Returns true
util.types.isInt32Array(new Float64Array());  // Returns false
</code></pre>
<h4><code>util.types.isKeyObject(value)</code><span><a class="mark" href="#utiltypesiskeyobjectvalue" id="utiltypesiskeyobjectvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_iskeyobject_value"></a></h4>
<div class="api_metadata">
<span>Added in: v16.2.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if <code>value</code> is a <a href="crypto.html#class-keyobject" class="type">&lt;KeyObject&gt;</a>, <code>false</code> otherwise.</p>
<h4><code>util.types.isMap(value)</code><span><a class="mark" href="#utiltypesismapvalue" id="utiltypesismapvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_ismap_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isMap(new Map());  // Returns true
</code></pre>
<h4><code>util.types.isMapIterator(value)</code><span><a class="mark" href="#utiltypesismapiteratorvalue" id="utiltypesismapiteratorvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_ismapiterator_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is an iterator returned for a built-in
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map"><code>Map</code></a> instance.</p>
<pre><code class="language-js">const map = new Map();
util.types.isMapIterator(map.keys());  // Returns true
util.types.isMapIterator(map.values());  // Returns true
util.types.isMapIterator(map.entries());  // Returns true
util.types.isMapIterator(map[Symbol.iterator]());  // Returns true
</code></pre>
<h4><code>util.types.isModuleNamespaceObject(value)</code><span><a class="mark" href="#utiltypesismodulenamespaceobjectvalue" id="utiltypesismodulenamespaceobjectvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_ismodulenamespaceobject_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<!-- eslint-skip -->

<pre><code class="language-js">import * as ns from &#39;./a.js&#39;;

util.types.isModuleNamespaceObject(ns);  // Returns true
</code></pre>
<h4><code>util.types.isNativeError(value)</code><span><a class="mark" href="#utiltypesisnativeerrorvalue" id="utiltypesisnativeerrorvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isnativeerror_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value was returned by the constructor of a
<a href="https://tc39.es/ecma262/#sec-error-objects">built-in <code>Error</code> type</a>.</p>
<pre><code class="language-js">console.log(util.types.isNativeError(new Error()));  // true
console.log(util.types.isNativeError(new TypeError()));  // true
console.log(util.types.isNativeError(new RangeError()));  // true
</code></pre>
<p>Subclasses of the native error types are also native errors:</p>
<pre><code class="language-js">class MyError extends Error {}
console.log(util.types.isNativeError(new MyError()));  // true
</code></pre>
<p>A value being <code>instanceof</code> a native error class is not equivalent to <code>isNativeError()</code>
returning <code>true</code> for that value. <code>isNativeError()</code> returns <code>true</code> for errors
which come from a different <a href="https://tc39.es/ecma262/#realm">realm</a> while <code>instanceof Error</code> returns <code>false</code>
for these errors:</p>
<pre><code class="language-js">const vm = require(&#39;node:vm&#39;);
const context = vm.createContext({});
const myError = vm.runInContext(&#39;new Error()&#39;, context);
console.log(util.types.isNativeError(myError)); // true
console.log(myError instanceof Error); // false
</code></pre>
<p>Conversely, <code>isNativeError()</code> returns <code>false</code> for all objects which were not
returned by the constructor of a native error. That includes values
which are <code>instanceof</code> native errors:</p>
<pre><code class="language-js">const myError = { __proto__: Error.prototype };
console.log(util.types.isNativeError(myError)); // false
console.log(myError instanceof Error); // true
</code></pre>
<h4><code>util.types.isNumberObject(value)</code><span><a class="mark" href="#utiltypesisnumberobjectvalue" id="utiltypesisnumberobjectvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isnumberobject_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is a number object, e.g. created
by <code>new Number()</code>.</p>
<pre><code class="language-js">util.types.isNumberObject(0);  // Returns false
util.types.isNumberObject(new Number(0));   // Returns true
</code></pre>
<h4><code>util.types.isPromise(value)</code><span><a class="mark" href="#utiltypesispromisevalue" id="utiltypesispromisevalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_ispromise_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isPromise(Promise.resolve(42));  // Returns true
</code></pre>
<h4><code>util.types.isProxy(value)</code><span><a class="mark" href="#utiltypesisproxyvalue" id="utiltypesisproxyvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isproxy_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">const target = {};
const proxy = new Proxy(target, {});
util.types.isProxy(target);  // Returns false
util.types.isProxy(proxy);  // Returns true
</code></pre>
<h4><code>util.types.isRegExp(value)</code><span><a class="mark" href="#utiltypesisregexpvalue" id="utiltypesisregexpvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isregexp_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is a regular expression object.</p>
<pre><code class="language-js">util.types.isRegExp(/abc/);  // Returns true
util.types.isRegExp(new RegExp(&#39;abc&#39;));  // Returns true
</code></pre>
<h4><code>util.types.isSet(value)</code><span><a class="mark" href="#utiltypesissetvalue" id="utiltypesissetvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isset_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isSet(new Set());  // Returns true
</code></pre>
<h4><code>util.types.isSetIterator(value)</code><span><a class="mark" href="#utiltypesissetiteratorvalue" id="utiltypesissetiteratorvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_issetiterator_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is an iterator returned for a built-in
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set"><code>Set</code></a> instance.</p>
<pre><code class="language-js">const set = new Set();
util.types.isSetIterator(set.keys());  // Returns true
util.types.isSetIterator(set.values());  // Returns true
util.types.isSetIterator(set.entries());  // Returns true
util.types.isSetIterator(set[Symbol.iterator]());  // Returns true
</code></pre>
<h4><code>util.types.isSharedArrayBuffer(value)</code><span><a class="mark" href="#utiltypesissharedarraybuffervalue" id="utiltypesissharedarraybuffervalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_issharedarraybuffer_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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.
This 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
desirable to test for both; See <a href="#utiltypesisanyarraybuffervalue"><code>util.types.isAnyArrayBuffer()</code></a> for that.</p>
<pre><code class="language-js">util.types.isSharedArrayBuffer(new ArrayBuffer());  // Returns false
util.types.isSharedArrayBuffer(new SharedArrayBuffer());  // Returns true
</code></pre>
<h4><code>util.types.isStringObject(value)</code><span><a class="mark" href="#utiltypesisstringobjectvalue" id="utiltypesisstringobjectvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isstringobject_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is a string object, e.g. created
by <code>new String()</code>.</p>
<pre><code class="language-js">util.types.isStringObject(&#39;foo&#39;);  // Returns false
util.types.isStringObject(new String(&#39;foo&#39;));   // Returns true
</code></pre>
<h4><code>util.types.isSymbolObject(value)</code><span><a class="mark" href="#utiltypesissymbolobjectvalue" id="utiltypesissymbolobjectvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_issymbolobject_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the value is a symbol object, created
by calling <code>Object()</code> on a <code>Symbol</code> primitive.</p>
<pre><code class="language-js">const symbol = Symbol(&#39;foo&#39;);
util.types.isSymbolObject(symbol);  // Returns false
util.types.isSymbolObject(Object(symbol));   // Returns true
</code></pre>
<h4><code>util.types.isTypedArray(value)</code><span><a class="mark" href="#utiltypesistypedarrayvalue" id="utiltypesistypedarrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_istypedarray_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isTypedArray(new ArrayBuffer());  // Returns false
util.types.isTypedArray(new Uint8Array());  // Returns true
util.types.isTypedArray(new Float64Array());  // Returns true
</code></pre>
<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>
<h4><code>util.types.isUint8Array(value)</code><span><a class="mark" href="#utiltypesisuint8arrayvalue" id="utiltypesisuint8arrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isuint8array_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isUint8Array(new ArrayBuffer());  // Returns false
util.types.isUint8Array(new Uint8Array());  // Returns true
util.types.isUint8Array(new Float64Array());  // Returns false
</code></pre>
<h4><code>util.types.isUint8ClampedArray(value)</code><span><a class="mark" href="#utiltypesisuint8clampedarrayvalue" id="utiltypesisuint8clampedarrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isuint8clampedarray_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isUint8ClampedArray(new ArrayBuffer());  // Returns false
util.types.isUint8ClampedArray(new Uint8ClampedArray());  // Returns true
util.types.isUint8ClampedArray(new Float64Array());  // Returns false
</code></pre>
<h4><code>util.types.isUint16Array(value)</code><span><a class="mark" href="#utiltypesisuint16arrayvalue" id="utiltypesisuint16arrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isuint16array_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isUint16Array(new ArrayBuffer());  // Returns false
util.types.isUint16Array(new Uint16Array());  // Returns true
util.types.isUint16Array(new Float64Array());  // Returns false
</code></pre>
<h4><code>util.types.isUint32Array(value)</code><span><a class="mark" href="#utiltypesisuint32arrayvalue" id="utiltypesisuint32arrayvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isuint32array_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isUint32Array(new ArrayBuffer());  // Returns false
util.types.isUint32Array(new Uint32Array());  // Returns true
util.types.isUint32Array(new Float64Array());  // Returns false
</code></pre>
<h4><code>util.types.isWeakMap(value)</code><span><a class="mark" href="#utiltypesisweakmapvalue" id="utiltypesisweakmapvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isweakmap_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isWeakMap(new WeakMap());  // Returns true
</code></pre>
<h4><code>util.types.isWeakSet(value)</code><span><a class="mark" href="#utiltypesisweaksetvalue" id="utiltypesisweaksetvalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_isweakset_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">util.types.isWeakSet(new WeakSet());  // Returns true
</code></pre>
<h4><code>util.types.isWebAssemblyCompiledModule(value)</code><span><a class="mark" href="#utiltypesiswebassemblycompiledmodulevalue" id="utiltypesiswebassemblycompiledmodulevalue">#</a></span><a aria-hidden="true" class="legacy" id="util_util_types_iswebassemblycompiledmodule_value"></a></h4>
<div class="api_metadata">
<span>Added in: v10.0.0</span><span>Deprecated since: v14.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <code>value instanceof WebAssembly.Module</code> instead.</p>
</blockquote>
<ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<pre><code class="language-js">const module = new WebAssembly.Module(wasmBuffer);
util.types.isWebAssemblyCompiledModule(module);  // Returns true
</code></pre>
</section><section><h3>Deprecated APIs<span><a class="mark" href="#deprecated-apis" id="deprecated-apis">#</a></span><a aria-hidden="true" class="legacy" id="util_deprecated_apis"></a></h3>
<p>The following APIs are deprecated and should no longer be used. Existing
applications and modules should be updated to find alternative approaches.</p>
<h4><code>util._extend(target, source)</code><span><a class="mark" href="#util_extendtarget-source" id="util_extendtarget-source">#</a></span><a aria-hidden="true" class="legacy" id="util_util_extend_target_source"></a></h4>
<div class="api_metadata">
<span>Added in: v0.7.5</span><span>Deprecated since: v6.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign"><code>Object.assign()</code></a> instead.</p>
</blockquote>
<ul>
<li><code>target</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
<li><code>source</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>The <code>util._extend()</code> method was never intended to be used outside of internal
Node.js modules. The community found and used it anyway.</p>
<p>It is deprecated and should not be used in new code. JavaScript comes with very
similar 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>
<h4><code>util.isArray(object)</code><span><a class="mark" href="#utilisarrayobject" id="utilisarrayobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isarray_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.6.0</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray"><code>Array.isArray()</code></a> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<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>
<p>Returns <code>true</code> if the given <code>object</code> is an <code>Array</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isArray([]);
// Returns: true
util.isArray(new Array());
// Returns: true
util.isArray({});
// Returns: false
</code></pre>
<h4><code>util.isBoolean(object)</code><span><a class="mark" href="#utilisbooleanobject" id="utilisbooleanobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isboolean_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <code>typeof value === &#39;boolean&#39;</code> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Boolean</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isBoolean(1);
// Returns: false
util.isBoolean(0);
// Returns: false
util.isBoolean(false);
// Returns: true
</code></pre>
<h4><code>util.isBuffer(object)</code><span><a class="mark" href="#utilisbufferobject" id="utilisbufferobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isbuffer_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <a href="buffer.html#static-method-bufferisbufferobj"><code>Buffer.isBuffer()</code></a> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Buffer</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isBuffer({ length: 0 });
// Returns: false
util.isBuffer([]);
// Returns: false
util.isBuffer(Buffer.from(&#39;hello world&#39;));
// Returns: true
</code></pre>
<h4><code>util.isDate(object)</code><span><a class="mark" href="#utilisdateobject" id="utilisdateobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isdate_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.6.0</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <a href="#utiltypesisdatevalue"><code>util.types.isDate()</code></a> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Date</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isDate(new Date());
// Returns: true
util.isDate(Date());
// false (without &#39;new&#39; returns a String)
util.isDate({});
// Returns: false
</code></pre>
<h4><code>util.isError(object)</code><span><a class="mark" href="#utiliserrorobject" id="utiliserrorobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_iserror_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.6.0</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <a href="#utiltypesisnativeerrorvalue"><code>util.types.isNativeError()</code></a> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is an <a href="errors.html#class-error"><code>Error</code></a>. Otherwise, returns
<code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isError(new Error());
// Returns: true
util.isError(new TypeError());
// Returns: true
util.isError({ name: &#39;Error&#39;, message: &#39;an error occurred&#39; });
// Returns: false
</code></pre>
<p>This method relies on <code>Object.prototype.toString()</code> behavior. It is
possible to obtain an incorrect result when the <code>object</code> argument manipulates
<code>@@toStringTag</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);
const obj = { name: &#39;Error&#39;, message: &#39;an error occurred&#39; };

util.isError(obj);
// Returns: false
obj[Symbol.toStringTag] = &#39;Error&#39;;
util.isError(obj);
// Returns: true
</code></pre>
<h4><code>util.isFunction(object)</code><span><a class="mark" href="#utilisfunctionobject" id="utilisfunctionobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isfunction_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <code>typeof value === &#39;function&#39;</code> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Function</code>. Otherwise, returns
<code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

function Foo() {}
const Bar = () =&gt; {};

util.isFunction({});
// Returns: false
util.isFunction(Foo);
// Returns: true
util.isFunction(Bar);
// Returns: true
</code></pre>
<h4><code>util.isNull(object)</code><span><a class="mark" href="#utilisnullobject" id="utilisnullobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isnull_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <code>value === null</code> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is strictly <code>null</code>. Otherwise, returns
<code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isNull(0);
// Returns: false
util.isNull(undefined);
// Returns: false
util.isNull(null);
// Returns: true
</code></pre>
<h4><code>util.isNullOrUndefined(object)</code><span><a class="mark" href="#utilisnullorundefinedobject" id="utilisnullorundefinedobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isnullorundefined_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use
<code>value === undefined || value === null</code> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is <code>null</code> or <code>undefined</code>. Otherwise,
returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isNullOrUndefined(0);
// Returns: false
util.isNullOrUndefined(undefined);
// Returns: true
util.isNullOrUndefined(null);
// Returns: true
</code></pre>
<h4><code>util.isNumber(object)</code><span><a class="mark" href="#utilisnumberobject" id="utilisnumberobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isnumber_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <code>typeof value === &#39;number&#39;</code> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Number</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isNumber(false);
// Returns: false
util.isNumber(Infinity);
// Returns: true
util.isNumber(0);
// Returns: true
util.isNumber(NaN);
// Returns: true
</code></pre>
<h4><code>util.isObject(object)</code><span><a class="mark" href="#utilisobjectobject" id="utilisobjectobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isobject_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated:
Use <code>value !== null &amp;&amp; typeof value === &#39;object&#39;</code> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is strictly an <code>Object</code> <strong>and</strong> not a
<code>Function</code> (even though functions are objects in JavaScript).
Otherwise, returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isObject(5);
// Returns: false
util.isObject(null);
// Returns: false
util.isObject({});
// Returns: true
util.isObject(() =&gt; {});
// Returns: false
</code></pre>
<h4><code>util.isPrimitive(object)</code><span><a class="mark" href="#utilisprimitiveobject" id="utilisprimitiveobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isprimitive_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use
<code>(typeof value !== &#39;object&#39; &amp;&amp; typeof value !== &#39;function&#39;) || value === null</code>
instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a primitive type. Otherwise, returns
<code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isPrimitive(5);
// Returns: true
util.isPrimitive(&#39;foo&#39;);
// Returns: true
util.isPrimitive(false);
// Returns: true
util.isPrimitive(null);
// Returns: true
util.isPrimitive(undefined);
// Returns: true
util.isPrimitive({});
// Returns: false
util.isPrimitive(() =&gt; {});
// Returns: false
util.isPrimitive(/^$/);
// Returns: false
util.isPrimitive(new Date());
// Returns: false
</code></pre>
<h4><code>util.isRegExp(object)</code><span><a class="mark" href="#utilisregexpobject" id="utilisregexpobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isregexp_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.6.0</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>RegExp</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isRegExp(/some regexp/);
// Returns: true
util.isRegExp(new RegExp(&#39;another regexp&#39;));
// Returns: true
util.isRegExp({});
// Returns: false
</code></pre>
<h4><code>util.isString(object)</code><span><a class="mark" href="#utilisstringobject" id="utilisstringobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isstring_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <code>typeof value === &#39;string&#39;</code> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>string</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isString(&#39;&#39;);
// Returns: true
util.isString(&#39;foo&#39;);
// Returns: true
util.isString(String(&#39;foo&#39;));
// Returns: true
util.isString(5);
// Returns: false
</code></pre>
<h4><code>util.isSymbol(object)</code><span><a class="mark" href="#utilissymbolobject" id="utilissymbolobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_issymbol_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <code>typeof value === &#39;symbol&#39;</code> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Symbol</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.isSymbol(5);
// Returns: false
util.isSymbol(&#39;foo&#39;);
// Returns: false
util.isSymbol(Symbol(&#39;foo&#39;));
// Returns: true
</code></pre>
<h4><code>util.isUndefined(object)</code><span><a class="mark" href="#utilisundefinedobject" id="utilisundefinedobject">#</a></span><a aria-hidden="true" class="legacy" id="util_util_isundefined_object"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use <code>value === undefined</code> instead.</p>
</blockquote>
<ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is <code>undefined</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

const foo = undefined;
util.isUndefined(5);
// Returns: false
util.isUndefined(foo);
// Returns: true
util.isUndefined(null);
// Returns: false
</code></pre>
<h4><code>util.log(string)</code><span><a class="mark" href="#utillogstring" id="utillogstring">#</a></span><a aria-hidden="true" class="legacy" id="util_util_log_string"></a></h4>
<div class="api_metadata">
<span>Added in: v0.3.0</span><span>Deprecated since: v6.0.0</span>
</div><blockquote>
<p>Stability: 0 - Deprecated: Use a third party module instead.</p>
</blockquote>
<ul>
<li><code>string</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>The <code>util.log()</code> method prints the given <code>string</code> to <code>stdout</code> with an included
timestamp.</p>
<pre><code class="language-js">const util = require(&#39;node:util&#39;);

util.log(&#39;Timestamped message.&#39;);
</code></pre>
</section>
        <!-- API END -->
      </div>
    </div>
  </div>
</body>
</html>

Zerion Mini Shell 1.0