11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<html lang="en">
31cb0ef41Sopenharmony_ci<head>
41cb0ef41Sopenharmony_ci  <meta charset="utf-8">
51cb0ef41Sopenharmony_ci  <meta name="viewport" content="width=device-width">
61cb0ef41Sopenharmony_ci  <meta name="nodejs.org:node-version" content="v18.20.1">
71cb0ef41Sopenharmony_ci  <title>Util | Node.js v18.20.1 Documentation</title>
81cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
91cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="assets/style.css">
101cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="assets/hljs.css">
111cb0ef41Sopenharmony_ci  <link rel="canonical" href="https://nodejs.org/api/util.html">
121cb0ef41Sopenharmony_ci  <script async defer src="assets/api.js" type="text/javascript"></script>
131cb0ef41Sopenharmony_ci  <style>@media(max-width:558px){.with-42-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:718px){.with-62-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:574px){.with-44-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:566px){.with-43-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:550px){.with-41-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}</style>
141cb0ef41Sopenharmony_ci</head>
151cb0ef41Sopenharmony_ci<body class="alt apidoc" id="api-section-util">
161cb0ef41Sopenharmony_ci  <div id="content" class="clearfix">
171cb0ef41Sopenharmony_ci    <div id="column2" class="interior">
181cb0ef41Sopenharmony_ci      <div id="intro" class="interior">
191cb0ef41Sopenharmony_ci        <a href="/" title="Go back to the home page">
201cb0ef41Sopenharmony_ci          Node.js
211cb0ef41Sopenharmony_ci        </a>
221cb0ef41Sopenharmony_ci      </div>
231cb0ef41Sopenharmony_ci      <ul>
241cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
251cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
261cb0ef41Sopenharmony_ci</ul>
271cb0ef41Sopenharmony_ci<hr class="line">
281cb0ef41Sopenharmony_ci<ul>
291cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
301cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
311cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
321cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
331cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
341cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
351cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
361cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
371cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
381cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
391cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
401cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
411cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
421cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
431cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
441cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
451cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns">DNS</a></li>
461cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
471cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
481cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
491cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
501cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
511cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
521cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
531cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
541cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
551cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
561cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
571cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
581cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
591cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
601cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
611cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
621cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
631cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
641cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
651cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process">Process</a></li>
661cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
671cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
681cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
691cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
701cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
711cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
721cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
731cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
741cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
751cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
761cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
771cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
781cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
791cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
801cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
811cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util active">Utilities</a></li>
821cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
831cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
841cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
851cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
861cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
871cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
881cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
891cb0ef41Sopenharmony_ci</ul>
901cb0ef41Sopenharmony_ci<hr class="line">
911cb0ef41Sopenharmony_ci<ul>
921cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
931cb0ef41Sopenharmony_ci</ul>
941cb0ef41Sopenharmony_ci    </div>
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci    <div id="column1" data-id="util" class="interior">
971cb0ef41Sopenharmony_ci      <header class="header">
981cb0ef41Sopenharmony_ci        <div class="header-container">
991cb0ef41Sopenharmony_ci          <h1>Node.js v18.20.1 documentation</h1>
1001cb0ef41Sopenharmony_ci          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
1011cb0ef41Sopenharmony_ci            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
1021cb0ef41Sopenharmony_ci              <path fill="none" d="M0 0h24v24H0z" />
1031cb0ef41Sopenharmony_ci              <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"/>
1041cb0ef41Sopenharmony_ci              <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"/>
1051cb0ef41Sopenharmony_ci            </svg>
1061cb0ef41Sopenharmony_ci            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
1071cb0ef41Sopenharmony_ci              <path d="M0 0h24v24H0z" fill="none" />
1081cb0ef41Sopenharmony_ci              <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"/>
1091cb0ef41Sopenharmony_ci            </svg>
1101cb0ef41Sopenharmony_ci          </button>
1111cb0ef41Sopenharmony_ci        </div>
1121cb0ef41Sopenharmony_ci        <div id="gtoc">
1131cb0ef41Sopenharmony_ci          <ul>
1141cb0ef41Sopenharmony_ci            <li class="pinned-header">Node.js v18.20.1</li>
1151cb0ef41Sopenharmony_ci            
1161cb0ef41Sopenharmony_ci    <li class="picker-header">
1171cb0ef41Sopenharmony_ci      <a href="#">
1181cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
1191cb0ef41Sopenharmony_ci        Table of contents
1201cb0ef41Sopenharmony_ci      </a>
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci      <div class="picker"><div class="toc"><ul>
1231cb0ef41Sopenharmony_ci<li><span class="stability_2"><a href="#util">Util</a></span>
1241cb0ef41Sopenharmony_ci<ul>
1251cb0ef41Sopenharmony_ci<li><a href="#utilcallbackifyoriginal"><code>util.callbackify(original)</code></a></li>
1261cb0ef41Sopenharmony_ci<li><a href="#utildebuglogsection-callback"><code>util.debuglog(section[, callback])</code></a>
1271cb0ef41Sopenharmony_ci<ul>
1281cb0ef41Sopenharmony_ci<li><a href="#debuglogenabled"><code>debuglog().enabled</code></a></li>
1291cb0ef41Sopenharmony_ci</ul>
1301cb0ef41Sopenharmony_ci</li>
1311cb0ef41Sopenharmony_ci<li><a href="#utildebugsection"><code>util.debug(section)</code></a></li>
1321cb0ef41Sopenharmony_ci<li><a href="#utildeprecatefn-msg-code"><code>util.deprecate(fn, msg[, code])</code></a></li>
1331cb0ef41Sopenharmony_ci<li><a href="#utilformatformat-args"><code>util.format(format[, ...args])</code></a></li>
1341cb0ef41Sopenharmony_ci<li><a href="#utilformatwithoptionsinspectoptions-format-args"><code>util.formatWithOptions(inspectOptions, format[, ...args])</code></a></li>
1351cb0ef41Sopenharmony_ci<li><a href="#utilgetsystemerrornameerr"><code>util.getSystemErrorName(err)</code></a></li>
1361cb0ef41Sopenharmony_ci<li><a href="#utilgetsystemerrormap"><code>util.getSystemErrorMap()</code></a></li>
1371cb0ef41Sopenharmony_ci<li><span class="stability_3"><a href="#utilinheritsconstructor-superconstructor"><code>util.inherits(constructor, superConstructor)</code></a></span></li>
1381cb0ef41Sopenharmony_ci<li><a href="#utilinspectobject-options"><code>util.inspect(object[, options])</code></a></li>
1391cb0ef41Sopenharmony_ci<li><a href="#utilinspectobject-showhidden-depth-colors"><code>util.inspect(object[, showHidden[, depth[, colors]]])</code></a>
1401cb0ef41Sopenharmony_ci<ul>
1411cb0ef41Sopenharmony_ci<li><a href="#customizing-utilinspect-colors">Customizing <code>util.inspect</code> colors</a>
1421cb0ef41Sopenharmony_ci<ul>
1431cb0ef41Sopenharmony_ci<li><a href="#modifiers">Modifiers</a></li>
1441cb0ef41Sopenharmony_ci<li><a href="#foreground-colors">Foreground colors</a></li>
1451cb0ef41Sopenharmony_ci<li><a href="#background-colors">Background colors</a></li>
1461cb0ef41Sopenharmony_ci</ul>
1471cb0ef41Sopenharmony_ci</li>
1481cb0ef41Sopenharmony_ci<li><a href="#custom-inspection-functions-on-objects">Custom inspection functions on objects</a></li>
1491cb0ef41Sopenharmony_ci<li><a href="#utilinspectcustom"><code>util.inspect.custom</code></a></li>
1501cb0ef41Sopenharmony_ci<li><a href="#utilinspectdefaultoptions"><code>util.inspect.defaultOptions</code></a></li>
1511cb0ef41Sopenharmony_ci</ul>
1521cb0ef41Sopenharmony_ci</li>
1531cb0ef41Sopenharmony_ci<li><a href="#utilisdeepstrictequalval1-val2"><code>util.isDeepStrictEqual(val1, val2)</code></a></li>
1541cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#class-utilmimetype">Class: <code>util.MIMEType</code></a></span>
1551cb0ef41Sopenharmony_ci<ul>
1561cb0ef41Sopenharmony_ci<li><a href="#constructor-new-mimetypeinput">Constructor: <code>new MIMEType(input)</code></a></li>
1571cb0ef41Sopenharmony_ci<li><a href="#mimetype"><code>mime.type</code></a></li>
1581cb0ef41Sopenharmony_ci<li><a href="#mimesubtype"><code>mime.subtype</code></a></li>
1591cb0ef41Sopenharmony_ci<li><a href="#mimeessence"><code>mime.essence</code></a></li>
1601cb0ef41Sopenharmony_ci<li><a href="#mimeparams"><code>mime.params</code></a></li>
1611cb0ef41Sopenharmony_ci<li><a href="#mimetostring"><code>mime.toString()</code></a></li>
1621cb0ef41Sopenharmony_ci<li><a href="#mimetojson"><code>mime.toJSON()</code></a></li>
1631cb0ef41Sopenharmony_ci</ul>
1641cb0ef41Sopenharmony_ci</li>
1651cb0ef41Sopenharmony_ci<li><a href="#class-utilmimeparams">Class: <code>util.MIMEParams</code></a>
1661cb0ef41Sopenharmony_ci<ul>
1671cb0ef41Sopenharmony_ci<li><a href="#constructor-new-mimeparams">Constructor: <code>new MIMEParams()</code></a></li>
1681cb0ef41Sopenharmony_ci<li><a href="#mimeparamsdeletename"><code>mimeParams.delete(name)</code></a></li>
1691cb0ef41Sopenharmony_ci<li><a href="#mimeparamsentries"><code>mimeParams.entries()</code></a></li>
1701cb0ef41Sopenharmony_ci<li><a href="#mimeparamsgetname"><code>mimeParams.get(name)</code></a></li>
1711cb0ef41Sopenharmony_ci<li><a href="#mimeparamshasname"><code>mimeParams.has(name)</code></a></li>
1721cb0ef41Sopenharmony_ci<li><a href="#mimeparamskeys"><code>mimeParams.keys()</code></a></li>
1731cb0ef41Sopenharmony_ci<li><a href="#mimeparamssetname-value"><code>mimeParams.set(name, value)</code></a></li>
1741cb0ef41Sopenharmony_ci<li><a href="#mimeparamsvalues"><code>mimeParams.values()</code></a></li>
1751cb0ef41Sopenharmony_ci<li><a href="#mimeparamsiterator"><code>mimeParams[@@iterator]()</code></a></li>
1761cb0ef41Sopenharmony_ci</ul>
1771cb0ef41Sopenharmony_ci</li>
1781cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#utilparseargsconfig"><code>util.parseArgs([config])</code></a></span>
1791cb0ef41Sopenharmony_ci<ul>
1801cb0ef41Sopenharmony_ci<li><a href="#parseargs-tokens"><code>parseArgs</code> <code>tokens</code></a></li>
1811cb0ef41Sopenharmony_ci</ul>
1821cb0ef41Sopenharmony_ci</li>
1831cb0ef41Sopenharmony_ci<li><a href="#utilpromisifyoriginal"><code>util.promisify(original)</code></a>
1841cb0ef41Sopenharmony_ci<ul>
1851cb0ef41Sopenharmony_ci<li><a href="#custom-promisified-functions">Custom promisified functions</a></li>
1861cb0ef41Sopenharmony_ci<li><a href="#utilpromisifycustom"><code>util.promisify.custom</code></a></li>
1871cb0ef41Sopenharmony_ci</ul>
1881cb0ef41Sopenharmony_ci</li>
1891cb0ef41Sopenharmony_ci<li><a href="#utilstripvtcontrolcharactersstr"><code>util.stripVTControlCharacters(str)</code></a></li>
1901cb0ef41Sopenharmony_ci<li><a href="#class-utiltextdecoder">Class: <code>util.TextDecoder</code></a>
1911cb0ef41Sopenharmony_ci<ul>
1921cb0ef41Sopenharmony_ci<li><a href="#whatwg-supported-encodings">WHATWG supported encodings</a>
1931cb0ef41Sopenharmony_ci<ul>
1941cb0ef41Sopenharmony_ci<li><a href="#encodings-supported-by-default-with-full-icu-data">Encodings supported by default (with full ICU data)</a></li>
1951cb0ef41Sopenharmony_ci<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>
1961cb0ef41Sopenharmony_ci<li><a href="#encodings-supported-when-icu-is-disabled">Encodings supported when ICU is disabled</a></li>
1971cb0ef41Sopenharmony_ci</ul>
1981cb0ef41Sopenharmony_ci</li>
1991cb0ef41Sopenharmony_ci<li><a href="#new-textdecoderencoding-options"><code>new TextDecoder([encoding[, options]])</code></a></li>
2001cb0ef41Sopenharmony_ci<li><a href="#textdecoderdecodeinput-options"><code>textDecoder.decode([input[, options]])</code></a></li>
2011cb0ef41Sopenharmony_ci<li><a href="#textdecoderencoding"><code>textDecoder.encoding</code></a></li>
2021cb0ef41Sopenharmony_ci<li><a href="#textdecoderfatal"><code>textDecoder.fatal</code></a></li>
2031cb0ef41Sopenharmony_ci<li><a href="#textdecoderignorebom"><code>textDecoder.ignoreBOM</code></a></li>
2041cb0ef41Sopenharmony_ci</ul>
2051cb0ef41Sopenharmony_ci</li>
2061cb0ef41Sopenharmony_ci<li><a href="#class-utiltextencoder">Class: <code>util.TextEncoder</code></a>
2071cb0ef41Sopenharmony_ci<ul>
2081cb0ef41Sopenharmony_ci<li><a href="#textencoderencodeinput"><code>textEncoder.encode([input])</code></a></li>
2091cb0ef41Sopenharmony_ci<li><a href="#textencoderencodeintosrc-dest"><code>textEncoder.encodeInto(src, dest)</code></a></li>
2101cb0ef41Sopenharmony_ci<li><a href="#textencoderencoding"><code>textEncoder.encoding</code></a></li>
2111cb0ef41Sopenharmony_ci</ul>
2121cb0ef41Sopenharmony_ci</li>
2131cb0ef41Sopenharmony_ci<li><a href="#utiltousvstringstring"><code>util.toUSVString(string)</code></a></li>
2141cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#utiltransferableabortcontroller"><code>util.transferableAbortController()</code></a></span></li>
2151cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#utiltransferableabortsignalsignal"><code>util.transferableAbortSignal(signal)</code></a></span></li>
2161cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#utilabortedsignal-resource"><code>util.aborted(signal, resource)</code></a></span></li>
2171cb0ef41Sopenharmony_ci<li><a href="#utiltypes"><code>util.types</code></a>
2181cb0ef41Sopenharmony_ci<ul>
2191cb0ef41Sopenharmony_ci<li><a href="#utiltypesisanyarraybuffervalue"><code>util.types.isAnyArrayBuffer(value)</code></a></li>
2201cb0ef41Sopenharmony_ci<li><a href="#utiltypesisarraybufferviewvalue"><code>util.types.isArrayBufferView(value)</code></a></li>
2211cb0ef41Sopenharmony_ci<li><a href="#utiltypesisargumentsobjectvalue"><code>util.types.isArgumentsObject(value)</code></a></li>
2221cb0ef41Sopenharmony_ci<li><a href="#utiltypesisarraybuffervalue"><code>util.types.isArrayBuffer(value)</code></a></li>
2231cb0ef41Sopenharmony_ci<li><a href="#utiltypesisasyncfunctionvalue"><code>util.types.isAsyncFunction(value)</code></a></li>
2241cb0ef41Sopenharmony_ci<li><a href="#utiltypesisbigint64arrayvalue"><code>util.types.isBigInt64Array(value)</code></a></li>
2251cb0ef41Sopenharmony_ci<li><a href="#utiltypesisbiguint64arrayvalue"><code>util.types.isBigUint64Array(value)</code></a></li>
2261cb0ef41Sopenharmony_ci<li><a href="#utiltypesisbooleanobjectvalue"><code>util.types.isBooleanObject(value)</code></a></li>
2271cb0ef41Sopenharmony_ci<li><a href="#utiltypesisboxedprimitivevalue"><code>util.types.isBoxedPrimitive(value)</code></a></li>
2281cb0ef41Sopenharmony_ci<li><a href="#utiltypesiscryptokeyvalue"><code>util.types.isCryptoKey(value)</code></a></li>
2291cb0ef41Sopenharmony_ci<li><a href="#utiltypesisdataviewvalue"><code>util.types.isDataView(value)</code></a></li>
2301cb0ef41Sopenharmony_ci<li><a href="#utiltypesisdatevalue"><code>util.types.isDate(value)</code></a></li>
2311cb0ef41Sopenharmony_ci<li><a href="#utiltypesisexternalvalue"><code>util.types.isExternal(value)</code></a></li>
2321cb0ef41Sopenharmony_ci<li><a href="#utiltypesisfloat32arrayvalue"><code>util.types.isFloat32Array(value)</code></a></li>
2331cb0ef41Sopenharmony_ci<li><a href="#utiltypesisfloat64arrayvalue"><code>util.types.isFloat64Array(value)</code></a></li>
2341cb0ef41Sopenharmony_ci<li><a href="#utiltypesisgeneratorfunctionvalue"><code>util.types.isGeneratorFunction(value)</code></a></li>
2351cb0ef41Sopenharmony_ci<li><a href="#utiltypesisgeneratorobjectvalue"><code>util.types.isGeneratorObject(value)</code></a></li>
2361cb0ef41Sopenharmony_ci<li><a href="#utiltypesisint8arrayvalue"><code>util.types.isInt8Array(value)</code></a></li>
2371cb0ef41Sopenharmony_ci<li><a href="#utiltypesisint16arrayvalue"><code>util.types.isInt16Array(value)</code></a></li>
2381cb0ef41Sopenharmony_ci<li><a href="#utiltypesisint32arrayvalue"><code>util.types.isInt32Array(value)</code></a></li>
2391cb0ef41Sopenharmony_ci<li><a href="#utiltypesiskeyobjectvalue"><code>util.types.isKeyObject(value)</code></a></li>
2401cb0ef41Sopenharmony_ci<li><a href="#utiltypesismapvalue"><code>util.types.isMap(value)</code></a></li>
2411cb0ef41Sopenharmony_ci<li><a href="#utiltypesismapiteratorvalue"><code>util.types.isMapIterator(value)</code></a></li>
2421cb0ef41Sopenharmony_ci<li><a href="#utiltypesismodulenamespaceobjectvalue"><code>util.types.isModuleNamespaceObject(value)</code></a></li>
2431cb0ef41Sopenharmony_ci<li><a href="#utiltypesisnativeerrorvalue"><code>util.types.isNativeError(value)</code></a></li>
2441cb0ef41Sopenharmony_ci<li><a href="#utiltypesisnumberobjectvalue"><code>util.types.isNumberObject(value)</code></a></li>
2451cb0ef41Sopenharmony_ci<li><a href="#utiltypesispromisevalue"><code>util.types.isPromise(value)</code></a></li>
2461cb0ef41Sopenharmony_ci<li><a href="#utiltypesisproxyvalue"><code>util.types.isProxy(value)</code></a></li>
2471cb0ef41Sopenharmony_ci<li><a href="#utiltypesisregexpvalue"><code>util.types.isRegExp(value)</code></a></li>
2481cb0ef41Sopenharmony_ci<li><a href="#utiltypesissetvalue"><code>util.types.isSet(value)</code></a></li>
2491cb0ef41Sopenharmony_ci<li><a href="#utiltypesissetiteratorvalue"><code>util.types.isSetIterator(value)</code></a></li>
2501cb0ef41Sopenharmony_ci<li><a href="#utiltypesissharedarraybuffervalue"><code>util.types.isSharedArrayBuffer(value)</code></a></li>
2511cb0ef41Sopenharmony_ci<li><a href="#utiltypesisstringobjectvalue"><code>util.types.isStringObject(value)</code></a></li>
2521cb0ef41Sopenharmony_ci<li><a href="#utiltypesissymbolobjectvalue"><code>util.types.isSymbolObject(value)</code></a></li>
2531cb0ef41Sopenharmony_ci<li><a href="#utiltypesistypedarrayvalue"><code>util.types.isTypedArray(value)</code></a></li>
2541cb0ef41Sopenharmony_ci<li><a href="#utiltypesisuint8arrayvalue"><code>util.types.isUint8Array(value)</code></a></li>
2551cb0ef41Sopenharmony_ci<li><a href="#utiltypesisuint8clampedarrayvalue"><code>util.types.isUint8ClampedArray(value)</code></a></li>
2561cb0ef41Sopenharmony_ci<li><a href="#utiltypesisuint16arrayvalue"><code>util.types.isUint16Array(value)</code></a></li>
2571cb0ef41Sopenharmony_ci<li><a href="#utiltypesisuint32arrayvalue"><code>util.types.isUint32Array(value)</code></a></li>
2581cb0ef41Sopenharmony_ci<li><a href="#utiltypesisweakmapvalue"><code>util.types.isWeakMap(value)</code></a></li>
2591cb0ef41Sopenharmony_ci<li><a href="#utiltypesisweaksetvalue"><code>util.types.isWeakSet(value)</code></a></li>
2601cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utiltypesiswebassemblycompiledmodulevalue"><code>util.types.isWebAssemblyCompiledModule(value)</code></a></span></li>
2611cb0ef41Sopenharmony_ci</ul>
2621cb0ef41Sopenharmony_ci</li>
2631cb0ef41Sopenharmony_ci<li><a href="#deprecated-apis">Deprecated APIs</a>
2641cb0ef41Sopenharmony_ci<ul>
2651cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#util_extendtarget-source"><code>util._extend(target, source)</code></a></span></li>
2661cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisarrayobject"><code>util.isArray(object)</code></a></span></li>
2671cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisbooleanobject"><code>util.isBoolean(object)</code></a></span></li>
2681cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisbufferobject"><code>util.isBuffer(object)</code></a></span></li>
2691cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisdateobject"><code>util.isDate(object)</code></a></span></li>
2701cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utiliserrorobject"><code>util.isError(object)</code></a></span></li>
2711cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisfunctionobject"><code>util.isFunction(object)</code></a></span></li>
2721cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisnullobject"><code>util.isNull(object)</code></a></span></li>
2731cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisnullorundefinedobject"><code>util.isNullOrUndefined(object)</code></a></span></li>
2741cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisnumberobject"><code>util.isNumber(object)</code></a></span></li>
2751cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisobjectobject"><code>util.isObject(object)</code></a></span></li>
2761cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisprimitiveobject"><code>util.isPrimitive(object)</code></a></span></li>
2771cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisregexpobject"><code>util.isRegExp(object)</code></a></span></li>
2781cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisstringobject"><code>util.isString(object)</code></a></span></li>
2791cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilissymbolobject"><code>util.isSymbol(object)</code></a></span></li>
2801cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisundefinedobject"><code>util.isUndefined(object)</code></a></span></li>
2811cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utillogstring"><code>util.log(string)</code></a></span></li>
2821cb0ef41Sopenharmony_ci</ul>
2831cb0ef41Sopenharmony_ci</li>
2841cb0ef41Sopenharmony_ci</ul>
2851cb0ef41Sopenharmony_ci</li>
2861cb0ef41Sopenharmony_ci</ul></div></div>
2871cb0ef41Sopenharmony_ci    </li>
2881cb0ef41Sopenharmony_ci  
2891cb0ef41Sopenharmony_ci            
2901cb0ef41Sopenharmony_ci    <li class="picker-header">
2911cb0ef41Sopenharmony_ci      <a href="#">
2921cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
2931cb0ef41Sopenharmony_ci        Index
2941cb0ef41Sopenharmony_ci      </a>
2951cb0ef41Sopenharmony_ci
2961cb0ef41Sopenharmony_ci      <div class="picker"><ul>
2971cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
2981cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
2991cb0ef41Sopenharmony_ci
3001cb0ef41Sopenharmony_ci      <li>
3011cb0ef41Sopenharmony_ci        <a href="index.html">Index</a>
3021cb0ef41Sopenharmony_ci      </li>
3031cb0ef41Sopenharmony_ci    </ul>
3041cb0ef41Sopenharmony_ci  
3051cb0ef41Sopenharmony_ci<hr class="line">
3061cb0ef41Sopenharmony_ci<ul>
3071cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
3081cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
3091cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
3101cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
3111cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
3121cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
3131cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
3141cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
3151cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
3161cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
3171cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
3181cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
3191cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
3201cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
3211cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
3221cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
3231cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns">DNS</a></li>
3241cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
3251cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
3261cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
3271cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
3281cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
3291cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
3301cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
3311cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
3321cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
3331cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
3341cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
3351cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
3361cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
3371cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
3381cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
3391cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
3401cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
3411cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
3421cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
3431cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process">Process</a></li>
3441cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
3451cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
3461cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
3471cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
3481cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
3491cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
3501cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
3511cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
3521cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
3531cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
3541cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
3551cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
3561cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
3571cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
3581cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
3591cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util active">Utilities</a></li>
3601cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
3611cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
3621cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
3631cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
3641cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
3651cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
3661cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
3671cb0ef41Sopenharmony_ci</ul>
3681cb0ef41Sopenharmony_ci<hr class="line">
3691cb0ef41Sopenharmony_ci<ul>
3701cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
3711cb0ef41Sopenharmony_ci</ul></div>
3721cb0ef41Sopenharmony_ci    </li>
3731cb0ef41Sopenharmony_ci  
3741cb0ef41Sopenharmony_ci            
3751cb0ef41Sopenharmony_ci    <li class="picker-header">
3761cb0ef41Sopenharmony_ci      <a href="#">
3771cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
3781cb0ef41Sopenharmony_ci        Other versions
3791cb0ef41Sopenharmony_ci      </a>
3801cb0ef41Sopenharmony_ci      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v21.x/api/util.html">21.x</a></li>
3811cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v20.x/api/util.html">20.x <b>LTS</b></a></li>
3821cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v19.x/api/util.html">19.x</a></li>
3831cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v18.x/api/util.html">18.x <b>LTS</b></a></li>
3841cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v17.x/api/util.html">17.x</a></li>
3851cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v16.x/api/util.html">16.x</a></li>
3861cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v15.x/api/util.html">15.x</a></li>
3871cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v14.x/api/util.html">14.x</a></li>
3881cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v13.x/api/util.html">13.x</a></li>
3891cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v12.x/api/util.html">12.x</a></li>
3901cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v11.x/api/util.html">11.x</a></li>
3911cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v10.x/api/util.html">10.x</a></li>
3921cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v9.x/api/util.html">9.x</a></li>
3931cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v8.x/api/util.html">8.x</a></li>
3941cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v7.x/api/util.html">7.x</a></li>
3951cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v6.x/api/util.html">6.x</a></li>
3961cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v5.x/api/util.html">5.x</a></li>
3971cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v4.x/api/util.html">4.x</a></li>
3981cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/util.html">0.12.x</a></li>
3991cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/util.html">0.10.x</a></li></ol></div>
4001cb0ef41Sopenharmony_ci    </li>
4011cb0ef41Sopenharmony_ci  
4021cb0ef41Sopenharmony_ci            <li class="picker-header">
4031cb0ef41Sopenharmony_ci              <a href="#">
4041cb0ef41Sopenharmony_ci                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
4051cb0ef41Sopenharmony_ci                Options
4061cb0ef41Sopenharmony_ci              </a>
4071cb0ef41Sopenharmony_ci        
4081cb0ef41Sopenharmony_ci              <div class="picker">
4091cb0ef41Sopenharmony_ci                <ul>
4101cb0ef41Sopenharmony_ci                  <li>
4111cb0ef41Sopenharmony_ci                    <a href="all.html">View on single page</a>
4121cb0ef41Sopenharmony_ci                  </li>
4131cb0ef41Sopenharmony_ci                  <li>
4141cb0ef41Sopenharmony_ci                    <a href="util.json">View as JSON</a>
4151cb0ef41Sopenharmony_ci                  </li>
4161cb0ef41Sopenharmony_ci                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/util.md">Edit on GitHub</a></li>    
4171cb0ef41Sopenharmony_ci                </ul>
4181cb0ef41Sopenharmony_ci              </div>
4191cb0ef41Sopenharmony_ci            </li>
4201cb0ef41Sopenharmony_ci          </ul>
4211cb0ef41Sopenharmony_ci        </div>
4221cb0ef41Sopenharmony_ci        <hr>
4231cb0ef41Sopenharmony_ci      </header>
4241cb0ef41Sopenharmony_ci
4251cb0ef41Sopenharmony_ci      <details id="toc" open><summary>Table of contents</summary><ul>
4261cb0ef41Sopenharmony_ci<li><span class="stability_2"><a href="#util">Util</a></span>
4271cb0ef41Sopenharmony_ci<ul>
4281cb0ef41Sopenharmony_ci<li><a href="#utilcallbackifyoriginal"><code>util.callbackify(original)</code></a></li>
4291cb0ef41Sopenharmony_ci<li><a href="#utildebuglogsection-callback"><code>util.debuglog(section[, callback])</code></a>
4301cb0ef41Sopenharmony_ci<ul>
4311cb0ef41Sopenharmony_ci<li><a href="#debuglogenabled"><code>debuglog().enabled</code></a></li>
4321cb0ef41Sopenharmony_ci</ul>
4331cb0ef41Sopenharmony_ci</li>
4341cb0ef41Sopenharmony_ci<li><a href="#utildebugsection"><code>util.debug(section)</code></a></li>
4351cb0ef41Sopenharmony_ci<li><a href="#utildeprecatefn-msg-code"><code>util.deprecate(fn, msg[, code])</code></a></li>
4361cb0ef41Sopenharmony_ci<li><a href="#utilformatformat-args"><code>util.format(format[, ...args])</code></a></li>
4371cb0ef41Sopenharmony_ci<li><a href="#utilformatwithoptionsinspectoptions-format-args"><code>util.formatWithOptions(inspectOptions, format[, ...args])</code></a></li>
4381cb0ef41Sopenharmony_ci<li><a href="#utilgetsystemerrornameerr"><code>util.getSystemErrorName(err)</code></a></li>
4391cb0ef41Sopenharmony_ci<li><a href="#utilgetsystemerrormap"><code>util.getSystemErrorMap()</code></a></li>
4401cb0ef41Sopenharmony_ci<li><span class="stability_3"><a href="#utilinheritsconstructor-superconstructor"><code>util.inherits(constructor, superConstructor)</code></a></span></li>
4411cb0ef41Sopenharmony_ci<li><a href="#utilinspectobject-options"><code>util.inspect(object[, options])</code></a></li>
4421cb0ef41Sopenharmony_ci<li><a href="#utilinspectobject-showhidden-depth-colors"><code>util.inspect(object[, showHidden[, depth[, colors]]])</code></a>
4431cb0ef41Sopenharmony_ci<ul>
4441cb0ef41Sopenharmony_ci<li><a href="#customizing-utilinspect-colors">Customizing <code>util.inspect</code> colors</a>
4451cb0ef41Sopenharmony_ci<ul>
4461cb0ef41Sopenharmony_ci<li><a href="#modifiers">Modifiers</a></li>
4471cb0ef41Sopenharmony_ci<li><a href="#foreground-colors">Foreground colors</a></li>
4481cb0ef41Sopenharmony_ci<li><a href="#background-colors">Background colors</a></li>
4491cb0ef41Sopenharmony_ci</ul>
4501cb0ef41Sopenharmony_ci</li>
4511cb0ef41Sopenharmony_ci<li><a href="#custom-inspection-functions-on-objects">Custom inspection functions on objects</a></li>
4521cb0ef41Sopenharmony_ci<li><a href="#utilinspectcustom"><code>util.inspect.custom</code></a></li>
4531cb0ef41Sopenharmony_ci<li><a href="#utilinspectdefaultoptions"><code>util.inspect.defaultOptions</code></a></li>
4541cb0ef41Sopenharmony_ci</ul>
4551cb0ef41Sopenharmony_ci</li>
4561cb0ef41Sopenharmony_ci<li><a href="#utilisdeepstrictequalval1-val2"><code>util.isDeepStrictEqual(val1, val2)</code></a></li>
4571cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#class-utilmimetype">Class: <code>util.MIMEType</code></a></span>
4581cb0ef41Sopenharmony_ci<ul>
4591cb0ef41Sopenharmony_ci<li><a href="#constructor-new-mimetypeinput">Constructor: <code>new MIMEType(input)</code></a></li>
4601cb0ef41Sopenharmony_ci<li><a href="#mimetype"><code>mime.type</code></a></li>
4611cb0ef41Sopenharmony_ci<li><a href="#mimesubtype"><code>mime.subtype</code></a></li>
4621cb0ef41Sopenharmony_ci<li><a href="#mimeessence"><code>mime.essence</code></a></li>
4631cb0ef41Sopenharmony_ci<li><a href="#mimeparams"><code>mime.params</code></a></li>
4641cb0ef41Sopenharmony_ci<li><a href="#mimetostring"><code>mime.toString()</code></a></li>
4651cb0ef41Sopenharmony_ci<li><a href="#mimetojson"><code>mime.toJSON()</code></a></li>
4661cb0ef41Sopenharmony_ci</ul>
4671cb0ef41Sopenharmony_ci</li>
4681cb0ef41Sopenharmony_ci<li><a href="#class-utilmimeparams">Class: <code>util.MIMEParams</code></a>
4691cb0ef41Sopenharmony_ci<ul>
4701cb0ef41Sopenharmony_ci<li><a href="#constructor-new-mimeparams">Constructor: <code>new MIMEParams()</code></a></li>
4711cb0ef41Sopenharmony_ci<li><a href="#mimeparamsdeletename"><code>mimeParams.delete(name)</code></a></li>
4721cb0ef41Sopenharmony_ci<li><a href="#mimeparamsentries"><code>mimeParams.entries()</code></a></li>
4731cb0ef41Sopenharmony_ci<li><a href="#mimeparamsgetname"><code>mimeParams.get(name)</code></a></li>
4741cb0ef41Sopenharmony_ci<li><a href="#mimeparamshasname"><code>mimeParams.has(name)</code></a></li>
4751cb0ef41Sopenharmony_ci<li><a href="#mimeparamskeys"><code>mimeParams.keys()</code></a></li>
4761cb0ef41Sopenharmony_ci<li><a href="#mimeparamssetname-value"><code>mimeParams.set(name, value)</code></a></li>
4771cb0ef41Sopenharmony_ci<li><a href="#mimeparamsvalues"><code>mimeParams.values()</code></a></li>
4781cb0ef41Sopenharmony_ci<li><a href="#mimeparamsiterator"><code>mimeParams[@@iterator]()</code></a></li>
4791cb0ef41Sopenharmony_ci</ul>
4801cb0ef41Sopenharmony_ci</li>
4811cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#utilparseargsconfig"><code>util.parseArgs([config])</code></a></span>
4821cb0ef41Sopenharmony_ci<ul>
4831cb0ef41Sopenharmony_ci<li><a href="#parseargs-tokens"><code>parseArgs</code> <code>tokens</code></a></li>
4841cb0ef41Sopenharmony_ci</ul>
4851cb0ef41Sopenharmony_ci</li>
4861cb0ef41Sopenharmony_ci<li><a href="#utilpromisifyoriginal"><code>util.promisify(original)</code></a>
4871cb0ef41Sopenharmony_ci<ul>
4881cb0ef41Sopenharmony_ci<li><a href="#custom-promisified-functions">Custom promisified functions</a></li>
4891cb0ef41Sopenharmony_ci<li><a href="#utilpromisifycustom"><code>util.promisify.custom</code></a></li>
4901cb0ef41Sopenharmony_ci</ul>
4911cb0ef41Sopenharmony_ci</li>
4921cb0ef41Sopenharmony_ci<li><a href="#utilstripvtcontrolcharactersstr"><code>util.stripVTControlCharacters(str)</code></a></li>
4931cb0ef41Sopenharmony_ci<li><a href="#class-utiltextdecoder">Class: <code>util.TextDecoder</code></a>
4941cb0ef41Sopenharmony_ci<ul>
4951cb0ef41Sopenharmony_ci<li><a href="#whatwg-supported-encodings">WHATWG supported encodings</a>
4961cb0ef41Sopenharmony_ci<ul>
4971cb0ef41Sopenharmony_ci<li><a href="#encodings-supported-by-default-with-full-icu-data">Encodings supported by default (with full ICU data)</a></li>
4981cb0ef41Sopenharmony_ci<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>
4991cb0ef41Sopenharmony_ci<li><a href="#encodings-supported-when-icu-is-disabled">Encodings supported when ICU is disabled</a></li>
5001cb0ef41Sopenharmony_ci</ul>
5011cb0ef41Sopenharmony_ci</li>
5021cb0ef41Sopenharmony_ci<li><a href="#new-textdecoderencoding-options"><code>new TextDecoder([encoding[, options]])</code></a></li>
5031cb0ef41Sopenharmony_ci<li><a href="#textdecoderdecodeinput-options"><code>textDecoder.decode([input[, options]])</code></a></li>
5041cb0ef41Sopenharmony_ci<li><a href="#textdecoderencoding"><code>textDecoder.encoding</code></a></li>
5051cb0ef41Sopenharmony_ci<li><a href="#textdecoderfatal"><code>textDecoder.fatal</code></a></li>
5061cb0ef41Sopenharmony_ci<li><a href="#textdecoderignorebom"><code>textDecoder.ignoreBOM</code></a></li>
5071cb0ef41Sopenharmony_ci</ul>
5081cb0ef41Sopenharmony_ci</li>
5091cb0ef41Sopenharmony_ci<li><a href="#class-utiltextencoder">Class: <code>util.TextEncoder</code></a>
5101cb0ef41Sopenharmony_ci<ul>
5111cb0ef41Sopenharmony_ci<li><a href="#textencoderencodeinput"><code>textEncoder.encode([input])</code></a></li>
5121cb0ef41Sopenharmony_ci<li><a href="#textencoderencodeintosrc-dest"><code>textEncoder.encodeInto(src, dest)</code></a></li>
5131cb0ef41Sopenharmony_ci<li><a href="#textencoderencoding"><code>textEncoder.encoding</code></a></li>
5141cb0ef41Sopenharmony_ci</ul>
5151cb0ef41Sopenharmony_ci</li>
5161cb0ef41Sopenharmony_ci<li><a href="#utiltousvstringstring"><code>util.toUSVString(string)</code></a></li>
5171cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#utiltransferableabortcontroller"><code>util.transferableAbortController()</code></a></span></li>
5181cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#utiltransferableabortsignalsignal"><code>util.transferableAbortSignal(signal)</code></a></span></li>
5191cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#utilabortedsignal-resource"><code>util.aborted(signal, resource)</code></a></span></li>
5201cb0ef41Sopenharmony_ci<li><a href="#utiltypes"><code>util.types</code></a>
5211cb0ef41Sopenharmony_ci<ul>
5221cb0ef41Sopenharmony_ci<li><a href="#utiltypesisanyarraybuffervalue"><code>util.types.isAnyArrayBuffer(value)</code></a></li>
5231cb0ef41Sopenharmony_ci<li><a href="#utiltypesisarraybufferviewvalue"><code>util.types.isArrayBufferView(value)</code></a></li>
5241cb0ef41Sopenharmony_ci<li><a href="#utiltypesisargumentsobjectvalue"><code>util.types.isArgumentsObject(value)</code></a></li>
5251cb0ef41Sopenharmony_ci<li><a href="#utiltypesisarraybuffervalue"><code>util.types.isArrayBuffer(value)</code></a></li>
5261cb0ef41Sopenharmony_ci<li><a href="#utiltypesisasyncfunctionvalue"><code>util.types.isAsyncFunction(value)</code></a></li>
5271cb0ef41Sopenharmony_ci<li><a href="#utiltypesisbigint64arrayvalue"><code>util.types.isBigInt64Array(value)</code></a></li>
5281cb0ef41Sopenharmony_ci<li><a href="#utiltypesisbiguint64arrayvalue"><code>util.types.isBigUint64Array(value)</code></a></li>
5291cb0ef41Sopenharmony_ci<li><a href="#utiltypesisbooleanobjectvalue"><code>util.types.isBooleanObject(value)</code></a></li>
5301cb0ef41Sopenharmony_ci<li><a href="#utiltypesisboxedprimitivevalue"><code>util.types.isBoxedPrimitive(value)</code></a></li>
5311cb0ef41Sopenharmony_ci<li><a href="#utiltypesiscryptokeyvalue"><code>util.types.isCryptoKey(value)</code></a></li>
5321cb0ef41Sopenharmony_ci<li><a href="#utiltypesisdataviewvalue"><code>util.types.isDataView(value)</code></a></li>
5331cb0ef41Sopenharmony_ci<li><a href="#utiltypesisdatevalue"><code>util.types.isDate(value)</code></a></li>
5341cb0ef41Sopenharmony_ci<li><a href="#utiltypesisexternalvalue"><code>util.types.isExternal(value)</code></a></li>
5351cb0ef41Sopenharmony_ci<li><a href="#utiltypesisfloat32arrayvalue"><code>util.types.isFloat32Array(value)</code></a></li>
5361cb0ef41Sopenharmony_ci<li><a href="#utiltypesisfloat64arrayvalue"><code>util.types.isFloat64Array(value)</code></a></li>
5371cb0ef41Sopenharmony_ci<li><a href="#utiltypesisgeneratorfunctionvalue"><code>util.types.isGeneratorFunction(value)</code></a></li>
5381cb0ef41Sopenharmony_ci<li><a href="#utiltypesisgeneratorobjectvalue"><code>util.types.isGeneratorObject(value)</code></a></li>
5391cb0ef41Sopenharmony_ci<li><a href="#utiltypesisint8arrayvalue"><code>util.types.isInt8Array(value)</code></a></li>
5401cb0ef41Sopenharmony_ci<li><a href="#utiltypesisint16arrayvalue"><code>util.types.isInt16Array(value)</code></a></li>
5411cb0ef41Sopenharmony_ci<li><a href="#utiltypesisint32arrayvalue"><code>util.types.isInt32Array(value)</code></a></li>
5421cb0ef41Sopenharmony_ci<li><a href="#utiltypesiskeyobjectvalue"><code>util.types.isKeyObject(value)</code></a></li>
5431cb0ef41Sopenharmony_ci<li><a href="#utiltypesismapvalue"><code>util.types.isMap(value)</code></a></li>
5441cb0ef41Sopenharmony_ci<li><a href="#utiltypesismapiteratorvalue"><code>util.types.isMapIterator(value)</code></a></li>
5451cb0ef41Sopenharmony_ci<li><a href="#utiltypesismodulenamespaceobjectvalue"><code>util.types.isModuleNamespaceObject(value)</code></a></li>
5461cb0ef41Sopenharmony_ci<li><a href="#utiltypesisnativeerrorvalue"><code>util.types.isNativeError(value)</code></a></li>
5471cb0ef41Sopenharmony_ci<li><a href="#utiltypesisnumberobjectvalue"><code>util.types.isNumberObject(value)</code></a></li>
5481cb0ef41Sopenharmony_ci<li><a href="#utiltypesispromisevalue"><code>util.types.isPromise(value)</code></a></li>
5491cb0ef41Sopenharmony_ci<li><a href="#utiltypesisproxyvalue"><code>util.types.isProxy(value)</code></a></li>
5501cb0ef41Sopenharmony_ci<li><a href="#utiltypesisregexpvalue"><code>util.types.isRegExp(value)</code></a></li>
5511cb0ef41Sopenharmony_ci<li><a href="#utiltypesissetvalue"><code>util.types.isSet(value)</code></a></li>
5521cb0ef41Sopenharmony_ci<li><a href="#utiltypesissetiteratorvalue"><code>util.types.isSetIterator(value)</code></a></li>
5531cb0ef41Sopenharmony_ci<li><a href="#utiltypesissharedarraybuffervalue"><code>util.types.isSharedArrayBuffer(value)</code></a></li>
5541cb0ef41Sopenharmony_ci<li><a href="#utiltypesisstringobjectvalue"><code>util.types.isStringObject(value)</code></a></li>
5551cb0ef41Sopenharmony_ci<li><a href="#utiltypesissymbolobjectvalue"><code>util.types.isSymbolObject(value)</code></a></li>
5561cb0ef41Sopenharmony_ci<li><a href="#utiltypesistypedarrayvalue"><code>util.types.isTypedArray(value)</code></a></li>
5571cb0ef41Sopenharmony_ci<li><a href="#utiltypesisuint8arrayvalue"><code>util.types.isUint8Array(value)</code></a></li>
5581cb0ef41Sopenharmony_ci<li><a href="#utiltypesisuint8clampedarrayvalue"><code>util.types.isUint8ClampedArray(value)</code></a></li>
5591cb0ef41Sopenharmony_ci<li><a href="#utiltypesisuint16arrayvalue"><code>util.types.isUint16Array(value)</code></a></li>
5601cb0ef41Sopenharmony_ci<li><a href="#utiltypesisuint32arrayvalue"><code>util.types.isUint32Array(value)</code></a></li>
5611cb0ef41Sopenharmony_ci<li><a href="#utiltypesisweakmapvalue"><code>util.types.isWeakMap(value)</code></a></li>
5621cb0ef41Sopenharmony_ci<li><a href="#utiltypesisweaksetvalue"><code>util.types.isWeakSet(value)</code></a></li>
5631cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utiltypesiswebassemblycompiledmodulevalue"><code>util.types.isWebAssemblyCompiledModule(value)</code></a></span></li>
5641cb0ef41Sopenharmony_ci</ul>
5651cb0ef41Sopenharmony_ci</li>
5661cb0ef41Sopenharmony_ci<li><a href="#deprecated-apis">Deprecated APIs</a>
5671cb0ef41Sopenharmony_ci<ul>
5681cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#util_extendtarget-source"><code>util._extend(target, source)</code></a></span></li>
5691cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisarrayobject"><code>util.isArray(object)</code></a></span></li>
5701cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisbooleanobject"><code>util.isBoolean(object)</code></a></span></li>
5711cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisbufferobject"><code>util.isBuffer(object)</code></a></span></li>
5721cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisdateobject"><code>util.isDate(object)</code></a></span></li>
5731cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utiliserrorobject"><code>util.isError(object)</code></a></span></li>
5741cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisfunctionobject"><code>util.isFunction(object)</code></a></span></li>
5751cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisnullobject"><code>util.isNull(object)</code></a></span></li>
5761cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisnullorundefinedobject"><code>util.isNullOrUndefined(object)</code></a></span></li>
5771cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisnumberobject"><code>util.isNumber(object)</code></a></span></li>
5781cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisobjectobject"><code>util.isObject(object)</code></a></span></li>
5791cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisprimitiveobject"><code>util.isPrimitive(object)</code></a></span></li>
5801cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisregexpobject"><code>util.isRegExp(object)</code></a></span></li>
5811cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisstringobject"><code>util.isString(object)</code></a></span></li>
5821cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilissymbolobject"><code>util.isSymbol(object)</code></a></span></li>
5831cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utilisundefinedobject"><code>util.isUndefined(object)</code></a></span></li>
5841cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#utillogstring"><code>util.log(string)</code></a></span></li>
5851cb0ef41Sopenharmony_ci</ul>
5861cb0ef41Sopenharmony_ci</li>
5871cb0ef41Sopenharmony_ci</ul>
5881cb0ef41Sopenharmony_ci</li>
5891cb0ef41Sopenharmony_ci</ul></details>
5901cb0ef41Sopenharmony_ci
5911cb0ef41Sopenharmony_ci      <div id="apicontent">
5921cb0ef41Sopenharmony_ci        <h2>Util<span><a class="mark" href="#util" id="util">#</a></span><a aria-hidden="true" class="legacy" id="util_util"></a></h2>
5931cb0ef41Sopenharmony_ci
5941cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_2"><a href="documentation.html#stability-index">Stability: 2</a> - Stable</div><p></p>
5951cb0ef41Sopenharmony_ci<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v18.20.1/lib/util.js">lib/util.js</a></p>
5961cb0ef41Sopenharmony_ci<p>The <code>node:util</code> module supports the needs of Node.js internal APIs. Many of the
5971cb0ef41Sopenharmony_ciutilities are useful for application and module developers as well. To access
5981cb0ef41Sopenharmony_ciit:</p>
5991cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);</code> <button class="copy-button">copy</button></pre>
6001cb0ef41Sopenharmony_ci<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>
6011cb0ef41Sopenharmony_ci<div class="api_metadata">
6021cb0ef41Sopenharmony_ci<span>Added in: v8.2.0</span>
6031cb0ef41Sopenharmony_ci</div>
6041cb0ef41Sopenharmony_ci<ul>
6051cb0ef41Sopenharmony_ci<li><code>original</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> An <code>async</code> function</li>
6061cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> a callback style function</li>
6071cb0ef41Sopenharmony_ci</ul>
6081cb0ef41Sopenharmony_ci<p>Takes an <code>async</code> function (or a function that returns a <code>Promise</code>) and returns a
6091cb0ef41Sopenharmony_cifunction following the error-first callback style, i.e. taking
6101cb0ef41Sopenharmony_cian <code>(err, value) => ...</code> callback as the last argument. In the callback, the
6111cb0ef41Sopenharmony_cifirst argument will be the rejection reason (or <code>null</code> if the <code>Promise</code>
6121cb0ef41Sopenharmony_ciresolved), and the second argument will be the resolved value.</p>
6131cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
6141cb0ef41Sopenharmony_ci
6151cb0ef41Sopenharmony_ci<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">fn</span>(<span class="hljs-params"></span>) {
6161cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> <span class="hljs-string">'hello world'</span>;
6171cb0ef41Sopenharmony_ci}
6181cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> callbackFunction = util.<span class="hljs-title function_">callbackify</span>(fn);
6191cb0ef41Sopenharmony_ci
6201cb0ef41Sopenharmony_ci<span class="hljs-title function_">callbackFunction</span>(<span class="hljs-function">(<span class="hljs-params">err, ret</span>) =></span> {
6211cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">throw</span> err;
6221cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(ret);
6231cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
6241cb0ef41Sopenharmony_ci<p>Will print:</p>
6251cb0ef41Sopenharmony_ci<pre><code class="language-text">hello world</code> <button class="copy-button">copy</button></pre>
6261cb0ef41Sopenharmony_ci<p>The callback is executed asynchronously, and will have a limited stack trace.
6271cb0ef41Sopenharmony_ciIf the callback throws, the process will emit an <a href="process.html#event-uncaughtexception"><code>'uncaughtException'</code></a>
6281cb0ef41Sopenharmony_cievent, and if not handled will exit.</p>
6291cb0ef41Sopenharmony_ci<p>Since <code>null</code> has a special meaning as the first argument to a callback, if a
6301cb0ef41Sopenharmony_ciwrapped function rejects a <code>Promise</code> with a falsy value as a reason, the value
6311cb0ef41Sopenharmony_ciis wrapped in an <code>Error</code> with the original value stored in a field named
6321cb0ef41Sopenharmony_ci<code>reason</code>.</p>
6331cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">fn</span>(<span class="hljs-params"></span>) {
6341cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(<span class="hljs-literal">null</span>);
6351cb0ef41Sopenharmony_ci}
6361cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> callbackFunction = util.<span class="hljs-title function_">callbackify</span>(fn);
6371cb0ef41Sopenharmony_ci
6381cb0ef41Sopenharmony_ci<span class="hljs-title function_">callbackFunction</span>(<span class="hljs-function">(<span class="hljs-params">err, ret</span>) =></span> {
6391cb0ef41Sopenharmony_ci  <span class="hljs-comment">// When the Promise was rejected with `null` it is wrapped with an Error and</span>
6401cb0ef41Sopenharmony_ci  <span class="hljs-comment">// the original value is stored in `reason`.</span>
6411cb0ef41Sopenharmony_ci  err &#x26;&#x26; <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">hasOwn</span>(err, <span class="hljs-string">'reason'</span>) &#x26;&#x26; err.<span class="hljs-property">reason</span> === <span class="hljs-literal">null</span>;  <span class="hljs-comment">// true</span>
6421cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
6431cb0ef41Sopenharmony_ci</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>
6441cb0ef41Sopenharmony_ci<div class="api_metadata">
6451cb0ef41Sopenharmony_ci<span>Added in: v0.11.3</span>
6461cb0ef41Sopenharmony_ci</div>
6471cb0ef41Sopenharmony_ci<ul>
6481cb0ef41Sopenharmony_ci<li><code>section</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A string identifying the portion of the application for
6491cb0ef41Sopenharmony_ciwhich the <code>debuglog</code> function is being created.</li>
6501cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A callback invoked the first time the logging function
6511cb0ef41Sopenharmony_ciis called with a function argument that is a more optimized logging function.</li>
6521cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The logging function</li>
6531cb0ef41Sopenharmony_ci</ul>
6541cb0ef41Sopenharmony_ci<p>The <code>util.debuglog()</code> method is used to create a function that conditionally
6551cb0ef41Sopenharmony_ciwrites debug messages to <code>stderr</code> based on the existence of the <code>NODE_DEBUG</code>
6561cb0ef41Sopenharmony_cienvironment variable. If the <code>section</code> name appears within the value of that
6571cb0ef41Sopenharmony_cienvironment variable, then the returned function operates similar to
6581cb0ef41Sopenharmony_ci<a href="console.html#consoleerrordata-args"><code>console.error()</code></a>. If not, then the returned function is a no-op.</p>
6591cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
6601cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> debuglog = util.<span class="hljs-title function_">debuglog</span>(<span class="hljs-string">'foo'</span>);
6611cb0ef41Sopenharmony_ci
6621cb0ef41Sopenharmony_ci<span class="hljs-title function_">debuglog</span>(<span class="hljs-string">'hello from foo [%d]'</span>, <span class="hljs-number">123</span>);</code> <button class="copy-button">copy</button></pre>
6631cb0ef41Sopenharmony_ci<p>If this program is run with <code>NODE_DEBUG=foo</code> in the environment, then
6641cb0ef41Sopenharmony_ciit will output something like:</p>
6651cb0ef41Sopenharmony_ci<pre><code class="language-console">FOO 3245: hello from foo [123]</code> <button class="copy-button">copy</button></pre>
6661cb0ef41Sopenharmony_ci<p>where <code>3245</code> is the process id. If it is not run with that
6671cb0ef41Sopenharmony_cienvironment variable set, then it will not print anything.</p>
6681cb0ef41Sopenharmony_ci<p>The <code>section</code> supports wildcard also:</p>
6691cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
6701cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> debuglog = util.<span class="hljs-title function_">debuglog</span>(<span class="hljs-string">'foo-bar'</span>);
6711cb0ef41Sopenharmony_ci
6721cb0ef41Sopenharmony_ci<span class="hljs-title function_">debuglog</span>(<span class="hljs-string">'hi there, it\'s foo-bar [%d]'</span>, <span class="hljs-number">2333</span>);</code> <button class="copy-button">copy</button></pre>
6731cb0ef41Sopenharmony_ci<p>if it is run with <code>NODE_DEBUG=foo*</code> in the environment, then it will output
6741cb0ef41Sopenharmony_cisomething like:</p>
6751cb0ef41Sopenharmony_ci<pre><code class="language-console">FOO-BAR 3257: hi there, it's foo-bar [2333]</code> <button class="copy-button">copy</button></pre>
6761cb0ef41Sopenharmony_ci<p>Multiple comma-separated <code>section</code> names may be specified in the <code>NODE_DEBUG</code>
6771cb0ef41Sopenharmony_cienvironment variable: <code>NODE_DEBUG=fs,net,tls</code>.</p>
6781cb0ef41Sopenharmony_ci<p>The optional <code>callback</code> argument can be used to replace the logging function
6791cb0ef41Sopenharmony_ciwith a different function that doesn't have any initialization or
6801cb0ef41Sopenharmony_ciunnecessary wrapping.</p>
6811cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
6821cb0ef41Sopenharmony_ci<span class="hljs-keyword">let</span> debuglog = util.<span class="hljs-title function_">debuglog</span>(<span class="hljs-string">'internals'</span>, <span class="hljs-function">(<span class="hljs-params">debug</span>) =></span> {
6831cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Replace with a logging function that optimizes out</span>
6841cb0ef41Sopenharmony_ci  <span class="hljs-comment">// testing if the section is enabled</span>
6851cb0ef41Sopenharmony_ci  debuglog = debug;
6861cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
6871cb0ef41Sopenharmony_ci<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>
6881cb0ef41Sopenharmony_ci<div class="api_metadata">
6891cb0ef41Sopenharmony_ci<span>Added in: v14.9.0</span>
6901cb0ef41Sopenharmony_ci</div>
6911cb0ef41Sopenharmony_ci<ul>
6921cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
6931cb0ef41Sopenharmony_ci</ul>
6941cb0ef41Sopenharmony_ci<p>The <code>util.debuglog().enabled</code> getter is used to create a test that can be used
6951cb0ef41Sopenharmony_ciin conditionals based on the existence of the <code>NODE_DEBUG</code> environment variable.
6961cb0ef41Sopenharmony_ciIf the <code>section</code> name appears within the value of that environment variable,
6971cb0ef41Sopenharmony_cithen the returned value will be <code>true</code>. If not, then the returned value will be
6981cb0ef41Sopenharmony_ci<code>false</code>.</p>
6991cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
7001cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> enabled = util.<span class="hljs-title function_">debuglog</span>(<span class="hljs-string">'foo'</span>).<span class="hljs-property">enabled</span>;
7011cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (enabled) {
7021cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'hello from foo [%d]'</span>, <span class="hljs-number">123</span>);
7031cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
7041cb0ef41Sopenharmony_ci<p>If this program is run with <code>NODE_DEBUG=foo</code> in the environment, then it will
7051cb0ef41Sopenharmony_cioutput something like:</p>
7061cb0ef41Sopenharmony_ci<pre><code class="language-console">hello from foo [123]</code> <button class="copy-button">copy</button></pre>
7071cb0ef41Sopenharmony_ci</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>
7081cb0ef41Sopenharmony_ci<div class="api_metadata">
7091cb0ef41Sopenharmony_ci<span>Added in: v14.9.0</span>
7101cb0ef41Sopenharmony_ci</div>
7111cb0ef41Sopenharmony_ci<p>Alias for <code>util.debuglog</code>. Usage allows for readability of that doesn't imply
7121cb0ef41Sopenharmony_cilogging when only using <code>util.debuglog().enabled</code>.</p>
7131cb0ef41Sopenharmony_ci</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>
7141cb0ef41Sopenharmony_ci<div class="api_metadata">
7151cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
7161cb0ef41Sopenharmony_ci<table>
7171cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
7181cb0ef41Sopenharmony_ci<tr><td>v10.0.0</td>
7191cb0ef41Sopenharmony_ci<td><p>Deprecation warnings are only emitted once for each code.</p></td></tr>
7201cb0ef41Sopenharmony_ci<tr><td>v0.8.0</td>
7211cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.8.0</span></p></td></tr>
7221cb0ef41Sopenharmony_ci</tbody></table>
7231cb0ef41Sopenharmony_ci</details>
7241cb0ef41Sopenharmony_ci</div>
7251cb0ef41Sopenharmony_ci<ul>
7261cb0ef41Sopenharmony_ci<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The function that is being deprecated.</li>
7271cb0ef41Sopenharmony_ci<li><code>msg</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A warning message to display when the deprecated function is
7281cb0ef41Sopenharmony_ciinvoked.</li>
7291cb0ef41Sopenharmony_ci<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A deprecation code. See the <a href="deprecations.html#list-of-deprecated-apis">list of deprecated APIs</a> for a
7301cb0ef41Sopenharmony_cilist of codes.</li>
7311cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The deprecated function wrapped to emit a warning.</li>
7321cb0ef41Sopenharmony_ci</ul>
7331cb0ef41Sopenharmony_ci<p>The <code>util.deprecate()</code> method wraps <code>fn</code> (which may be a function or class) in
7341cb0ef41Sopenharmony_cisuch a way that it is marked as deprecated.</p>
7351cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
7361cb0ef41Sopenharmony_ci
7371cb0ef41Sopenharmony_ci<span class="hljs-built_in">exports</span>.<span class="hljs-property">obsoleteFunction</span> = util.<span class="hljs-title function_">deprecate</span>(<span class="hljs-function">() =></span> {
7381cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Do something here.</span>
7391cb0ef41Sopenharmony_ci}, <span class="hljs-string">'obsoleteFunction() is deprecated. Use newShinyFunction() instead.'</span>);</code> <button class="copy-button">copy</button></pre>
7401cb0ef41Sopenharmony_ci<p>When called, <code>util.deprecate()</code> will return a function that will emit a
7411cb0ef41Sopenharmony_ci<code>DeprecationWarning</code> using the <a href="process.html#event-warning"><code>'warning'</code></a> event. The warning will
7421cb0ef41Sopenharmony_cibe emitted and printed to <code>stderr</code> the first time the returned function is
7431cb0ef41Sopenharmony_cicalled. After the warning is emitted, the wrapped function is called without
7441cb0ef41Sopenharmony_ciemitting a warning.</p>
7451cb0ef41Sopenharmony_ci<p>If the same optional <code>code</code> is supplied in multiple calls to <code>util.deprecate()</code>,
7461cb0ef41Sopenharmony_cithe warning will be emitted only once for that <code>code</code>.</p>
7471cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
7481cb0ef41Sopenharmony_ci
7491cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> fn1 = util.<span class="hljs-title function_">deprecate</span>(someFunction, someMessage, <span class="hljs-string">'DEP0001'</span>);
7501cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> fn2 = util.<span class="hljs-title function_">deprecate</span>(someOtherFunction, someOtherMessage, <span class="hljs-string">'DEP0001'</span>);
7511cb0ef41Sopenharmony_ci<span class="hljs-title function_">fn1</span>(); <span class="hljs-comment">// Emits a deprecation warning with code DEP0001</span>
7521cb0ef41Sopenharmony_ci<span class="hljs-title function_">fn2</span>(); <span class="hljs-comment">// Does not emit a deprecation warning because it has the same code</span></code> <button class="copy-button">copy</button></pre>
7531cb0ef41Sopenharmony_ci<p>If either the <code>--no-deprecation</code> or <code>--no-warnings</code> command-line flags are
7541cb0ef41Sopenharmony_ciused, or if the <code>process.noDeprecation</code> property is set to <code>true</code> <em>prior</em> to
7551cb0ef41Sopenharmony_cithe first deprecation warning, the <code>util.deprecate()</code> method does nothing.</p>
7561cb0ef41Sopenharmony_ci<p>If the <code>--trace-deprecation</code> or <code>--trace-warnings</code> command-line flags are set,
7571cb0ef41Sopenharmony_cior the <code>process.traceDeprecation</code> property is set to <code>true</code>, a warning and a
7581cb0ef41Sopenharmony_cistack trace are printed to <code>stderr</code> the first time the deprecated function is
7591cb0ef41Sopenharmony_cicalled.</p>
7601cb0ef41Sopenharmony_ci<p>If the <code>--throw-deprecation</code> command-line flag is set, or the
7611cb0ef41Sopenharmony_ci<code>process.throwDeprecation</code> property is set to <code>true</code>, then an exception will be
7621cb0ef41Sopenharmony_cithrown when the deprecated function is called.</p>
7631cb0ef41Sopenharmony_ci<p>The <code>--throw-deprecation</code> command-line flag and <code>process.throwDeprecation</code>
7641cb0ef41Sopenharmony_ciproperty take precedence over <code>--trace-deprecation</code> and
7651cb0ef41Sopenharmony_ci<code>process.traceDeprecation</code>.</p>
7661cb0ef41Sopenharmony_ci</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>
7671cb0ef41Sopenharmony_ci<div class="api_metadata">
7681cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
7691cb0ef41Sopenharmony_ci<table>
7701cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
7711cb0ef41Sopenharmony_ci<tr><td>v12.11.0</td>
7721cb0ef41Sopenharmony_ci<td><p>The <code>%c</code> specifier is ignored now.</p></td></tr>
7731cb0ef41Sopenharmony_ci<tr><td>v12.0.0</td>
7741cb0ef41Sopenharmony_ci<td><p>The <code>format</code> argument is now only taken as such if it actually contains format specifiers.</p></td></tr>
7751cb0ef41Sopenharmony_ci<tr><td>v12.0.0</td>
7761cb0ef41Sopenharmony_ci<td><p>If the <code>format</code> argument is not a format string, the output string's formatting is no longer dependent on the type of the first argument. This change removes previously present quotes from strings that were being output when the first argument was not a string.</p></td></tr>
7771cb0ef41Sopenharmony_ci<tr><td>v11.4.0</td>
7781cb0ef41Sopenharmony_ci<td><p>The <code>%d</code>, <code>%f</code>, and <code>%i</code> specifiers now support Symbols properly.</p></td></tr>
7791cb0ef41Sopenharmony_ci<tr><td>v11.4.0</td>
7801cb0ef41Sopenharmony_ci<td><p>The <code>%o</code> specifier's <code>depth</code> has default depth of 4 again.</p></td></tr>
7811cb0ef41Sopenharmony_ci<tr><td>v11.0.0</td>
7821cb0ef41Sopenharmony_ci<td><p>The <code>%o</code> specifier's <code>depth</code> option will now fall back to the default depth.</p></td></tr>
7831cb0ef41Sopenharmony_ci<tr><td>v10.12.0</td>
7841cb0ef41Sopenharmony_ci<td><p>The <code>%d</code> and <code>%i</code> specifiers now support BigInt.</p></td></tr>
7851cb0ef41Sopenharmony_ci<tr><td>v8.4.0</td>
7861cb0ef41Sopenharmony_ci<td><p>The <code>%o</code> and <code>%O</code> specifiers are supported now.</p></td></tr>
7871cb0ef41Sopenharmony_ci<tr><td>v0.5.3</td>
7881cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.5.3</span></p></td></tr>
7891cb0ef41Sopenharmony_ci</tbody></table>
7901cb0ef41Sopenharmony_ci</details>
7911cb0ef41Sopenharmony_ci</div>
7921cb0ef41Sopenharmony_ci<ul>
7931cb0ef41Sopenharmony_ci<li><code>format</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A <code>printf</code>-like format string.</li>
7941cb0ef41Sopenharmony_ci</ul>
7951cb0ef41Sopenharmony_ci<p>The <code>util.format()</code> method returns a formatted string using the first argument
7961cb0ef41Sopenharmony_cias a <code>printf</code>-like format string which can contain zero or more format
7971cb0ef41Sopenharmony_cispecifiers. Each specifier is replaced with the converted value from the
7981cb0ef41Sopenharmony_cicorresponding argument. Supported specifiers are:</p>
7991cb0ef41Sopenharmony_ci<ul>
8001cb0ef41Sopenharmony_ci<li><code>%s</code>: <code>String</code> will be used to convert all values except <code>BigInt</code>, <code>Object</code>
8011cb0ef41Sopenharmony_ciand <code>-0</code>. <code>BigInt</code> values will be represented with an <code>n</code> and Objects that
8021cb0ef41Sopenharmony_cihave no user defined <code>toString</code> function are inspected using <code>util.inspect()</code>
8031cb0ef41Sopenharmony_ciwith options <code>{ depth: 0, colors: false, compact: 3 }</code>.</li>
8041cb0ef41Sopenharmony_ci<li><code>%d</code>: <code>Number</code> will be used to convert all values except <code>BigInt</code> and
8051cb0ef41Sopenharmony_ci<code>Symbol</code>.</li>
8061cb0ef41Sopenharmony_ci<li><code>%i</code>: <code>parseInt(value, 10)</code> is used for all values except <code>BigInt</code> and
8071cb0ef41Sopenharmony_ci<code>Symbol</code>.</li>
8081cb0ef41Sopenharmony_ci<li><code>%f</code>: <code>parseFloat(value)</code> is used for all values expect <code>Symbol</code>.</li>
8091cb0ef41Sopenharmony_ci<li><code>%j</code>: JSON. Replaced with the string <code>'[Circular]'</code> if the argument contains
8101cb0ef41Sopenharmony_cicircular references.</li>
8111cb0ef41Sopenharmony_ci<li><code>%o</code>: <code>Object</code>. A string representation of an object with generic JavaScript
8121cb0ef41Sopenharmony_ciobject formatting. Similar to <code>util.inspect()</code> with options
8131cb0ef41Sopenharmony_ci<code>{ showHidden: true, showProxy: true }</code>. This will show the full object
8141cb0ef41Sopenharmony_ciincluding non-enumerable properties and proxies.</li>
8151cb0ef41Sopenharmony_ci<li><code>%O</code>: <code>Object</code>. A string representation of an object with generic JavaScript
8161cb0ef41Sopenharmony_ciobject formatting. Similar to <code>util.inspect()</code> without options. This will show
8171cb0ef41Sopenharmony_cithe full object not including non-enumerable properties and proxies.</li>
8181cb0ef41Sopenharmony_ci<li><code>%c</code>: <code>CSS</code>. This specifier is ignored and will skip any CSS passed in.</li>
8191cb0ef41Sopenharmony_ci<li><code>%%</code>: single percent sign (<code>'%'</code>). This does not consume an argument.</li>
8201cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The formatted string</li>
8211cb0ef41Sopenharmony_ci</ul>
8221cb0ef41Sopenharmony_ci<p>If a specifier does not have a corresponding argument, it is not replaced:</p>
8231cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-title function_">format</span>(<span class="hljs-string">'%s:%s'</span>, <span class="hljs-string">'foo'</span>);
8241cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: 'foo:%s'</span></code> <button class="copy-button">copy</button></pre>
8251cb0ef41Sopenharmony_ci<p>Values that are not part of the format string are formatted using
8261cb0ef41Sopenharmony_ci<code>util.inspect()</code> if their type is not <code>string</code>.</p>
8271cb0ef41Sopenharmony_ci<p>If there are more arguments passed to the <code>util.format()</code> method than the
8281cb0ef41Sopenharmony_cinumber of specifiers, the extra arguments are concatenated to the returned
8291cb0ef41Sopenharmony_cistring, separated by spaces:</p>
8301cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-title function_">format</span>(<span class="hljs-string">'%s:%s'</span>, <span class="hljs-string">'foo'</span>, <span class="hljs-string">'bar'</span>, <span class="hljs-string">'baz'</span>);
8311cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: 'foo:bar baz'</span></code> <button class="copy-button">copy</button></pre>
8321cb0ef41Sopenharmony_ci<p>If the first argument does not contain a valid format specifier, <code>util.format()</code>
8331cb0ef41Sopenharmony_cireturns a string that is the concatenation of all arguments separated by spaces:</p>
8341cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-title function_">format</span>(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>);
8351cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: '1 2 3'</span></code> <button class="copy-button">copy</button></pre>
8361cb0ef41Sopenharmony_ci<p>If only one argument is passed to <code>util.format()</code>, it is returned as it is
8371cb0ef41Sopenharmony_ciwithout any formatting:</p>
8381cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-title function_">format</span>(<span class="hljs-string">'%% %s'</span>);
8391cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: '%% %s'</span></code> <button class="copy-button">copy</button></pre>
8401cb0ef41Sopenharmony_ci<p><code>util.format()</code> is a synchronous method that is intended as a debugging tool.
8411cb0ef41Sopenharmony_ciSome input values can have a significant performance overhead that can block the
8421cb0ef41Sopenharmony_cievent loop. Use this function with care and never in a hot code path.</p>
8431cb0ef41Sopenharmony_ci</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>
8441cb0ef41Sopenharmony_ci<div class="api_metadata">
8451cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
8461cb0ef41Sopenharmony_ci</div>
8471cb0ef41Sopenharmony_ci<ul>
8481cb0ef41Sopenharmony_ci<li><code>inspectOptions</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
8491cb0ef41Sopenharmony_ci<li><code>format</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
8501cb0ef41Sopenharmony_ci</ul>
8511cb0ef41Sopenharmony_ci<p>This function is identical to <a href="#utilformatformat-args"><code>util.format()</code></a>, except in that it takes
8521cb0ef41Sopenharmony_cian <code>inspectOptions</code> argument which specifies options that are passed along to
8531cb0ef41Sopenharmony_ci<a href="#utilinspectobject-options"><code>util.inspect()</code></a>.</p>
8541cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-title function_">formatWithOptions</span>({ <span class="hljs-attr">colors</span>: <span class="hljs-literal">true</span> }, <span class="hljs-string">'See object %O'</span>, { <span class="hljs-attr">foo</span>: <span class="hljs-number">42</span> });
8551cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns 'See object { foo: 42 }', where `42` is colored as a number</span>
8561cb0ef41Sopenharmony_ci<span class="hljs-comment">// when printed to a terminal.</span></code> <button class="copy-button">copy</button></pre>
8571cb0ef41Sopenharmony_ci</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>
8581cb0ef41Sopenharmony_ci<div class="api_metadata">
8591cb0ef41Sopenharmony_ci<span>Added in: v9.7.0</span>
8601cb0ef41Sopenharmony_ci</div>
8611cb0ef41Sopenharmony_ci<ul>
8621cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
8631cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
8641cb0ef41Sopenharmony_ci</ul>
8651cb0ef41Sopenharmony_ci<p>Returns the string name for a numeric error code that comes from a Node.js API.
8661cb0ef41Sopenharmony_ciThe mapping between error codes and error names is platform-dependent.
8671cb0ef41Sopenharmony_ciSee <a href="errors.html#common-system-errors">Common System Errors</a> for the names of common errors.</p>
8681cb0ef41Sopenharmony_ci<pre><code class="language-js">fs.<span class="hljs-title function_">access</span>(<span class="hljs-string">'file/that/does/not/exist'</span>, <span class="hljs-function">(<span class="hljs-params">err</span>) =></span> {
8691cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> name = util.<span class="hljs-title function_">getSystemErrorName</span>(err.<span class="hljs-property">errno</span>);
8701cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(name);  <span class="hljs-comment">// ENOENT</span>
8711cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
8721cb0ef41Sopenharmony_ci</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>
8731cb0ef41Sopenharmony_ci<div class="api_metadata">
8741cb0ef41Sopenharmony_ci<span>Added in: v16.0.0, v14.17.0</span>
8751cb0ef41Sopenharmony_ci</div>
8761cb0ef41Sopenharmony_ci<ul>
8771cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map" class="type">&#x3C;Map></a></li>
8781cb0ef41Sopenharmony_ci</ul>
8791cb0ef41Sopenharmony_ci<p>Returns a Map of all system error codes available from the Node.js API.
8801cb0ef41Sopenharmony_ciThe mapping between error codes and error names is platform-dependent.
8811cb0ef41Sopenharmony_ciSee <a href="errors.html#common-system-errors">Common System Errors</a> for the names of common errors.</p>
8821cb0ef41Sopenharmony_ci<pre><code class="language-js">fs.<span class="hljs-title function_">access</span>(<span class="hljs-string">'file/that/does/not/exist'</span>, <span class="hljs-function">(<span class="hljs-params">err</span>) =></span> {
8831cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> errorMap = util.<span class="hljs-title function_">getSystemErrorMap</span>();
8841cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> name = errorMap.<span class="hljs-title function_">get</span>(err.<span class="hljs-property">errno</span>);
8851cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(name);  <span class="hljs-comment">// ENOENT</span>
8861cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
8871cb0ef41Sopenharmony_ci</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>
8881cb0ef41Sopenharmony_ci<div class="api_metadata">
8891cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
8901cb0ef41Sopenharmony_ci<table>
8911cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
8921cb0ef41Sopenharmony_ci<tr><td>v5.0.0</td>
8931cb0ef41Sopenharmony_ci<td><p>The <code>constructor</code> parameter can refer to an ES6 class now.</p></td></tr>
8941cb0ef41Sopenharmony_ci<tr><td>v0.3.0</td>
8951cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.3.0</span></p></td></tr>
8961cb0ef41Sopenharmony_ci</tbody></table>
8971cb0ef41Sopenharmony_ci</details>
8981cb0ef41Sopenharmony_ci</div>
8991cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_3"><a href="documentation.html#stability-index">Stability: 3</a> - Legacy: Use ES2015 class syntax and <code>extends</code> keyword instead.</div><p></p>
9001cb0ef41Sopenharmony_ci<ul>
9011cb0ef41Sopenharmony_ci<li><code>constructor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
9021cb0ef41Sopenharmony_ci<li><code>superConstructor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
9031cb0ef41Sopenharmony_ci</ul>
9041cb0ef41Sopenharmony_ci<p>Usage of <code>util.inherits()</code> is discouraged. Please use the ES6 <code>class</code> and
9051cb0ef41Sopenharmony_ci<code>extends</code> keywords to get language level inheritance support. Also note
9061cb0ef41Sopenharmony_cithat the two styles are <a href="https://github.com/nodejs/node/issues/4179">semantically incompatible</a>.</p>
9071cb0ef41Sopenharmony_ci<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
9081cb0ef41Sopenharmony_ciprototype of <code>constructor</code> will be set to a new object created from
9091cb0ef41Sopenharmony_ci<code>superConstructor</code>.</p>
9101cb0ef41Sopenharmony_ci<p>This mainly adds some input validation on top of
9111cb0ef41Sopenharmony_ci<code>Object.setPrototypeOf(constructor.prototype, superConstructor.prototype)</code>.
9121cb0ef41Sopenharmony_ciAs an additional convenience, <code>superConstructor</code> will be accessible
9131cb0ef41Sopenharmony_cithrough the <code>constructor.super_</code> property.</p>
9141cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
9151cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> <span class="hljs-title class_">EventEmitter</span> = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:events'</span>);
9161cb0ef41Sopenharmony_ci
9171cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">MyStream</span>(<span class="hljs-params"></span>) {
9181cb0ef41Sopenharmony_ci  <span class="hljs-title class_">EventEmitter</span>.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>);
9191cb0ef41Sopenharmony_ci}
9201cb0ef41Sopenharmony_ci
9211cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">inherits</span>(<span class="hljs-title class_">MyStream</span>, <span class="hljs-title class_">EventEmitter</span>);
9221cb0ef41Sopenharmony_ci
9231cb0ef41Sopenharmony_ci<span class="hljs-title class_">MyStream</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>.<span class="hljs-property">write</span> = <span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>) {
9241cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">emit</span>(<span class="hljs-string">'data'</span>, data);
9251cb0ef41Sopenharmony_ci};
9261cb0ef41Sopenharmony_ci
9271cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyStream</span>();
9281cb0ef41Sopenharmony_ci
9291cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(stream <span class="hljs-keyword">instanceof</span> <span class="hljs-title class_">EventEmitter</span>); <span class="hljs-comment">// true</span>
9301cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">MyStream</span>.<span class="hljs-property">super_</span> === <span class="hljs-title class_">EventEmitter</span>); <span class="hljs-comment">// true</span>
9311cb0ef41Sopenharmony_ci
9321cb0ef41Sopenharmony_cistream.<span class="hljs-title function_">on</span>(<span class="hljs-string">'data'</span>, <span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
9331cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Received data: "<span class="hljs-subst">${data}</span>"`</span>);
9341cb0ef41Sopenharmony_ci});
9351cb0ef41Sopenharmony_cistream.<span class="hljs-title function_">write</span>(<span class="hljs-string">'It works!'</span>); <span class="hljs-comment">// Received data: "It works!"</span></code> <button class="copy-button">copy</button></pre>
9361cb0ef41Sopenharmony_ci<p>ES6 example using <code>class</code> and <code>extends</code>:</p>
9371cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> <span class="hljs-title class_">EventEmitter</span> = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:events'</span>);
9381cb0ef41Sopenharmony_ci
9391cb0ef41Sopenharmony_ci<span class="hljs-keyword">class</span> <span class="hljs-title class_">MyStream</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_ inherited__">EventEmitter</span> {
9401cb0ef41Sopenharmony_ci  <span class="hljs-title function_">write</span>(<span class="hljs-params">data</span>) {
9411cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">emit</span>(<span class="hljs-string">'data'</span>, data);
9421cb0ef41Sopenharmony_ci  }
9431cb0ef41Sopenharmony_ci}
9441cb0ef41Sopenharmony_ci
9451cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyStream</span>();
9461cb0ef41Sopenharmony_ci
9471cb0ef41Sopenharmony_cistream.<span class="hljs-title function_">on</span>(<span class="hljs-string">'data'</span>, <span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
9481cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Received data: "<span class="hljs-subst">${data}</span>"`</span>);
9491cb0ef41Sopenharmony_ci});
9501cb0ef41Sopenharmony_cistream.<span class="hljs-title function_">write</span>(<span class="hljs-string">'With ES6'</span>);</code> <button class="copy-button">copy</button></pre>
9511cb0ef41Sopenharmony_ci</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>
9521cb0ef41Sopenharmony_ci</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>
9531cb0ef41Sopenharmony_ci<div class="api_metadata">
9541cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
9551cb0ef41Sopenharmony_ci<table>
9561cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
9571cb0ef41Sopenharmony_ci<tr><td>v17.3.0, v16.14.0</td>
9581cb0ef41Sopenharmony_ci<td><p>The <code>numericSeparator</code> option is supported now.</p></td></tr>
9591cb0ef41Sopenharmony_ci<tr><td>v13.0.0</td>
9601cb0ef41Sopenharmony_ci<td><p>Circular references now include a marker to the reference.</p></td></tr>
9611cb0ef41Sopenharmony_ci<tr><td>v14.6.0, v12.19.0</td>
9621cb0ef41Sopenharmony_ci<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>
9631cb0ef41Sopenharmony_ci<tr><td>v13.13.0, v12.17.0</td>
9641cb0ef41Sopenharmony_ci<td><p>The <code>maxStringLength</code> option is supported now.</p></td></tr>
9651cb0ef41Sopenharmony_ci<tr><td>v13.5.0, v12.16.0</td>
9661cb0ef41Sopenharmony_ci<td><p>User defined prototype properties are inspected in case <code>showHidden</code> is <code>true</code>.</p></td></tr>
9671cb0ef41Sopenharmony_ci<tr><td>v12.0.0</td>
9681cb0ef41Sopenharmony_ci<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>
9691cb0ef41Sopenharmony_ci<tr><td>v12.0.0</td>
9701cb0ef41Sopenharmony_ci<td><p>Internal properties no longer appear in the context argument of a custom inspection function.</p></td></tr>
9711cb0ef41Sopenharmony_ci<tr><td>v11.11.0</td>
9721cb0ef41Sopenharmony_ci<td><p>The <code>compact</code> option accepts numbers for a new output mode.</p></td></tr>
9731cb0ef41Sopenharmony_ci<tr><td>v11.7.0</td>
9741cb0ef41Sopenharmony_ci<td><p>ArrayBuffers now also show their binary contents.</p></td></tr>
9751cb0ef41Sopenharmony_ci<tr><td>v11.5.0</td>
9761cb0ef41Sopenharmony_ci<td><p>The <code>getters</code> option is supported now.</p></td></tr>
9771cb0ef41Sopenharmony_ci<tr><td>v11.4.0</td>
9781cb0ef41Sopenharmony_ci<td><p>The <code>depth</code> default changed back to <code>2</code>.</p></td></tr>
9791cb0ef41Sopenharmony_ci<tr><td>v11.0.0</td>
9801cb0ef41Sopenharmony_ci<td><p>The <code>depth</code> default changed to <code>20</code>.</p></td></tr>
9811cb0ef41Sopenharmony_ci<tr><td>v11.0.0</td>
9821cb0ef41Sopenharmony_ci<td><p>The inspection output is now limited to about 128 MiB. Data above that size will not be fully inspected.</p></td></tr>
9831cb0ef41Sopenharmony_ci<tr><td>v10.12.0</td>
9841cb0ef41Sopenharmony_ci<td><p>The <code>sorted</code> option is supported now.</p></td></tr>
9851cb0ef41Sopenharmony_ci<tr><td>v10.6.0</td>
9861cb0ef41Sopenharmony_ci<td><p>Inspecting linked lists and similar objects is now possible up to the maximum call stack size.</p></td></tr>
9871cb0ef41Sopenharmony_ci<tr><td>v10.0.0</td>
9881cb0ef41Sopenharmony_ci<td><p>The <code>WeakMap</code> and <code>WeakSet</code> entries can now be inspected as well.</p></td></tr>
9891cb0ef41Sopenharmony_ci<tr><td>v9.9.0</td>
9901cb0ef41Sopenharmony_ci<td><p>The <code>compact</code> option is supported now.</p></td></tr>
9911cb0ef41Sopenharmony_ci<tr><td>v6.6.0</td>
9921cb0ef41Sopenharmony_ci<td><p>Custom inspection functions can now return <code>this</code>.</p></td></tr>
9931cb0ef41Sopenharmony_ci<tr><td>v6.3.0</td>
9941cb0ef41Sopenharmony_ci<td><p>The <code>breakLength</code> option is supported now.</p></td></tr>
9951cb0ef41Sopenharmony_ci<tr><td>v6.1.0</td>
9961cb0ef41Sopenharmony_ci<td><p>The <code>maxArrayLength</code> option is supported now; in particular, long arrays are truncated by default.</p></td></tr>
9971cb0ef41Sopenharmony_ci<tr><td>v6.1.0</td>
9981cb0ef41Sopenharmony_ci<td><p>The <code>showProxy</code> option is supported now.</p></td></tr>
9991cb0ef41Sopenharmony_ci<tr><td>v0.3.0</td>
10001cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.3.0</span></p></td></tr>
10011cb0ef41Sopenharmony_ci</tbody></table>
10021cb0ef41Sopenharmony_ci</details>
10031cb0ef41Sopenharmony_ci</div>
10041cb0ef41Sopenharmony_ci<ul>
10051cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> Any JavaScript primitive or <code>Object</code>.</li>
10061cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
10071cb0ef41Sopenharmony_ci<ul>
10081cb0ef41Sopenharmony_ci<li><code>showHidden</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> If <code>true</code>, <code>object</code>'s non-enumerable symbols and
10091cb0ef41Sopenharmony_ciproperties 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
10101cb0ef41Sopenharmony_ci<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
10111cb0ef41Sopenharmony_ciproperties (excluding method properties). <strong>Default:</strong> <code>false</code>.</li>
10121cb0ef41Sopenharmony_ci<li><code>depth</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> Specifies the number of times to recurse while formatting
10131cb0ef41Sopenharmony_ci<code>object</code>. This is useful for inspecting large objects. To recurse up to
10141cb0ef41Sopenharmony_cithe maximum call stack size pass <code>Infinity</code> or <code>null</code>.
10151cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>2</code>.</li>
10161cb0ef41Sopenharmony_ci<li><code>colors</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> If <code>true</code>, the output is styled with ANSI color
10171cb0ef41Sopenharmony_cicodes. Colors are customizable. See <a href="#customizing-utilinspect-colors">Customizing <code>util.inspect</code> colors</a>.
10181cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>false</code>.</li>
10191cb0ef41Sopenharmony_ci<li><code>customInspect</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> If <code>false</code>,
10201cb0ef41Sopenharmony_ci<code>[util.inspect.custom](depth, opts, inspect)</code> functions are not invoked.
10211cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>true</code>.</li>
10221cb0ef41Sopenharmony_ci<li><code>showProxy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> If <code>true</code>, <code>Proxy</code> inspection includes
10231cb0ef41Sopenharmony_cithe <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>
10241cb0ef41Sopenharmony_ci<li><code>maxArrayLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> Specifies the maximum number of <code>Array</code>,
10251cb0ef41Sopenharmony_ci<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
10261cb0ef41Sopenharmony_ciformatting. Set to <code>null</code> or <code>Infinity</code> to show all elements. Set to <code>0</code> or
10271cb0ef41Sopenharmony_cinegative to show no elements. <strong>Default:</strong> <code>100</code>.</li>
10281cb0ef41Sopenharmony_ci<li><code>maxStringLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> Specifies the maximum number of characters to
10291cb0ef41Sopenharmony_ciinclude when formatting. Set to <code>null</code> or <code>Infinity</code> to show all elements.
10301cb0ef41Sopenharmony_ciSet to <code>0</code> or negative to show no characters. <strong>Default:</strong> <code>10000</code>.</li>
10311cb0ef41Sopenharmony_ci<li><code>breakLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> The length at which input values are split across
10321cb0ef41Sopenharmony_cimultiple lines. Set to <code>Infinity</code> to format the input as a single line
10331cb0ef41Sopenharmony_ci(in combination with <code>compact</code> set to <code>true</code> or any number >= <code>1</code>).
10341cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>80</code>.</li>
10351cb0ef41Sopenharmony_ci<li><code>compact</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> Setting this to <code>false</code> causes each object key
10361cb0ef41Sopenharmony_cito be displayed on a new line. It will break on new lines in text that is
10371cb0ef41Sopenharmony_cilonger than <code>breakLength</code>. If set to a number, the most <code>n</code> inner elements
10381cb0ef41Sopenharmony_ciare united on a single line as long as all properties fit into
10391cb0ef41Sopenharmony_ci<code>breakLength</code>. Short array elements are also grouped together. For more
10401cb0ef41Sopenharmony_ciinformation, see the example below. <strong>Default:</strong> <code>3</code>.</li>
10411cb0ef41Sopenharmony_ci<li><code>sorted</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> If set to <code>true</code> or a function, all properties
10421cb0ef41Sopenharmony_ciof an object, and <code>Set</code> and <code>Map</code> entries are sorted in the resulting
10431cb0ef41Sopenharmony_cistring. 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,
10441cb0ef41Sopenharmony_ciit 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>
10451cb0ef41Sopenharmony_ci<li><code>getters</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> If set to <code>true</code>, getters are inspected. If set
10461cb0ef41Sopenharmony_cito <code>'get'</code>, only getters without a corresponding setter are inspected. If
10471cb0ef41Sopenharmony_ciset to <code>'set'</code>, only getters with a corresponding setter are inspected.
10481cb0ef41Sopenharmony_ciThis might cause side effects depending on the getter function.
10491cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>false</code>.</li>
10501cb0ef41Sopenharmony_ci<li><code>numericSeparator</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> If set to <code>true</code>, an underscore is used to
10511cb0ef41Sopenharmony_ciseparate every three digits in all bigints and numbers.
10521cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>false</code>.</li>
10531cb0ef41Sopenharmony_ci</ul>
10541cb0ef41Sopenharmony_ci</li>
10551cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The representation of <code>object</code>.</li>
10561cb0ef41Sopenharmony_ci</ul>
10571cb0ef41Sopenharmony_ci<p>The <code>util.inspect()</code> method returns a string representation of <code>object</code> that is
10581cb0ef41Sopenharmony_ciintended for debugging. The output of <code>util.inspect</code> may change at any time
10591cb0ef41Sopenharmony_ciand should not be depended upon programmatically. Additional <code>options</code> may be
10601cb0ef41Sopenharmony_cipassed that alter the result.
10611cb0ef41Sopenharmony_ci<code>util.inspect()</code> will use the constructor's name and/or <code>@@toStringTag</code> to make
10621cb0ef41Sopenharmony_cian identifiable tag for an inspected value.</p>
10631cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">class</span> <span class="hljs-title class_">Foo</span> {
10641cb0ef41Sopenharmony_ci  get [<span class="hljs-title class_">Symbol</span>.<span class="hljs-property">toStringTag</span>]() {
10651cb0ef41Sopenharmony_ci    <span class="hljs-keyword">return</span> <span class="hljs-string">'bar'</span>;
10661cb0ef41Sopenharmony_ci  }
10671cb0ef41Sopenharmony_ci}
10681cb0ef41Sopenharmony_ci
10691cb0ef41Sopenharmony_ci<span class="hljs-keyword">class</span> <span class="hljs-title class_">Bar</span> {}
10701cb0ef41Sopenharmony_ci
10711cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> baz = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">create</span>(<span class="hljs-literal">null</span>, { [<span class="hljs-title class_">Symbol</span>.<span class="hljs-property">toStringTag</span>]: { <span class="hljs-attr">value</span>: <span class="hljs-string">'foo'</span> } });
10721cb0ef41Sopenharmony_ci
10731cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">inspect</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Foo</span>()); <span class="hljs-comment">// 'Foo [bar] {}'</span>
10741cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">inspect</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Bar</span>()); <span class="hljs-comment">// 'Bar {}'</span>
10751cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">inspect</span>(baz);       <span class="hljs-comment">// '[foo] {}'</span></code> <button class="copy-button">copy</button></pre>
10761cb0ef41Sopenharmony_ci<p>Circular references point to their anchor by using a reference index:</p>
10771cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> { inspect } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
10781cb0ef41Sopenharmony_ci
10791cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> obj = {};
10801cb0ef41Sopenharmony_ciobj.<span class="hljs-property">a</span> = [obj];
10811cb0ef41Sopenharmony_ciobj.<span class="hljs-property">b</span> = {};
10821cb0ef41Sopenharmony_ciobj.<span class="hljs-property">b</span>.<span class="hljs-property">inner</span> = obj.<span class="hljs-property">b</span>;
10831cb0ef41Sopenharmony_ciobj.<span class="hljs-property">b</span>.<span class="hljs-property">obj</span> = obj;
10841cb0ef41Sopenharmony_ci
10851cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">inspect</span>(obj));
10861cb0ef41Sopenharmony_ci<span class="hljs-comment">// &#x3C;ref *1> {</span>
10871cb0ef41Sopenharmony_ci<span class="hljs-comment">//   a: [ [Circular *1] ],</span>
10881cb0ef41Sopenharmony_ci<span class="hljs-comment">//   b: &#x3C;ref *2> { inner: [Circular *2], obj: [Circular *1] }</span>
10891cb0ef41Sopenharmony_ci<span class="hljs-comment">// }</span></code> <button class="copy-button">copy</button></pre>
10901cb0ef41Sopenharmony_ci<p>The following example inspects all properties of the <code>util</code> object:</p>
10911cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
10921cb0ef41Sopenharmony_ci
10931cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(util.<span class="hljs-title function_">inspect</span>(util, { <span class="hljs-attr">showHidden</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">depth</span>: <span class="hljs-literal">null</span> }));</code> <button class="copy-button">copy</button></pre>
10941cb0ef41Sopenharmony_ci<p>The following example highlights the effect of the <code>compact</code> option:</p>
10951cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
10961cb0ef41Sopenharmony_ci
10971cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> o = {
10981cb0ef41Sopenharmony_ci  <span class="hljs-attr">a</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, [[
10991cb0ef41Sopenharmony_ci    <span class="hljs-string">'Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit, sed do '</span> +
11001cb0ef41Sopenharmony_ci      <span class="hljs-string">'eiusmod \ntempor incididunt ut labore et dolore magna aliqua.'</span>,
11011cb0ef41Sopenharmony_ci    <span class="hljs-string">'test'</span>,
11021cb0ef41Sopenharmony_ci    <span class="hljs-string">'foo'</span>]], <span class="hljs-number">4</span>],
11031cb0ef41Sopenharmony_ci  <span class="hljs-attr">b</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>([[<span class="hljs-string">'za'</span>, <span class="hljs-number">1</span>], [<span class="hljs-string">'zb'</span>, <span class="hljs-string">'test'</span>]]),
11041cb0ef41Sopenharmony_ci};
11051cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(util.<span class="hljs-title function_">inspect</span>(o, { <span class="hljs-attr">compact</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">depth</span>: <span class="hljs-number">5</span>, <span class="hljs-attr">breakLength</span>: <span class="hljs-number">80</span> }));
11061cb0ef41Sopenharmony_ci
11071cb0ef41Sopenharmony_ci<span class="hljs-comment">// { a:</span>
11081cb0ef41Sopenharmony_ci<span class="hljs-comment">//   [ 1,</span>
11091cb0ef41Sopenharmony_ci<span class="hljs-comment">//     2,</span>
11101cb0ef41Sopenharmony_ci<span class="hljs-comment">//     [ [ 'Lorem ipsum dolor sit amet,\nconsectetur [...]', // A long line</span>
11111cb0ef41Sopenharmony_ci<span class="hljs-comment">//           'test',</span>
11121cb0ef41Sopenharmony_ci<span class="hljs-comment">//           'foo' ] ],</span>
11131cb0ef41Sopenharmony_ci<span class="hljs-comment">//     4 ],</span>
11141cb0ef41Sopenharmony_ci<span class="hljs-comment">//   b: Map(2) { 'za' => 1, 'zb' => 'test' } }</span>
11151cb0ef41Sopenharmony_ci
11161cb0ef41Sopenharmony_ci<span class="hljs-comment">// Setting `compact` to false or an integer creates more reader friendly output.</span>
11171cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(util.<span class="hljs-title function_">inspect</span>(o, { <span class="hljs-attr">compact</span>: <span class="hljs-literal">false</span>, <span class="hljs-attr">depth</span>: <span class="hljs-number">5</span>, <span class="hljs-attr">breakLength</span>: <span class="hljs-number">80</span> }));
11181cb0ef41Sopenharmony_ci
11191cb0ef41Sopenharmony_ci<span class="hljs-comment">// {</span>
11201cb0ef41Sopenharmony_ci<span class="hljs-comment">//   a: [</span>
11211cb0ef41Sopenharmony_ci<span class="hljs-comment">//     1,</span>
11221cb0ef41Sopenharmony_ci<span class="hljs-comment">//     2,</span>
11231cb0ef41Sopenharmony_ci<span class="hljs-comment">//     [</span>
11241cb0ef41Sopenharmony_ci<span class="hljs-comment">//       [</span>
11251cb0ef41Sopenharmony_ci<span class="hljs-comment">//         'Lorem ipsum dolor sit amet,\n' +</span>
11261cb0ef41Sopenharmony_ci<span class="hljs-comment">//           'consectetur adipiscing elit, sed do eiusmod \n' +</span>
11271cb0ef41Sopenharmony_ci<span class="hljs-comment">//           'tempor incididunt ut labore et dolore magna aliqua.',</span>
11281cb0ef41Sopenharmony_ci<span class="hljs-comment">//         'test',</span>
11291cb0ef41Sopenharmony_ci<span class="hljs-comment">//         'foo'</span>
11301cb0ef41Sopenharmony_ci<span class="hljs-comment">//       ]</span>
11311cb0ef41Sopenharmony_ci<span class="hljs-comment">//     ],</span>
11321cb0ef41Sopenharmony_ci<span class="hljs-comment">//     4</span>
11331cb0ef41Sopenharmony_ci<span class="hljs-comment">//   ],</span>
11341cb0ef41Sopenharmony_ci<span class="hljs-comment">//   b: Map(2) {</span>
11351cb0ef41Sopenharmony_ci<span class="hljs-comment">//     'za' => 1,</span>
11361cb0ef41Sopenharmony_ci<span class="hljs-comment">//     'zb' => 'test'</span>
11371cb0ef41Sopenharmony_ci<span class="hljs-comment">//   }</span>
11381cb0ef41Sopenharmony_ci<span class="hljs-comment">// }</span>
11391cb0ef41Sopenharmony_ci
11401cb0ef41Sopenharmony_ci<span class="hljs-comment">// Setting `breakLength` to e.g. 150 will print the "Lorem ipsum" text in a</span>
11411cb0ef41Sopenharmony_ci<span class="hljs-comment">// single line.</span></code> <button class="copy-button">copy</button></pre>
11421cb0ef41Sopenharmony_ci<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
11431cb0ef41Sopenharmony_ciinspected. If there are more entries than <code>maxArrayLength</code>, there is no
11441cb0ef41Sopenharmony_ciguarantee which entries are displayed. That means retrieving the same
11451cb0ef41Sopenharmony_ci<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
11461cb0ef41Sopenharmony_ciwith no remaining strong references may be garbage collected at any time.</p>
11471cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> { inspect } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
11481cb0ef41Sopenharmony_ci
11491cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> obj = { <span class="hljs-attr">a</span>: <span class="hljs-number">1</span> };
11501cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> obj2 = { <span class="hljs-attr">b</span>: <span class="hljs-number">2</span> };
11511cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> weakSet = <span class="hljs-keyword">new</span> <span class="hljs-title class_">WeakSet</span>([obj, obj2]);
11521cb0ef41Sopenharmony_ci
11531cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">inspect</span>(weakSet, { <span class="hljs-attr">showHidden</span>: <span class="hljs-literal">true</span> }));
11541cb0ef41Sopenharmony_ci<span class="hljs-comment">// WeakSet { { a: 1 }, { b: 2 } }</span></code> <button class="copy-button">copy</button></pre>
11551cb0ef41Sopenharmony_ci<p>The <code>sorted</code> option ensures that an object's property insertion order does not
11561cb0ef41Sopenharmony_ciimpact the result of <code>util.inspect()</code>.</p>
11571cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> { inspect } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
11581cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> assert = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:assert'</span>);
11591cb0ef41Sopenharmony_ci
11601cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> o1 = {
11611cb0ef41Sopenharmony_ci  <span class="hljs-attr">b</span>: [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>],
11621cb0ef41Sopenharmony_ci  <span class="hljs-attr">a</span>: <span class="hljs-string">'`a` comes before `b`'</span>,
11631cb0ef41Sopenharmony_ci  <span class="hljs-attr">c</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Set</span>([<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>]),
11641cb0ef41Sopenharmony_ci};
11651cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">inspect</span>(o1, { <span class="hljs-attr">sorted</span>: <span class="hljs-literal">true</span> }));
11661cb0ef41Sopenharmony_ci<span class="hljs-comment">// { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set(3) { 1, 2, 3 } }</span>
11671cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">inspect</span>(o1, { <span class="hljs-attr">sorted</span>: <span class="hljs-function">(<span class="hljs-params">a, b</span>) =></span> b.<span class="hljs-title function_">localeCompare</span>(a) }));
11681cb0ef41Sopenharmony_ci<span class="hljs-comment">// { c: Set(3) { 3, 2, 1 }, b: [ 2, 3, 1 ], a: '`a` comes before `b`' }</span>
11691cb0ef41Sopenharmony_ci
11701cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> o2 = {
11711cb0ef41Sopenharmony_ci  <span class="hljs-attr">c</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Set</span>([<span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">3</span>]),
11721cb0ef41Sopenharmony_ci  <span class="hljs-attr">a</span>: <span class="hljs-string">'`a` comes before `b`'</span>,
11731cb0ef41Sopenharmony_ci  <span class="hljs-attr">b</span>: [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>],
11741cb0ef41Sopenharmony_ci};
11751cb0ef41Sopenharmony_ciassert.<span class="hljs-property">strict</span>.<span class="hljs-title function_">equal</span>(
11761cb0ef41Sopenharmony_ci  <span class="hljs-title function_">inspect</span>(o1, { <span class="hljs-attr">sorted</span>: <span class="hljs-literal">true</span> }),
11771cb0ef41Sopenharmony_ci  <span class="hljs-title function_">inspect</span>(o2, { <span class="hljs-attr">sorted</span>: <span class="hljs-literal">true</span> }),
11781cb0ef41Sopenharmony_ci);</code> <button class="copy-button">copy</button></pre>
11791cb0ef41Sopenharmony_ci<p>The <code>numericSeparator</code> option adds an underscore every three digits to all
11801cb0ef41Sopenharmony_cinumbers.</p>
11811cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> { inspect } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
11821cb0ef41Sopenharmony_ci
11831cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> thousand = <span class="hljs-number">1_000</span>;
11841cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> million = <span class="hljs-number">1_000_000</span>;
11851cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> bigNumber = <span class="hljs-number">123_456_789n</span>;
11861cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> bigDecimal = <span class="hljs-number">1_234.123_45</span>;
11871cb0ef41Sopenharmony_ci
11881cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(thousand, million, bigNumber, bigDecimal);
11891cb0ef41Sopenharmony_ci<span class="hljs-comment">// 1_000 1_000_000 123_456_789n 1_234.123_45</span></code> <button class="copy-button">copy</button></pre>
11901cb0ef41Sopenharmony_ci<p><code>util.inspect()</code> is a synchronous method intended for debugging. Its maximum
11911cb0ef41Sopenharmony_cioutput length is approximately 128 MiB. Inputs that result in longer output will
11921cb0ef41Sopenharmony_cibe truncated.</p>
11931cb0ef41Sopenharmony_ci<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>
11941cb0ef41Sopenharmony_ci
11951cb0ef41Sopenharmony_ci<p>Color output (if enabled) of <code>util.inspect</code> is customizable globally
11961cb0ef41Sopenharmony_civia the <code>util.inspect.styles</code> and <code>util.inspect.colors</code> properties.</p>
11971cb0ef41Sopenharmony_ci<p><code>util.inspect.styles</code> is a map associating a style name to a color from
11981cb0ef41Sopenharmony_ci<code>util.inspect.colors</code>.</p>
11991cb0ef41Sopenharmony_ci<p>The default styles and associated colors are:</p>
12001cb0ef41Sopenharmony_ci<ul>
12011cb0ef41Sopenharmony_ci<li><code>bigint</code>: <code>yellow</code></li>
12021cb0ef41Sopenharmony_ci<li><code>boolean</code>: <code>yellow</code></li>
12031cb0ef41Sopenharmony_ci<li><code>date</code>: <code>magenta</code></li>
12041cb0ef41Sopenharmony_ci<li><code>module</code>: <code>underline</code></li>
12051cb0ef41Sopenharmony_ci<li><code>name</code>: (no styling)</li>
12061cb0ef41Sopenharmony_ci<li><code>null</code>: <code>bold</code></li>
12071cb0ef41Sopenharmony_ci<li><code>number</code>: <code>yellow</code></li>
12081cb0ef41Sopenharmony_ci<li><code>regexp</code>: <code>red</code></li>
12091cb0ef41Sopenharmony_ci<li><code>special</code>: <code>cyan</code> (e.g., <code>Proxies</code>)</li>
12101cb0ef41Sopenharmony_ci<li><code>string</code>: <code>green</code></li>
12111cb0ef41Sopenharmony_ci<li><code>symbol</code>: <code>green</code></li>
12121cb0ef41Sopenharmony_ci<li><code>undefined</code>: <code>grey</code></li>
12131cb0ef41Sopenharmony_ci</ul>
12141cb0ef41Sopenharmony_ci<p>Color styling uses ANSI control codes that may not be supported on all
12151cb0ef41Sopenharmony_citerminals. To verify color support use <a href="tty.html#writestreamhascolorscount-env"><code>tty.hasColors()</code></a>.</p>
12161cb0ef41Sopenharmony_ci<p>Predefined control codes are listed below (grouped as "Modifiers", "Foreground
12171cb0ef41Sopenharmony_cicolors", and "Background colors").</p>
12181cb0ef41Sopenharmony_ci<h5>Modifiers<span><a class="mark" href="#modifiers" id="modifiers">#</a></span><a aria-hidden="true" class="legacy" id="util_modifiers"></a></h5>
12191cb0ef41Sopenharmony_ci<p>Modifier support varies throughout different terminals. They will mostly be
12201cb0ef41Sopenharmony_ciignored, if not supported.</p>
12211cb0ef41Sopenharmony_ci<ul>
12221cb0ef41Sopenharmony_ci<li><code>reset</code> - Resets all (color) modifiers to their defaults</li>
12231cb0ef41Sopenharmony_ci<li><strong>bold</strong> - Make text bold</li>
12241cb0ef41Sopenharmony_ci<li><em>italic</em> - Make text italic</li>
12251cb0ef41Sopenharmony_ci<li><span style="border-bottom: 1px;">underline</span> - Make text underlined</li>
12261cb0ef41Sopenharmony_ci<li><del>strikethrough</del> - Puts a horizontal line through the center of the text
12271cb0ef41Sopenharmony_ci(Alias: <code>strikeThrough</code>, <code>crossedout</code>, <code>crossedOut</code>)</li>
12281cb0ef41Sopenharmony_ci<li><code>hidden</code> - Prints the text, but makes it invisible (Alias: conceal)</li>
12291cb0ef41Sopenharmony_ci<li><span style="opacity: 0.5;">dim</span> - Decreased color intensity (Alias:
12301cb0ef41Sopenharmony_ci<code>faint</code>)</li>
12311cb0ef41Sopenharmony_ci<li><span style="border-top: 1px">overlined</span> - Make text overlined</li>
12321cb0ef41Sopenharmony_ci<li>blink - Hides and shows the text in an interval</li>
12331cb0ef41Sopenharmony_ci<li><span style="filter: invert(100%)">inverse</span> - Swap foreground and
12341cb0ef41Sopenharmony_cibackground colors (Alias: <code>swapcolors</code>, <code>swapColors</code>)</li>
12351cb0ef41Sopenharmony_ci<li><span style="border-bottom: 1px double;">doubleunderline</span> - Make text
12361cb0ef41Sopenharmony_cidouble underlined (Alias: <code>doubleUnderline</code>)</li>
12371cb0ef41Sopenharmony_ci<li><span style="border: 1px">framed</span> - Draw a frame around the text</li>
12381cb0ef41Sopenharmony_ci</ul>
12391cb0ef41Sopenharmony_ci<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>
12401cb0ef41Sopenharmony_ci<ul>
12411cb0ef41Sopenharmony_ci<li><code>black</code></li>
12421cb0ef41Sopenharmony_ci<li><code>red</code></li>
12431cb0ef41Sopenharmony_ci<li><code>green</code></li>
12441cb0ef41Sopenharmony_ci<li><code>yellow</code></li>
12451cb0ef41Sopenharmony_ci<li><code>blue</code></li>
12461cb0ef41Sopenharmony_ci<li><code>magenta</code></li>
12471cb0ef41Sopenharmony_ci<li><code>cyan</code></li>
12481cb0ef41Sopenharmony_ci<li><code>white</code></li>
12491cb0ef41Sopenharmony_ci<li><code>gray</code> (alias: <code>grey</code>, <code>blackBright</code>)</li>
12501cb0ef41Sopenharmony_ci<li><code>redBright</code></li>
12511cb0ef41Sopenharmony_ci<li><code>greenBright</code></li>
12521cb0ef41Sopenharmony_ci<li><code>yellowBright</code></li>
12531cb0ef41Sopenharmony_ci<li><code>blueBright</code></li>
12541cb0ef41Sopenharmony_ci<li><code>magentaBright</code></li>
12551cb0ef41Sopenharmony_ci<li><code>cyanBright</code></li>
12561cb0ef41Sopenharmony_ci<li><code>whiteBright</code></li>
12571cb0ef41Sopenharmony_ci</ul>
12581cb0ef41Sopenharmony_ci<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>
12591cb0ef41Sopenharmony_ci<ul>
12601cb0ef41Sopenharmony_ci<li><code>bgBlack</code></li>
12611cb0ef41Sopenharmony_ci<li><code>bgRed</code></li>
12621cb0ef41Sopenharmony_ci<li><code>bgGreen</code></li>
12631cb0ef41Sopenharmony_ci<li><code>bgYellow</code></li>
12641cb0ef41Sopenharmony_ci<li><code>bgBlue</code></li>
12651cb0ef41Sopenharmony_ci<li><code>bgMagenta</code></li>
12661cb0ef41Sopenharmony_ci<li><code>bgCyan</code></li>
12671cb0ef41Sopenharmony_ci<li><code>bgWhite</code></li>
12681cb0ef41Sopenharmony_ci<li><code>bgGray</code> (alias: <code>bgGrey</code>, <code>bgBlackBright</code>)</li>
12691cb0ef41Sopenharmony_ci<li><code>bgRedBright</code></li>
12701cb0ef41Sopenharmony_ci<li><code>bgGreenBright</code></li>
12711cb0ef41Sopenharmony_ci<li><code>bgYellowBright</code></li>
12721cb0ef41Sopenharmony_ci<li><code>bgBlueBright</code></li>
12731cb0ef41Sopenharmony_ci<li><code>bgMagentaBright</code></li>
12741cb0ef41Sopenharmony_ci<li><code>bgCyanBright</code></li>
12751cb0ef41Sopenharmony_ci<li><code>bgWhiteBright</code></li>
12761cb0ef41Sopenharmony_ci</ul>
12771cb0ef41Sopenharmony_ci<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>
12781cb0ef41Sopenharmony_ci
12791cb0ef41Sopenharmony_ci<div class="api_metadata">
12801cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
12811cb0ef41Sopenharmony_ci<table>
12821cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
12831cb0ef41Sopenharmony_ci<tr><td>v17.3.0, v16.14.0</td>
12841cb0ef41Sopenharmony_ci<td><p>The inspect argument is added for more interoperability.</p></td></tr>
12851cb0ef41Sopenharmony_ci<tr><td>v0.1.97</td>
12861cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.97</span></p></td></tr>
12871cb0ef41Sopenharmony_ci</tbody></table>
12881cb0ef41Sopenharmony_ci</details>
12891cb0ef41Sopenharmony_ci</div>
12901cb0ef41Sopenharmony_ci<p>Objects may also define their own
12911cb0ef41Sopenharmony_ci<a href="#utilinspectcustom"><code>[util.inspect.custom](depth, opts, inspect)</code></a> function,
12921cb0ef41Sopenharmony_ciwhich <code>util.inspect()</code> will invoke and use the result of when inspecting
12931cb0ef41Sopenharmony_cithe object.</p>
12941cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
12951cb0ef41Sopenharmony_ci
12961cb0ef41Sopenharmony_ci<span class="hljs-keyword">class</span> <span class="hljs-title class_">Box</span> {
12971cb0ef41Sopenharmony_ci  <span class="hljs-title function_">constructor</span>(<span class="hljs-params">value</span>) {
12981cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">this</span>.<span class="hljs-property">value</span> = value;
12991cb0ef41Sopenharmony_ci  }
13001cb0ef41Sopenharmony_ci
13011cb0ef41Sopenharmony_ci  [util.<span class="hljs-property">inspect</span>.<span class="hljs-property">custom</span>](depth, options, inspect) {
13021cb0ef41Sopenharmony_ci    <span class="hljs-keyword">if</span> (depth &#x3C; <span class="hljs-number">0</span>) {
13031cb0ef41Sopenharmony_ci      <span class="hljs-keyword">return</span> options.<span class="hljs-title function_">stylize</span>(<span class="hljs-string">'[Box]'</span>, <span class="hljs-string">'special'</span>);
13041cb0ef41Sopenharmony_ci    }
13051cb0ef41Sopenharmony_ci
13061cb0ef41Sopenharmony_ci    <span class="hljs-keyword">const</span> newOptions = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">assign</span>({}, options, {
13071cb0ef41Sopenharmony_ci      <span class="hljs-attr">depth</span>: options.<span class="hljs-property">depth</span> === <span class="hljs-literal">null</span> ? <span class="hljs-literal">null</span> : options.<span class="hljs-property">depth</span> - <span class="hljs-number">1</span>,
13081cb0ef41Sopenharmony_ci    });
13091cb0ef41Sopenharmony_ci
13101cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Five space padding because that's the size of "Box&#x3C; ".</span>
13111cb0ef41Sopenharmony_ci    <span class="hljs-keyword">const</span> padding = <span class="hljs-string">' '</span>.<span class="hljs-title function_">repeat</span>(<span class="hljs-number">5</span>);
13121cb0ef41Sopenharmony_ci    <span class="hljs-keyword">const</span> inner = <span class="hljs-title function_">inspect</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">value</span>, newOptions)
13131cb0ef41Sopenharmony_ci                  .<span class="hljs-title function_">replace</span>(<span class="hljs-regexp">/\n/g</span>, <span class="hljs-string">`\n<span class="hljs-subst">${padding}</span>`</span>);
13141cb0ef41Sopenharmony_ci    <span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${options.stylize(<span class="hljs-string">'Box'</span>, <span class="hljs-string">'special'</span>)}</span>&#x3C; <span class="hljs-subst">${inner}</span> >`</span>;
13151cb0ef41Sopenharmony_ci  }
13161cb0ef41Sopenharmony_ci}
13171cb0ef41Sopenharmony_ci
13181cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> box = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Box</span>(<span class="hljs-literal">true</span>);
13191cb0ef41Sopenharmony_ci
13201cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">inspect</span>(box);
13211cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: "Box&#x3C; true >"</span></code> <button class="copy-button">copy</button></pre>
13221cb0ef41Sopenharmony_ci<p>Custom <code>[util.inspect.custom](depth, opts, inspect)</code> functions typically return
13231cb0ef41Sopenharmony_cia string but may return a value of any type that will be formatted accordingly
13241cb0ef41Sopenharmony_ciby <code>util.inspect()</code>.</p>
13251cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
13261cb0ef41Sopenharmony_ci
13271cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> obj = { <span class="hljs-attr">foo</span>: <span class="hljs-string">'this will not show up in the inspect() output'</span> };
13281cb0ef41Sopenharmony_ciobj[util.<span class="hljs-property">inspect</span>.<span class="hljs-property">custom</span>] = <span class="hljs-function">(<span class="hljs-params">depth</span>) =></span> {
13291cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> { <span class="hljs-attr">bar</span>: <span class="hljs-string">'baz'</span> };
13301cb0ef41Sopenharmony_ci};
13311cb0ef41Sopenharmony_ci
13321cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">inspect</span>(obj);
13331cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: "{ bar: 'baz' }"</span></code> <button class="copy-button">copy</button></pre>
13341cb0ef41Sopenharmony_ci<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>
13351cb0ef41Sopenharmony_ci<div class="api_metadata">
13361cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
13371cb0ef41Sopenharmony_ci<table>
13381cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
13391cb0ef41Sopenharmony_ci<tr><td>v10.12.0</td>
13401cb0ef41Sopenharmony_ci<td><p>This is now defined as a shared symbol.</p></td></tr>
13411cb0ef41Sopenharmony_ci<tr><td>v6.6.0</td>
13421cb0ef41Sopenharmony_ci<td><p><span>Added in: v6.6.0</span></p></td></tr>
13431cb0ef41Sopenharmony_ci</tbody></table>
13441cb0ef41Sopenharmony_ci</details>
13451cb0ef41Sopenharmony_ci</div>
13461cb0ef41Sopenharmony_ci<ul>
13471cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&#x3C;symbol></a> that can be used to declare custom inspect functions.</li>
13481cb0ef41Sopenharmony_ci</ul>
13491cb0ef41Sopenharmony_ci<p>In addition to being accessible through <code>util.inspect.custom</code>, this
13501cb0ef41Sopenharmony_cisymbol is <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for">registered globally</a> and can be
13511cb0ef41Sopenharmony_ciaccessed in any environment as <code>Symbol.for('nodejs.util.inspect.custom')</code>.</p>
13521cb0ef41Sopenharmony_ci<p>Using this allows code to be written in a portable fashion, so that the custom
13531cb0ef41Sopenharmony_ciinspect function is used in an Node.js environment and ignored in the browser.
13541cb0ef41Sopenharmony_ciThe <code>util.inspect()</code> function itself is passed as third argument to the custom
13551cb0ef41Sopenharmony_ciinspect function to allow further portability.</p>
13561cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> customInspectSymbol = <span class="hljs-title class_">Symbol</span>.<span class="hljs-title function_">for</span>(<span class="hljs-string">'nodejs.util.inspect.custom'</span>);
13571cb0ef41Sopenharmony_ci
13581cb0ef41Sopenharmony_ci<span class="hljs-keyword">class</span> <span class="hljs-title class_">Password</span> {
13591cb0ef41Sopenharmony_ci  <span class="hljs-title function_">constructor</span>(<span class="hljs-params">value</span>) {
13601cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">this</span>.<span class="hljs-property">value</span> = value;
13611cb0ef41Sopenharmony_ci  }
13621cb0ef41Sopenharmony_ci
13631cb0ef41Sopenharmony_ci  <span class="hljs-title function_">toString</span>(<span class="hljs-params"></span>) {
13641cb0ef41Sopenharmony_ci    <span class="hljs-keyword">return</span> <span class="hljs-string">'xxxxxxxx'</span>;
13651cb0ef41Sopenharmony_ci  }
13661cb0ef41Sopenharmony_ci
13671cb0ef41Sopenharmony_ci  [customInspectSymbol](depth, inspectOptions, inspect) {
13681cb0ef41Sopenharmony_ci    <span class="hljs-keyword">return</span> <span class="hljs-string">`Password &#x3C;<span class="hljs-subst">${<span class="hljs-variable language_">this</span>.toString()}</span>>`</span>;
13691cb0ef41Sopenharmony_ci  }
13701cb0ef41Sopenharmony_ci}
13711cb0ef41Sopenharmony_ci
13721cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> password = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Password</span>(<span class="hljs-string">'r0sebud'</span>);
13731cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(password);
13741cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints Password &#x3C;xxxxxxxx></span></code> <button class="copy-button">copy</button></pre>
13751cb0ef41Sopenharmony_ci<p>See <a href="#custom-inspection-functions-on-objects">Custom inspection functions on Objects</a> for more details.</p>
13761cb0ef41Sopenharmony_ci<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>
13771cb0ef41Sopenharmony_ci<div class="api_metadata">
13781cb0ef41Sopenharmony_ci<span>Added in: v6.4.0</span>
13791cb0ef41Sopenharmony_ci</div>
13801cb0ef41Sopenharmony_ci<p>The <code>defaultOptions</code> value allows customization of the default options used by
13811cb0ef41Sopenharmony_ci<code>util.inspect</code>. This is useful for functions like <code>console.log</code> or
13821cb0ef41Sopenharmony_ci<code>util.format</code> which implicitly call into <code>util.inspect</code>. It shall be set to an
13831cb0ef41Sopenharmony_ciobject containing one or more valid <a href="#utilinspectobject-options"><code>util.inspect()</code></a> options. Setting
13841cb0ef41Sopenharmony_cioption properties directly is also supported.</p>
13851cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
13861cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> arr = <span class="hljs-title class_">Array</span>(<span class="hljs-number">101</span>).<span class="hljs-title function_">fill</span>(<span class="hljs-number">0</span>);
13871cb0ef41Sopenharmony_ci
13881cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(arr); <span class="hljs-comment">// Logs the truncated array</span>
13891cb0ef41Sopenharmony_ciutil.<span class="hljs-property">inspect</span>.<span class="hljs-property">defaultOptions</span>.<span class="hljs-property">maxArrayLength</span> = <span class="hljs-literal">null</span>;
13901cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(arr); <span class="hljs-comment">// logs the full array</span></code> <button class="copy-button">copy</button></pre>
13911cb0ef41Sopenharmony_ci</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>
13921cb0ef41Sopenharmony_ci<div class="api_metadata">
13931cb0ef41Sopenharmony_ci<span>Added in: v9.0.0</span>
13941cb0ef41Sopenharmony_ci</div>
13951cb0ef41Sopenharmony_ci<ul>
13961cb0ef41Sopenharmony_ci<li><code>val1</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
13971cb0ef41Sopenharmony_ci<li><code>val2</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
13981cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
13991cb0ef41Sopenharmony_ci</ul>
14001cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if there is deep strict equality between <code>val1</code> and <code>val2</code>.
14011cb0ef41Sopenharmony_ciOtherwise, returns <code>false</code>.</p>
14021cb0ef41Sopenharmony_ci<p>See <a href="assert.html#assertdeepstrictequalactual-expected-message"><code>assert.deepStrictEqual()</code></a> for more information about deep strict
14031cb0ef41Sopenharmony_ciequality.</p>
14041cb0ef41Sopenharmony_ci</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>
14051cb0ef41Sopenharmony_ci<div class="api_metadata">
14061cb0ef41Sopenharmony_ci<span>Added in: v18.13.0</span>
14071cb0ef41Sopenharmony_ci</div>
14081cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
14091cb0ef41Sopenharmony_ci<p>An implementation of <a href="https://bmeck.github.io/node-proposal-mime-api/">the MIMEType class</a>.</p>
14101cb0ef41Sopenharmony_ci<p>In accordance with browser conventions, all properties of <code>MIMEType</code> objects
14111cb0ef41Sopenharmony_ciare implemented as getters and setters on the class prototype, rather than as
14121cb0ef41Sopenharmony_cidata properties on the object itself.</p>
14131cb0ef41Sopenharmony_ci<p>A MIME string is a structured string containing multiple meaningful
14141cb0ef41Sopenharmony_cicomponents. When parsed, a <code>MIMEType</code> object is returned containing
14151cb0ef41Sopenharmony_ciproperties for each of these components.</p>
14161cb0ef41Sopenharmony_ci<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>
14171cb0ef41Sopenharmony_ci<ul>
14181cb0ef41Sopenharmony_ci<li><code>input</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The input MIME to parse</li>
14191cb0ef41Sopenharmony_ci</ul>
14201cb0ef41Sopenharmony_ci<p>Creates a new <code>MIMEType</code> object by parsing the <code>input</code>.</p>
14211cb0ef41Sopenharmony_ci
14221cb0ef41Sopenharmony_ci<pre class="with-42-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MIMEType</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
14231cb0ef41Sopenharmony_ci
14241cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIME = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/plain'</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">MIMEType</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
14251cb0ef41Sopenharmony_ci
14261cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIME = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/plain'</span>);</code><button class="copy-button">copy</button></pre>
14271cb0ef41Sopenharmony_ci<p>A <code>TypeError</code> will be thrown if the <code>input</code> is not a valid MIME. Note
14281cb0ef41Sopenharmony_cithat an effort will be made to coerce the given values into strings. For
14291cb0ef41Sopenharmony_ciinstance:</p>
14301cb0ef41Sopenharmony_ci
14311cb0ef41Sopenharmony_ci<pre class="with-62-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MIMEType</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
14321cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIME = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>({ <span class="hljs-attr">toString</span>: <span class="hljs-function">() =></span> <span class="hljs-string">'text/plain'</span> });
14331cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">String</span>(myMIME));
14341cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: text/plain</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">MIMEType</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
14351cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIME = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>({ <span class="hljs-attr">toString</span>: <span class="hljs-function">() =></span> <span class="hljs-string">'text/plain'</span> });
14361cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">String</span>(myMIME));
14371cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: text/plain</span></code><button class="copy-button">copy</button></pre>
14381cb0ef41Sopenharmony_ci<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>
14391cb0ef41Sopenharmony_ci<ul>
14401cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
14411cb0ef41Sopenharmony_ci</ul>
14421cb0ef41Sopenharmony_ci<p>Gets and sets the type portion of the MIME.</p>
14431cb0ef41Sopenharmony_ci
14441cb0ef41Sopenharmony_ci<pre class="with-42-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MIMEType</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
14451cb0ef41Sopenharmony_ci
14461cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIME = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/javascript'</span>);
14471cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">type</span>);
14481cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: text</span>
14491cb0ef41Sopenharmony_cimyMIME.<span class="hljs-property">type</span> = <span class="hljs-string">'application'</span>;
14501cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">type</span>);
14511cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: application</span>
14521cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">String</span>(myMIME));
14531cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: application/javascript</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">MIMEType</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
14541cb0ef41Sopenharmony_ci
14551cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIME = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/javascript'</span>);
14561cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">type</span>);
14571cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: text</span>
14581cb0ef41Sopenharmony_cimyMIME.<span class="hljs-property">type</span> = <span class="hljs-string">'application'</span>;
14591cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">type</span>);
14601cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: application</span>
14611cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">String</span>(myMIME));
14621cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: application/javascript</span></code><button class="copy-button">copy</button></pre>
14631cb0ef41Sopenharmony_ci<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>
14641cb0ef41Sopenharmony_ci<ul>
14651cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
14661cb0ef41Sopenharmony_ci</ul>
14671cb0ef41Sopenharmony_ci<p>Gets and sets the subtype portion of the MIME.</p>
14681cb0ef41Sopenharmony_ci
14691cb0ef41Sopenharmony_ci<pre class="with-42-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MIMEType</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
14701cb0ef41Sopenharmony_ci
14711cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIME = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/ecmascript'</span>);
14721cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">subtype</span>);
14731cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: ecmascript</span>
14741cb0ef41Sopenharmony_cimyMIME.<span class="hljs-property">subtype</span> = <span class="hljs-string">'javascript'</span>;
14751cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">subtype</span>);
14761cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: javascript</span>
14771cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">String</span>(myMIME));
14781cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: text/javascript</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">MIMEType</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
14791cb0ef41Sopenharmony_ci
14801cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIME = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/ecmascript'</span>);
14811cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">subtype</span>);
14821cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: ecmascript</span>
14831cb0ef41Sopenharmony_cimyMIME.<span class="hljs-property">subtype</span> = <span class="hljs-string">'javascript'</span>;
14841cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">subtype</span>);
14851cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: javascript</span>
14861cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">String</span>(myMIME));
14871cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: text/javascript</span></code><button class="copy-button">copy</button></pre>
14881cb0ef41Sopenharmony_ci<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>
14891cb0ef41Sopenharmony_ci<ul>
14901cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
14911cb0ef41Sopenharmony_ci</ul>
14921cb0ef41Sopenharmony_ci<p>Gets the essence of the MIME. This property is read only.
14931cb0ef41Sopenharmony_ciUse <code>mime.type</code> or <code>mime.subtype</code> to alter the MIME.</p>
14941cb0ef41Sopenharmony_ci
14951cb0ef41Sopenharmony_ci<pre class="with-42-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MIMEType</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
14961cb0ef41Sopenharmony_ci
14971cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIME = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/javascript;key=value'</span>);
14981cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">essence</span>);
14991cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: text/javascript</span>
15001cb0ef41Sopenharmony_cimyMIME.<span class="hljs-property">type</span> = <span class="hljs-string">'application'</span>;
15011cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">essence</span>);
15021cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: application/javascript</span>
15031cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">String</span>(myMIME));
15041cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: application/javascript;key=value</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">MIMEType</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
15051cb0ef41Sopenharmony_ci
15061cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIME = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/javascript;key=value'</span>);
15071cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">essence</span>);
15081cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: text/javascript</span>
15091cb0ef41Sopenharmony_cimyMIME.<span class="hljs-property">type</span> = <span class="hljs-string">'application'</span>;
15101cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myMIME.<span class="hljs-property">essence</span>);
15111cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: application/javascript</span>
15121cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">String</span>(myMIME));
15131cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: application/javascript;key=value</span></code><button class="copy-button">copy</button></pre>
15141cb0ef41Sopenharmony_ci<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>
15151cb0ef41Sopenharmony_ci<ul>
15161cb0ef41Sopenharmony_ci<li><a href="util.html#class-utilmimeparams" class="type">&#x3C;MIMEParams></a></li>
15171cb0ef41Sopenharmony_ci</ul>
15181cb0ef41Sopenharmony_ci<p>Gets the <a href="#class-utilmimeparams"><code>MIMEParams</code></a> object representing the
15191cb0ef41Sopenharmony_ciparameters of the MIME. This property is read-only. See
15201cb0ef41Sopenharmony_ci<a href="#class-utilmimeparams"><code>MIMEParams</code></a> documentation for details.</p>
15211cb0ef41Sopenharmony_ci<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>
15221cb0ef41Sopenharmony_ci<ul>
15231cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
15241cb0ef41Sopenharmony_ci</ul>
15251cb0ef41Sopenharmony_ci<p>The <code>toString()</code> method on the <code>MIMEType</code> object returns the serialized MIME.</p>
15261cb0ef41Sopenharmony_ci<p>Because of the need for standard compliance, this method does not allow users
15271cb0ef41Sopenharmony_cito customize the serialization process of the MIME.</p>
15281cb0ef41Sopenharmony_ci<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>
15291cb0ef41Sopenharmony_ci<ul>
15301cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
15311cb0ef41Sopenharmony_ci</ul>
15321cb0ef41Sopenharmony_ci<p>Alias for <a href="#mimetostring"><code>mime.toString()</code></a>.</p>
15331cb0ef41Sopenharmony_ci<p>This method is automatically called when an <code>MIMEType</code> object is serialized
15341cb0ef41Sopenharmony_ciwith <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify"><code>JSON.stringify()</code></a>.</p>
15351cb0ef41Sopenharmony_ci
15361cb0ef41Sopenharmony_ci<pre class="with-42-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MIMEType</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
15371cb0ef41Sopenharmony_ci
15381cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIMES = [
15391cb0ef41Sopenharmony_ci  <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'image/png'</span>),
15401cb0ef41Sopenharmony_ci  <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'image/gif'</span>),
15411cb0ef41Sopenharmony_ci];
15421cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>(myMIMES));
15431cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: ["image/png", "image/gif"]</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">MIMEType</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
15441cb0ef41Sopenharmony_ci
15451cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myMIMES = [
15461cb0ef41Sopenharmony_ci  <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'image/png'</span>),
15471cb0ef41Sopenharmony_ci  <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'image/gif'</span>),
15481cb0ef41Sopenharmony_ci];
15491cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>(myMIMES));
15501cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: ["image/png", "image/gif"]</span></code><button class="copy-button">copy</button></pre>
15511cb0ef41Sopenharmony_ci</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>
15521cb0ef41Sopenharmony_ci<div class="api_metadata">
15531cb0ef41Sopenharmony_ci<span>Added in: v18.13.0</span>
15541cb0ef41Sopenharmony_ci</div>
15551cb0ef41Sopenharmony_ci<p>The <code>MIMEParams</code> API provides read and write access to the parameters of a
15561cb0ef41Sopenharmony_ci<code>MIMEType</code>.</p>
15571cb0ef41Sopenharmony_ci<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>
15581cb0ef41Sopenharmony_ci<p>Creates a new <code>MIMEParams</code> object by with empty parameters</p>
15591cb0ef41Sopenharmony_ci
15601cb0ef41Sopenharmony_ci<pre class="with-44-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MIMEParams</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
15611cb0ef41Sopenharmony_ci
15621cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myParams = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEParams</span>();</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">MIMEParams</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
15631cb0ef41Sopenharmony_ci
15641cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myParams = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEParams</span>();</code><button class="copy-button">copy</button></pre>
15651cb0ef41Sopenharmony_ci<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>
15661cb0ef41Sopenharmony_ci<ul>
15671cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
15681cb0ef41Sopenharmony_ci</ul>
15691cb0ef41Sopenharmony_ci<p>Remove all name-value pairs whose name is <code>name</code>.</p>
15701cb0ef41Sopenharmony_ci<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>
15711cb0ef41Sopenharmony_ci<ul>
15721cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol" class="type">&#x3C;Iterator></a></li>
15731cb0ef41Sopenharmony_ci</ul>
15741cb0ef41Sopenharmony_ci<p>Returns an iterator over each of the name-value pairs in the parameters.
15751cb0ef41Sopenharmony_ciEach item of the iterator is a JavaScript <code>Array</code>. The first item of the array
15761cb0ef41Sopenharmony_ciis the <code>name</code>, the second item of the array is the <code>value</code>.</p>
15771cb0ef41Sopenharmony_ci<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>
15781cb0ef41Sopenharmony_ci<ul>
15791cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
15801cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> or <code>null</code> if there is no name-value pair with the given
15811cb0ef41Sopenharmony_ci<code>name</code>.</li>
15821cb0ef41Sopenharmony_ci</ul>
15831cb0ef41Sopenharmony_ci<p>Returns the value of the first name-value pair whose name is <code>name</code>. If there
15841cb0ef41Sopenharmony_ciare no such pairs, <code>null</code> is returned.</p>
15851cb0ef41Sopenharmony_ci<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>
15861cb0ef41Sopenharmony_ci<ul>
15871cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
15881cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
15891cb0ef41Sopenharmony_ci</ul>
15901cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if there is at least one name-value pair whose name is <code>name</code>.</p>
15911cb0ef41Sopenharmony_ci<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>
15921cb0ef41Sopenharmony_ci<ul>
15931cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol" class="type">&#x3C;Iterator></a></li>
15941cb0ef41Sopenharmony_ci</ul>
15951cb0ef41Sopenharmony_ci<p>Returns an iterator over the names of each name-value pair.</p>
15961cb0ef41Sopenharmony_ci
15971cb0ef41Sopenharmony_ci<pre class="with-42-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MIMEType</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
15981cb0ef41Sopenharmony_ci
15991cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { params } = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/plain;foo=0;bar=1'</span>);
16001cb0ef41Sopenharmony_ci<span class="hljs-keyword">for</span> (<span class="hljs-keyword">const</span> name <span class="hljs-keyword">of</span> params.<span class="hljs-title function_">keys</span>()) {
16011cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(name);
16021cb0ef41Sopenharmony_ci}
16031cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints:</span>
16041cb0ef41Sopenharmony_ci<span class="hljs-comment">//   foo</span>
16051cb0ef41Sopenharmony_ci<span class="hljs-comment">//   bar</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">MIMEType</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
16061cb0ef41Sopenharmony_ci
16071cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { params } = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/plain;foo=0;bar=1'</span>);
16081cb0ef41Sopenharmony_ci<span class="hljs-keyword">for</span> (<span class="hljs-keyword">const</span> name <span class="hljs-keyword">of</span> params.<span class="hljs-title function_">keys</span>()) {
16091cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(name);
16101cb0ef41Sopenharmony_ci}
16111cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints:</span>
16121cb0ef41Sopenharmony_ci<span class="hljs-comment">//   foo</span>
16131cb0ef41Sopenharmony_ci<span class="hljs-comment">//   bar</span></code><button class="copy-button">copy</button></pre>
16141cb0ef41Sopenharmony_ci<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>
16151cb0ef41Sopenharmony_ci<ul>
16161cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
16171cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
16181cb0ef41Sopenharmony_ci</ul>
16191cb0ef41Sopenharmony_ci<p>Sets the value in the <code>MIMEParams</code> object associated with <code>name</code> to
16201cb0ef41Sopenharmony_ci<code>value</code>. If there are any pre-existing name-value pairs whose names are <code>name</code>,
16211cb0ef41Sopenharmony_ciset the first such pair's value to <code>value</code>.</p>
16221cb0ef41Sopenharmony_ci
16231cb0ef41Sopenharmony_ci<pre class="with-42-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MIMEType</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
16241cb0ef41Sopenharmony_ci
16251cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { params } = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/plain;foo=0;bar=1'</span>);
16261cb0ef41Sopenharmony_ciparams.<span class="hljs-title function_">set</span>(<span class="hljs-string">'foo'</span>, <span class="hljs-string">'def'</span>);
16271cb0ef41Sopenharmony_ciparams.<span class="hljs-title function_">set</span>(<span class="hljs-string">'baz'</span>, <span class="hljs-string">'xyz'</span>);
16281cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(params.<span class="hljs-title function_">toString</span>());
16291cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: foo=def&#x26;bar=1&#x26;baz=xyz</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">MIMEType</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
16301cb0ef41Sopenharmony_ci
16311cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { params } = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/plain;foo=0;bar=1'</span>);
16321cb0ef41Sopenharmony_ciparams.<span class="hljs-title function_">set</span>(<span class="hljs-string">'foo'</span>, <span class="hljs-string">'def'</span>);
16331cb0ef41Sopenharmony_ciparams.<span class="hljs-title function_">set</span>(<span class="hljs-string">'baz'</span>, <span class="hljs-string">'xyz'</span>);
16341cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(params.<span class="hljs-title function_">toString</span>());
16351cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: foo=def&#x26;bar=1&#x26;baz=xyz</span></code><button class="copy-button">copy</button></pre>
16361cb0ef41Sopenharmony_ci<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>
16371cb0ef41Sopenharmony_ci<ul>
16381cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol" class="type">&#x3C;Iterator></a></li>
16391cb0ef41Sopenharmony_ci</ul>
16401cb0ef41Sopenharmony_ci<p>Returns an iterator over the values of each name-value pair.</p>
16411cb0ef41Sopenharmony_ci<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>
16421cb0ef41Sopenharmony_ci<ul>
16431cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol" class="type">&#x3C;Iterator></a></li>
16441cb0ef41Sopenharmony_ci</ul>
16451cb0ef41Sopenharmony_ci<p>Alias for <a href="#mimeparamsentries"><code>mimeParams.entries()</code></a>.</p>
16461cb0ef41Sopenharmony_ci
16471cb0ef41Sopenharmony_ci<pre class="with-42-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MIMEType</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
16481cb0ef41Sopenharmony_ci
16491cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { params } = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/plain;foo=bar;xyz=baz'</span>);
16501cb0ef41Sopenharmony_ci<span class="hljs-keyword">for</span> (<span class="hljs-keyword">const</span> [name, value] <span class="hljs-keyword">of</span> params) {
16511cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(name, value);
16521cb0ef41Sopenharmony_ci}
16531cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints:</span>
16541cb0ef41Sopenharmony_ci<span class="hljs-comment">//   foo bar</span>
16551cb0ef41Sopenharmony_ci<span class="hljs-comment">//   xyz baz</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">MIMEType</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
16561cb0ef41Sopenharmony_ci
16571cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { params } = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MIMEType</span>(<span class="hljs-string">'text/plain;foo=bar;xyz=baz'</span>);
16581cb0ef41Sopenharmony_ci<span class="hljs-keyword">for</span> (<span class="hljs-keyword">const</span> [name, value] <span class="hljs-keyword">of</span> params) {
16591cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(name, value);
16601cb0ef41Sopenharmony_ci}
16611cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints:</span>
16621cb0ef41Sopenharmony_ci<span class="hljs-comment">//   foo bar</span>
16631cb0ef41Sopenharmony_ci<span class="hljs-comment">//   xyz baz</span></code><button class="copy-button">copy</button></pre>
16641cb0ef41Sopenharmony_ci</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>
16651cb0ef41Sopenharmony_ci<div class="api_metadata">
16661cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
16671cb0ef41Sopenharmony_ci<table>
16681cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
16691cb0ef41Sopenharmony_ci<tr><td>v18.11.0</td>
16701cb0ef41Sopenharmony_ci<td><p>Add support for default values in input <code>config</code>.</p></td></tr>
16711cb0ef41Sopenharmony_ci<tr><td>v18.7.0, v16.17.0</td>
16721cb0ef41Sopenharmony_ci<td><p>add support for returning detailed parse information using <code>tokens</code> in input <code>config</code> and returned properties.</p></td></tr>
16731cb0ef41Sopenharmony_ci<tr><td>v18.3.0</td>
16741cb0ef41Sopenharmony_ci<td><p><span>Added in: v18.3.0</span></p></td></tr>
16751cb0ef41Sopenharmony_ci</tbody></table>
16761cb0ef41Sopenharmony_ci</details>
16771cb0ef41Sopenharmony_ci</div>
16781cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
16791cb0ef41Sopenharmony_ci<ul>
16801cb0ef41Sopenharmony_ci<li>
16811cb0ef41Sopenharmony_ci<p><code>config</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Used to provide arguments for parsing and to configure
16821cb0ef41Sopenharmony_cithe parser. <code>config</code> supports the following properties:</p>
16831cb0ef41Sopenharmony_ci<ul>
16841cb0ef41Sopenharmony_ci<li><code>args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> array of argument strings. <strong>Default:</strong> <code>process.argv</code>
16851cb0ef41Sopenharmony_ciwith <code>execPath</code> and <code>filename</code> removed.</li>
16861cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Used to describe arguments known to the parser.
16871cb0ef41Sopenharmony_ciKeys of <code>options</code> are the long names of options and values are an
16881cb0ef41Sopenharmony_ci<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> accepting the following properties:
16891cb0ef41Sopenharmony_ci<ul>
16901cb0ef41Sopenharmony_ci<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Type of argument, which must be either <code>boolean</code> or <code>string</code>.</li>
16911cb0ef41Sopenharmony_ci<li><code>multiple</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Whether this option can be provided multiple
16921cb0ef41Sopenharmony_citimes. If <code>true</code>, all values will be collected in an array. If
16931cb0ef41Sopenharmony_ci<code>false</code>, values for the option are last-wins. <strong>Default:</strong> <code>false</code>.</li>
16941cb0ef41Sopenharmony_ci<li><code>short</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A single character alias for the option.</li>
16951cb0ef41Sopenharmony_ci<li><code>default</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean[]></a> The default option
16961cb0ef41Sopenharmony_civalue when it is not set by args. It must be of the same type as the
16971cb0ef41Sopenharmony_ci<code>type</code> property. When <code>multiple</code> is <code>true</code>, it must be an array.</li>
16981cb0ef41Sopenharmony_ci</ul>
16991cb0ef41Sopenharmony_ci</li>
17001cb0ef41Sopenharmony_ci<li><code>strict</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Should an error be thrown when unknown arguments
17011cb0ef41Sopenharmony_ciare encountered, or when arguments are passed that do not match the
17021cb0ef41Sopenharmony_ci<code>type</code> configured in <code>options</code>.
17031cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>true</code>.</li>
17041cb0ef41Sopenharmony_ci<li><code>allowPositionals</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Whether this command accepts positional
17051cb0ef41Sopenharmony_ciarguments.
17061cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>false</code> if <code>strict</code> is <code>true</code>, otherwise <code>true</code>.</li>
17071cb0ef41Sopenharmony_ci<li><code>tokens</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Return the parsed tokens. This is useful for extending
17081cb0ef41Sopenharmony_cithe built-in behavior, from adding additional checks through to reprocessing
17091cb0ef41Sopenharmony_cithe tokens in different ways.
17101cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>false</code>.</li>
17111cb0ef41Sopenharmony_ci</ul>
17121cb0ef41Sopenharmony_ci</li>
17131cb0ef41Sopenharmony_ci<li>
17141cb0ef41Sopenharmony_ci<p>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> The parsed command line arguments:</p>
17151cb0ef41Sopenharmony_ci<ul>
17161cb0ef41Sopenharmony_ci<li><code>values</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></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">&#x3C;string></a>
17171cb0ef41Sopenharmony_cior <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> values.</li>
17181cb0ef41Sopenharmony_ci<li><code>positionals</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> Positional arguments.</li>
17191cb0ef41Sopenharmony_ci<li><code>tokens</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type">&#x3C;undefined></a> See <a href="#parseargs-tokens">parseArgs tokens</a>
17201cb0ef41Sopenharmony_cisection. Only returned if <code>config</code> includes <code>tokens: true</code>.</li>
17211cb0ef41Sopenharmony_ci</ul>
17221cb0ef41Sopenharmony_ci</li>
17231cb0ef41Sopenharmony_ci</ul>
17241cb0ef41Sopenharmony_ci<p>Provides a higher level API for command-line argument parsing than interacting
17251cb0ef41Sopenharmony_ciwith <code>process.argv</code> directly. Takes a specification for the expected arguments
17261cb0ef41Sopenharmony_ciand returns a structured object with the parsed options and positionals.</p>
17271cb0ef41Sopenharmony_ci
17281cb0ef41Sopenharmony_ci<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { parseArgs } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
17291cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> args = [<span class="hljs-string">'-f'</span>, <span class="hljs-string">'--bar'</span>, <span class="hljs-string">'b'</span>];
17301cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> options = {
17311cb0ef41Sopenharmony_ci  <span class="hljs-attr">foo</span>: {
17321cb0ef41Sopenharmony_ci    <span class="hljs-attr">type</span>: <span class="hljs-string">'boolean'</span>,
17331cb0ef41Sopenharmony_ci    <span class="hljs-attr">short</span>: <span class="hljs-string">'f'</span>,
17341cb0ef41Sopenharmony_ci  },
17351cb0ef41Sopenharmony_ci  <span class="hljs-attr">bar</span>: {
17361cb0ef41Sopenharmony_ci    <span class="hljs-attr">type</span>: <span class="hljs-string">'string'</span>,
17371cb0ef41Sopenharmony_ci  },
17381cb0ef41Sopenharmony_ci};
17391cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> {
17401cb0ef41Sopenharmony_ci  values,
17411cb0ef41Sopenharmony_ci  positionals,
17421cb0ef41Sopenharmony_ci} = <span class="hljs-title function_">parseArgs</span>({ args, options });
17431cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(values, positionals);
17441cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: [Object: null prototype] { foo: true, bar: 'b' } []</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { parseArgs } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
17451cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> args = [<span class="hljs-string">'-f'</span>, <span class="hljs-string">'--bar'</span>, <span class="hljs-string">'b'</span>];
17461cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> options = {
17471cb0ef41Sopenharmony_ci  <span class="hljs-attr">foo</span>: {
17481cb0ef41Sopenharmony_ci    <span class="hljs-attr">type</span>: <span class="hljs-string">'boolean'</span>,
17491cb0ef41Sopenharmony_ci    <span class="hljs-attr">short</span>: <span class="hljs-string">'f'</span>,
17501cb0ef41Sopenharmony_ci  },
17511cb0ef41Sopenharmony_ci  <span class="hljs-attr">bar</span>: {
17521cb0ef41Sopenharmony_ci    <span class="hljs-attr">type</span>: <span class="hljs-string">'string'</span>,
17531cb0ef41Sopenharmony_ci  },
17541cb0ef41Sopenharmony_ci};
17551cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> {
17561cb0ef41Sopenharmony_ci  values,
17571cb0ef41Sopenharmony_ci  positionals,
17581cb0ef41Sopenharmony_ci} = <span class="hljs-title function_">parseArgs</span>({ args, options });
17591cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(values, positionals);
17601cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints: [Object: null prototype] { foo: true, bar: 'b' } []</span></code><button class="copy-button">copy</button></pre>
17611cb0ef41Sopenharmony_ci<p><code>util.parseArgs</code> is experimental and behavior may change. Join the
17621cb0ef41Sopenharmony_ciconversation in <a href="https://github.com/pkgjs/parseargs">pkgjs/parseargs</a> to contribute to the design.</p>
17631cb0ef41Sopenharmony_ci<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>
17641cb0ef41Sopenharmony_ci<p>Detailed parse information is available for adding custom behaviors by
17651cb0ef41Sopenharmony_cispecifying <code>tokens: true</code> in the configuration.
17661cb0ef41Sopenharmony_ciThe returned tokens have properties describing:</p>
17671cb0ef41Sopenharmony_ci<ul>
17681cb0ef41Sopenharmony_ci<li>all tokens
17691cb0ef41Sopenharmony_ci<ul>
17701cb0ef41Sopenharmony_ci<li><code>kind</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> One of 'option', 'positional', or 'option-terminator'.</li>
17711cb0ef41Sopenharmony_ci<li><code>index</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> Index of element in <code>args</code> containing token. So the
17721cb0ef41Sopenharmony_cisource argument for a token is <code>args[token.index]</code>.</li>
17731cb0ef41Sopenharmony_ci</ul>
17741cb0ef41Sopenharmony_ci</li>
17751cb0ef41Sopenharmony_ci<li>option tokens
17761cb0ef41Sopenharmony_ci<ul>
17771cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Long name of option.</li>
17781cb0ef41Sopenharmony_ci<li><code>rawName</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> How option used in args, like <code>-f</code> of <code>--foo</code>.</li>
17791cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type">&#x3C;undefined></a> Option value specified in args.
17801cb0ef41Sopenharmony_ciUndefined for boolean options.</li>
17811cb0ef41Sopenharmony_ci<li><code>inlineValue</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type">&#x3C;undefined></a> Whether option value specified inline,
17821cb0ef41Sopenharmony_cilike <code>--foo=bar</code>.</li>
17831cb0ef41Sopenharmony_ci</ul>
17841cb0ef41Sopenharmony_ci</li>
17851cb0ef41Sopenharmony_ci<li>positional tokens
17861cb0ef41Sopenharmony_ci<ul>
17871cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The value of the positional argument in args (i.e. <code>args[index]</code>).</li>
17881cb0ef41Sopenharmony_ci</ul>
17891cb0ef41Sopenharmony_ci</li>
17901cb0ef41Sopenharmony_ci<li>option-terminator token</li>
17911cb0ef41Sopenharmony_ci</ul>
17921cb0ef41Sopenharmony_ci<p>The returned tokens are in the order encountered in the input args. Options
17931cb0ef41Sopenharmony_cithat appear more than once in args produce a token for each use. Short option
17941cb0ef41Sopenharmony_cigroups like <code>-xy</code> expand to a token for each option. So <code>-xxx</code> produces
17951cb0ef41Sopenharmony_cithree tokens.</p>
17961cb0ef41Sopenharmony_ci<p>For example to use the returned tokens to add support for a negated option
17971cb0ef41Sopenharmony_cilike <code>--no-color</code>, the tokens can be reprocessed to change the value stored
17981cb0ef41Sopenharmony_cifor the negated option.</p>
17991cb0ef41Sopenharmony_ci
18001cb0ef41Sopenharmony_ci<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { parseArgs } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
18011cb0ef41Sopenharmony_ci
18021cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> options = {
18031cb0ef41Sopenharmony_ci  <span class="hljs-string">'color'</span>: { <span class="hljs-attr">type</span>: <span class="hljs-string">'boolean'</span> },
18041cb0ef41Sopenharmony_ci  <span class="hljs-string">'no-color'</span>: { <span class="hljs-attr">type</span>: <span class="hljs-string">'boolean'</span> },
18051cb0ef41Sopenharmony_ci  <span class="hljs-string">'logfile'</span>: { <span class="hljs-attr">type</span>: <span class="hljs-string">'string'</span> },
18061cb0ef41Sopenharmony_ci  <span class="hljs-string">'no-logfile'</span>: { <span class="hljs-attr">type</span>: <span class="hljs-string">'boolean'</span> },
18071cb0ef41Sopenharmony_ci};
18081cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { values, tokens } = <span class="hljs-title function_">parseArgs</span>({ options, <span class="hljs-attr">tokens</span>: <span class="hljs-literal">true</span> });
18091cb0ef41Sopenharmony_ci
18101cb0ef41Sopenharmony_ci<span class="hljs-comment">// Reprocess the option tokens and overwrite the returned values.</span>
18111cb0ef41Sopenharmony_citokens
18121cb0ef41Sopenharmony_ci  .<span class="hljs-title function_">filter</span>(<span class="hljs-function">(<span class="hljs-params">token</span>) =></span> token.<span class="hljs-property">kind</span> === <span class="hljs-string">'option'</span>)
18131cb0ef41Sopenharmony_ci  .<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">token</span>) =></span> {
18141cb0ef41Sopenharmony_ci    <span class="hljs-keyword">if</span> (token.<span class="hljs-property">name</span>.<span class="hljs-title function_">startsWith</span>(<span class="hljs-string">'no-'</span>)) {
18151cb0ef41Sopenharmony_ci      <span class="hljs-comment">// Store foo:false for --no-foo</span>
18161cb0ef41Sopenharmony_ci      <span class="hljs-keyword">const</span> positiveName = token.<span class="hljs-property">name</span>.<span class="hljs-title function_">slice</span>(<span class="hljs-number">3</span>);
18171cb0ef41Sopenharmony_ci      values[positiveName] = <span class="hljs-literal">false</span>;
18181cb0ef41Sopenharmony_ci      <span class="hljs-keyword">delete</span> values[token.<span class="hljs-property">name</span>];
18191cb0ef41Sopenharmony_ci    } <span class="hljs-keyword">else</span> {
18201cb0ef41Sopenharmony_ci      <span class="hljs-comment">// Resave value so last one wins if both --foo and --no-foo.</span>
18211cb0ef41Sopenharmony_ci      values[token.<span class="hljs-property">name</span>] = token.<span class="hljs-property">value</span> ?? <span class="hljs-literal">true</span>;
18221cb0ef41Sopenharmony_ci    }
18231cb0ef41Sopenharmony_ci  });
18241cb0ef41Sopenharmony_ci
18251cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> color = values.<span class="hljs-property">color</span>;
18261cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> logfile = values.<span class="hljs-property">logfile</span> ?? <span class="hljs-string">'default.log'</span>;
18271cb0ef41Sopenharmony_ci
18281cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>({ logfile, color });</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { parseArgs } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
18291cb0ef41Sopenharmony_ci
18301cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> options = {
18311cb0ef41Sopenharmony_ci  <span class="hljs-string">'color'</span>: { <span class="hljs-attr">type</span>: <span class="hljs-string">'boolean'</span> },
18321cb0ef41Sopenharmony_ci  <span class="hljs-string">'no-color'</span>: { <span class="hljs-attr">type</span>: <span class="hljs-string">'boolean'</span> },
18331cb0ef41Sopenharmony_ci  <span class="hljs-string">'logfile'</span>: { <span class="hljs-attr">type</span>: <span class="hljs-string">'string'</span> },
18341cb0ef41Sopenharmony_ci  <span class="hljs-string">'no-logfile'</span>: { <span class="hljs-attr">type</span>: <span class="hljs-string">'boolean'</span> },
18351cb0ef41Sopenharmony_ci};
18361cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { values, tokens } = <span class="hljs-title function_">parseArgs</span>({ options, <span class="hljs-attr">tokens</span>: <span class="hljs-literal">true</span> });
18371cb0ef41Sopenharmony_ci
18381cb0ef41Sopenharmony_ci<span class="hljs-comment">// Reprocess the option tokens and overwrite the returned values.</span>
18391cb0ef41Sopenharmony_citokens
18401cb0ef41Sopenharmony_ci  .<span class="hljs-title function_">filter</span>(<span class="hljs-function">(<span class="hljs-params">token</span>) =></span> token.<span class="hljs-property">kind</span> === <span class="hljs-string">'option'</span>)
18411cb0ef41Sopenharmony_ci  .<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">token</span>) =></span> {
18421cb0ef41Sopenharmony_ci    <span class="hljs-keyword">if</span> (token.<span class="hljs-property">name</span>.<span class="hljs-title function_">startsWith</span>(<span class="hljs-string">'no-'</span>)) {
18431cb0ef41Sopenharmony_ci      <span class="hljs-comment">// Store foo:false for --no-foo</span>
18441cb0ef41Sopenharmony_ci      <span class="hljs-keyword">const</span> positiveName = token.<span class="hljs-property">name</span>.<span class="hljs-title function_">slice</span>(<span class="hljs-number">3</span>);
18451cb0ef41Sopenharmony_ci      values[positiveName] = <span class="hljs-literal">false</span>;
18461cb0ef41Sopenharmony_ci      <span class="hljs-keyword">delete</span> values[token.<span class="hljs-property">name</span>];
18471cb0ef41Sopenharmony_ci    } <span class="hljs-keyword">else</span> {
18481cb0ef41Sopenharmony_ci      <span class="hljs-comment">// Resave value so last one wins if both --foo and --no-foo.</span>
18491cb0ef41Sopenharmony_ci      values[token.<span class="hljs-property">name</span>] = token.<span class="hljs-property">value</span> ?? <span class="hljs-literal">true</span>;
18501cb0ef41Sopenharmony_ci    }
18511cb0ef41Sopenharmony_ci  });
18521cb0ef41Sopenharmony_ci
18531cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> color = values.<span class="hljs-property">color</span>;
18541cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> logfile = values.<span class="hljs-property">logfile</span> ?? <span class="hljs-string">'default.log'</span>;
18551cb0ef41Sopenharmony_ci
18561cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>({ logfile, color });</code><button class="copy-button">copy</button></pre>
18571cb0ef41Sopenharmony_ci<p>Example usage showing negated options, and when an option is used
18581cb0ef41Sopenharmony_cimultiple ways then last one wins.</p>
18591cb0ef41Sopenharmony_ci<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node negate.js</span>
18601cb0ef41Sopenharmony_ci{ logfile: 'default.log', color: undefined }
18611cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">$ </span><span class="language-bash">node negate.js --no-logfile --no-color</span>
18621cb0ef41Sopenharmony_ci{ logfile: false, color: false }
18631cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">$ </span><span class="language-bash">node negate.js --logfile=test.log --color</span>
18641cb0ef41Sopenharmony_ci{ logfile: 'test.log', color: true }
18651cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">$ </span><span class="language-bash">node negate.js --no-logfile --logfile=test.log --color --no-color</span>
18661cb0ef41Sopenharmony_ci{ logfile: 'test.log', color: false }</code> <button class="copy-button">copy</button></pre>
18671cb0ef41Sopenharmony_ci</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>
18681cb0ef41Sopenharmony_ci<div class="api_metadata">
18691cb0ef41Sopenharmony_ci<span>Added in: v8.0.0</span>
18701cb0ef41Sopenharmony_ci</div>
18711cb0ef41Sopenharmony_ci<ul>
18721cb0ef41Sopenharmony_ci<li><code>original</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
18731cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
18741cb0ef41Sopenharmony_ci</ul>
18751cb0ef41Sopenharmony_ci<p>Takes a function following the common error-first callback style, i.e. taking
18761cb0ef41Sopenharmony_cian <code>(err, value) => ...</code> callback as the last argument, and returns a version
18771cb0ef41Sopenharmony_cithat returns promises.</p>
18781cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
18791cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>);
18801cb0ef41Sopenharmony_ci
18811cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stat = util.<span class="hljs-title function_">promisify</span>(fs.<span class="hljs-property">stat</span>);
18821cb0ef41Sopenharmony_ci<span class="hljs-title function_">stat</span>(<span class="hljs-string">'.'</span>).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">stats</span>) =></span> {
18831cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Do something with `stats`</span>
18841cb0ef41Sopenharmony_ci}).<span class="hljs-title function_">catch</span>(<span class="hljs-function">(<span class="hljs-params">error</span>) =></span> {
18851cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Handle the error.</span>
18861cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
18871cb0ef41Sopenharmony_ci<p>Or, equivalently using <code>async function</code>s:</p>
18881cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
18891cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>);
18901cb0ef41Sopenharmony_ci
18911cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stat = util.<span class="hljs-title function_">promisify</span>(fs.<span class="hljs-property">stat</span>);
18921cb0ef41Sopenharmony_ci
18931cb0ef41Sopenharmony_ci<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">callStat</span>(<span class="hljs-params"></span>) {
18941cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> stats = <span class="hljs-keyword">await</span> <span class="hljs-title function_">stat</span>(<span class="hljs-string">'.'</span>);
18951cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`This directory is owned by <span class="hljs-subst">${stats.uid}</span>`</span>);
18961cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
18971cb0ef41Sopenharmony_ci<p>If there is an <code>original[util.promisify.custom]</code> property present, <code>promisify</code>
18981cb0ef41Sopenharmony_ciwill return its value, see <a href="#custom-promisified-functions">Custom promisified functions</a>.</p>
18991cb0ef41Sopenharmony_ci<p><code>promisify()</code> assumes that <code>original</code> is a function taking a callback as its
19001cb0ef41Sopenharmony_cifinal argument in all cases. If <code>original</code> is not a function, <code>promisify()</code>
19011cb0ef41Sopenharmony_ciwill throw an error. If <code>original</code> is a function but its last argument is not
19021cb0ef41Sopenharmony_cian error-first callback, it will still be passed an error-first
19031cb0ef41Sopenharmony_cicallback as its last argument.</p>
19041cb0ef41Sopenharmony_ci<p>Using <code>promisify()</code> on class methods or other methods that use <code>this</code> may not
19051cb0ef41Sopenharmony_ciwork as expected unless handled specially:</p>
19061cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
19071cb0ef41Sopenharmony_ci
19081cb0ef41Sopenharmony_ci<span class="hljs-keyword">class</span> <span class="hljs-title class_">Foo</span> {
19091cb0ef41Sopenharmony_ci  <span class="hljs-title function_">constructor</span>(<span class="hljs-params"></span>) {
19101cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">this</span>.<span class="hljs-property">a</span> = <span class="hljs-number">42</span>;
19111cb0ef41Sopenharmony_ci  }
19121cb0ef41Sopenharmony_ci
19131cb0ef41Sopenharmony_ci  <span class="hljs-title function_">bar</span>(<span class="hljs-params">callback</span>) {
19141cb0ef41Sopenharmony_ci    <span class="hljs-title function_">callback</span>(<span class="hljs-literal">null</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">a</span>);
19151cb0ef41Sopenharmony_ci  }
19161cb0ef41Sopenharmony_ci}
19171cb0ef41Sopenharmony_ci
19181cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> foo = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Foo</span>();
19191cb0ef41Sopenharmony_ci
19201cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> naiveBar = util.<span class="hljs-title function_">promisify</span>(foo.<span class="hljs-property">bar</span>);
19211cb0ef41Sopenharmony_ci<span class="hljs-comment">// TypeError: Cannot read property 'a' of undefined</span>
19221cb0ef41Sopenharmony_ci<span class="hljs-comment">// naiveBar().then(a => console.log(a));</span>
19231cb0ef41Sopenharmony_ci
19241cb0ef41Sopenharmony_cinaiveBar.<span class="hljs-title function_">call</span>(foo).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">a</span>) =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(a)); <span class="hljs-comment">// '42'</span>
19251cb0ef41Sopenharmony_ci
19261cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> bindBar = naiveBar.<span class="hljs-title function_">bind</span>(foo);
19271cb0ef41Sopenharmony_ci<span class="hljs-title function_">bindBar</span>().<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">a</span>) =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(a)); <span class="hljs-comment">// '42'</span></code> <button class="copy-button">copy</button></pre>
19281cb0ef41Sopenharmony_ci<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>
19291cb0ef41Sopenharmony_ci<p>Using the <code>util.promisify.custom</code> symbol one can override the return value of
19301cb0ef41Sopenharmony_ci<a href="#utilpromisifyoriginal"><code>util.promisify()</code></a>:</p>
19311cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
19321cb0ef41Sopenharmony_ci
19331cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">doSomething</span>(<span class="hljs-params">foo, callback</span>) {
19341cb0ef41Sopenharmony_ci  <span class="hljs-comment">// ...</span>
19351cb0ef41Sopenharmony_ci}
19361cb0ef41Sopenharmony_ci
19371cb0ef41Sopenharmony_cidoSomething[util.<span class="hljs-property">promisify</span>.<span class="hljs-property">custom</span>] = <span class="hljs-function">(<span class="hljs-params">foo</span>) =></span> {
19381cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> <span class="hljs-title function_">getPromiseSomehow</span>();
19391cb0ef41Sopenharmony_ci};
19401cb0ef41Sopenharmony_ci
19411cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> promisified = util.<span class="hljs-title function_">promisify</span>(doSomething);
19421cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(promisified === doSomething[util.<span class="hljs-property">promisify</span>.<span class="hljs-property">custom</span>]);
19431cb0ef41Sopenharmony_ci<span class="hljs-comment">// prints 'true'</span></code> <button class="copy-button">copy</button></pre>
19441cb0ef41Sopenharmony_ci<p>This can be useful for cases where the original function does not follow the
19451cb0ef41Sopenharmony_cistandard format of taking an error-first callback as the last argument.</p>
19461cb0ef41Sopenharmony_ci<p>For example, with a function that takes in
19471cb0ef41Sopenharmony_ci<code>(foo, onSuccessCallback, onErrorCallback)</code>:</p>
19481cb0ef41Sopenharmony_ci<pre><code class="language-js">doSomething[util.<span class="hljs-property">promisify</span>.<span class="hljs-property">custom</span>] = <span class="hljs-function">(<span class="hljs-params">foo</span>) =></span> {
19491cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =></span> {
19501cb0ef41Sopenharmony_ci    <span class="hljs-title function_">doSomething</span>(foo, resolve, reject);
19511cb0ef41Sopenharmony_ci  });
19521cb0ef41Sopenharmony_ci};</code> <button class="copy-button">copy</button></pre>
19531cb0ef41Sopenharmony_ci<p>If <code>promisify.custom</code> is defined but is not a function, <code>promisify()</code> will
19541cb0ef41Sopenharmony_cithrow an error.</p>
19551cb0ef41Sopenharmony_ci<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>
19561cb0ef41Sopenharmony_ci<div class="api_metadata">
19571cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
19581cb0ef41Sopenharmony_ci<table>
19591cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
19601cb0ef41Sopenharmony_ci<tr><td>v13.12.0, v12.16.2</td>
19611cb0ef41Sopenharmony_ci<td><p>This is now defined as a shared symbol.</p></td></tr>
19621cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
19631cb0ef41Sopenharmony_ci<td><p><span>Added in: v8.0.0</span></p></td></tr>
19641cb0ef41Sopenharmony_ci</tbody></table>
19651cb0ef41Sopenharmony_ci</details>
19661cb0ef41Sopenharmony_ci</div>
19671cb0ef41Sopenharmony_ci<ul>
19681cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&#x3C;symbol></a> that can be used to declare custom promisified variants of functions,
19691cb0ef41Sopenharmony_cisee <a href="#custom-promisified-functions">Custom promisified functions</a>.</li>
19701cb0ef41Sopenharmony_ci</ul>
19711cb0ef41Sopenharmony_ci<p>In addition to being accessible through <code>util.promisify.custom</code>, this
19721cb0ef41Sopenharmony_cisymbol is <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for">registered globally</a> and can be
19731cb0ef41Sopenharmony_ciaccessed in any environment as <code>Symbol.for('nodejs.util.promisify.custom')</code>.</p>
19741cb0ef41Sopenharmony_ci<p>For example, with a function that takes in
19751cb0ef41Sopenharmony_ci<code>(foo, onSuccessCallback, onErrorCallback)</code>:</p>
19761cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> kCustomPromisifiedSymbol = <span class="hljs-title class_">Symbol</span>.<span class="hljs-title function_">for</span>(<span class="hljs-string">'nodejs.util.promisify.custom'</span>);
19771cb0ef41Sopenharmony_ci
19781cb0ef41Sopenharmony_cidoSomething[kCustomPromisifiedSymbol] = <span class="hljs-function">(<span class="hljs-params">foo</span>) =></span> {
19791cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =></span> {
19801cb0ef41Sopenharmony_ci    <span class="hljs-title function_">doSomething</span>(foo, resolve, reject);
19811cb0ef41Sopenharmony_ci  });
19821cb0ef41Sopenharmony_ci};</code> <button class="copy-button">copy</button></pre>
19831cb0ef41Sopenharmony_ci</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>
19841cb0ef41Sopenharmony_ci<div class="api_metadata">
19851cb0ef41Sopenharmony_ci<span>Added in: v16.11.0</span>
19861cb0ef41Sopenharmony_ci</div>
19871cb0ef41Sopenharmony_ci<ul>
19881cb0ef41Sopenharmony_ci<li><code>str</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
19891cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
19901cb0ef41Sopenharmony_ci</ul>
19911cb0ef41Sopenharmony_ci<p>Returns <code>str</code> with any ANSI escape codes removed.</p>
19921cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(util.<span class="hljs-title function_">stripVTControlCharacters</span>(<span class="hljs-string">'\u001B[4mvalue\u001B[0m'</span>));
19931cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints "value"</span></code> <button class="copy-button">copy</button></pre>
19941cb0ef41Sopenharmony_ci</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>
19951cb0ef41Sopenharmony_ci<div class="api_metadata">
19961cb0ef41Sopenharmony_ci<span>Added in: v8.3.0</span>
19971cb0ef41Sopenharmony_ci</div>
19981cb0ef41Sopenharmony_ci<p>An implementation of the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a> <code>TextDecoder</code> API.</p>
19991cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> decoder = <span class="hljs-keyword">new</span> <span class="hljs-title class_">TextDecoder</span>();
20001cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> u8arr = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Uint8Array</span>([<span class="hljs-number">72</span>, <span class="hljs-number">101</span>, <span class="hljs-number">108</span>, <span class="hljs-number">108</span>, <span class="hljs-number">111</span>]);
20011cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(decoder.<span class="hljs-title function_">decode</span>(u8arr)); <span class="hljs-comment">// Hello</span></code> <button class="copy-button">copy</button></pre>
20021cb0ef41Sopenharmony_ci<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>
20031cb0ef41Sopenharmony_ci<p>Per the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a>, the encodings supported by the
20041cb0ef41Sopenharmony_ci<code>TextDecoder</code> API are outlined in the tables below. For each encoding,
20051cb0ef41Sopenharmony_cione or more aliases may be used.</p>
20061cb0ef41Sopenharmony_ci<p>Different Node.js build configurations support different sets of encodings.
20071cb0ef41Sopenharmony_ci(see <a href="intl.html">Internationalization</a>)</p>
20081cb0ef41Sopenharmony_ci<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>
20091cb0ef41Sopenharmony_ci
20101cb0ef41Sopenharmony_ci
20111cb0ef41Sopenharmony_ci
20121cb0ef41Sopenharmony_ci
20131cb0ef41Sopenharmony_ci
20141cb0ef41Sopenharmony_ci
20151cb0ef41Sopenharmony_ci
20161cb0ef41Sopenharmony_ci
20171cb0ef41Sopenharmony_ci
20181cb0ef41Sopenharmony_ci
20191cb0ef41Sopenharmony_ci
20201cb0ef41Sopenharmony_ci
20211cb0ef41Sopenharmony_ci
20221cb0ef41Sopenharmony_ci
20231cb0ef41Sopenharmony_ci
20241cb0ef41Sopenharmony_ci
20251cb0ef41Sopenharmony_ci
20261cb0ef41Sopenharmony_ci
20271cb0ef41Sopenharmony_ci
20281cb0ef41Sopenharmony_ci
20291cb0ef41Sopenharmony_ci
20301cb0ef41Sopenharmony_ci
20311cb0ef41Sopenharmony_ci
20321cb0ef41Sopenharmony_ci
20331cb0ef41Sopenharmony_ci
20341cb0ef41Sopenharmony_ci
20351cb0ef41Sopenharmony_ci
20361cb0ef41Sopenharmony_ci
20371cb0ef41Sopenharmony_ci
20381cb0ef41Sopenharmony_ci
20391cb0ef41Sopenharmony_ci
20401cb0ef41Sopenharmony_ci
20411cb0ef41Sopenharmony_ci
20421cb0ef41Sopenharmony_ci
20431cb0ef41Sopenharmony_ci
20441cb0ef41Sopenharmony_ci
20451cb0ef41Sopenharmony_ci
20461cb0ef41Sopenharmony_ci
20471cb0ef41Sopenharmony_ci
20481cb0ef41Sopenharmony_ci
20491cb0ef41Sopenharmony_ci
20501cb0ef41Sopenharmony_ci
20511cb0ef41Sopenharmony_ci
20521cb0ef41Sopenharmony_ci
20531cb0ef41Sopenharmony_ci
20541cb0ef41Sopenharmony_ci
20551cb0ef41Sopenharmony_ci
20561cb0ef41Sopenharmony_ci
20571cb0ef41Sopenharmony_ci
20581cb0ef41Sopenharmony_ci
20591cb0ef41Sopenharmony_ci
20601cb0ef41Sopenharmony_ci
20611cb0ef41Sopenharmony_ci
20621cb0ef41Sopenharmony_ci
20631cb0ef41Sopenharmony_ci
20641cb0ef41Sopenharmony_ci
20651cb0ef41Sopenharmony_ci
20661cb0ef41Sopenharmony_ci
20671cb0ef41Sopenharmony_ci
20681cb0ef41Sopenharmony_ci
20691cb0ef41Sopenharmony_ci
20701cb0ef41Sopenharmony_ci
20711cb0ef41Sopenharmony_ci
20721cb0ef41Sopenharmony_ci
20731cb0ef41Sopenharmony_ci
20741cb0ef41Sopenharmony_ci
20751cb0ef41Sopenharmony_ci
20761cb0ef41Sopenharmony_ci
20771cb0ef41Sopenharmony_ci
20781cb0ef41Sopenharmony_ci
20791cb0ef41Sopenharmony_ci
20801cb0ef41Sopenharmony_ci
20811cb0ef41Sopenharmony_ci
20821cb0ef41Sopenharmony_ci
20831cb0ef41Sopenharmony_ci
20841cb0ef41Sopenharmony_ci
20851cb0ef41Sopenharmony_ci
20861cb0ef41Sopenharmony_ci
20871cb0ef41Sopenharmony_ci
20881cb0ef41Sopenharmony_ci
20891cb0ef41Sopenharmony_ci
20901cb0ef41Sopenharmony_ci
20911cb0ef41Sopenharmony_ci
20921cb0ef41Sopenharmony_ci
20931cb0ef41Sopenharmony_ci
20941cb0ef41Sopenharmony_ci
20951cb0ef41Sopenharmony_ci
20961cb0ef41Sopenharmony_ci
20971cb0ef41Sopenharmony_ci
20981cb0ef41Sopenharmony_ci
20991cb0ef41Sopenharmony_ci
21001cb0ef41Sopenharmony_ci
21011cb0ef41Sopenharmony_ci
21021cb0ef41Sopenharmony_ci
21031cb0ef41Sopenharmony_ci
21041cb0ef41Sopenharmony_ci
21051cb0ef41Sopenharmony_ci
21061cb0ef41Sopenharmony_ci
21071cb0ef41Sopenharmony_ci
21081cb0ef41Sopenharmony_ci
21091cb0ef41Sopenharmony_ci
21101cb0ef41Sopenharmony_ci
21111cb0ef41Sopenharmony_ci
21121cb0ef41Sopenharmony_ci
21131cb0ef41Sopenharmony_ci
21141cb0ef41Sopenharmony_ci
21151cb0ef41Sopenharmony_ci
21161cb0ef41Sopenharmony_ci
21171cb0ef41Sopenharmony_ci
21181cb0ef41Sopenharmony_ci
21191cb0ef41Sopenharmony_ci
21201cb0ef41Sopenharmony_ci
21211cb0ef41Sopenharmony_ci
21221cb0ef41Sopenharmony_ci
21231cb0ef41Sopenharmony_ci
21241cb0ef41Sopenharmony_ci
21251cb0ef41Sopenharmony_ci
21261cb0ef41Sopenharmony_ci
21271cb0ef41Sopenharmony_ci
21281cb0ef41Sopenharmony_ci
21291cb0ef41Sopenharmony_ci
21301cb0ef41Sopenharmony_ci
21311cb0ef41Sopenharmony_ci
21321cb0ef41Sopenharmony_ci
21331cb0ef41Sopenharmony_ci
21341cb0ef41Sopenharmony_ci
21351cb0ef41Sopenharmony_ci
21361cb0ef41Sopenharmony_ci
21371cb0ef41Sopenharmony_ci
21381cb0ef41Sopenharmony_ci
21391cb0ef41Sopenharmony_ci
21401cb0ef41Sopenharmony_ci
21411cb0ef41Sopenharmony_ci
21421cb0ef41Sopenharmony_ci
21431cb0ef41Sopenharmony_ci
21441cb0ef41Sopenharmony_ci
21451cb0ef41Sopenharmony_ci
21461cb0ef41Sopenharmony_ci
21471cb0ef41Sopenharmony_ci
21481cb0ef41Sopenharmony_ci
21491cb0ef41Sopenharmony_ci
21501cb0ef41Sopenharmony_ci
21511cb0ef41Sopenharmony_ci
21521cb0ef41Sopenharmony_ci
21531cb0ef41Sopenharmony_ci
21541cb0ef41Sopenharmony_ci<table><thead><tr><th>Encoding</th><th>Aliases</th></tr></thead><tbody><tr><td><code>'ibm866'</code></td><td><code>'866'</code>, <code>'cp866'</code>, <code>'csibm866'</code></td></tr><tr><td><code>'iso-8859-2'</code></td><td><code>'csisolatin2'</code>, <code>'iso-ir-101'</code>, <code>'iso8859-2'</code>, <code>'iso88592'</code>, <code>'iso_8859-2'</code>, <code>'iso_8859-2:1987'</code>, <code>'l2'</code>, <code>'latin2'</code></td></tr><tr><td><code>'iso-8859-3'</code></td><td><code>'csisolatin3'</code>, <code>'iso-ir-109'</code>, <code>'iso8859-3'</code>, <code>'iso88593'</code>, <code>'iso_8859-3'</code>, <code>'iso_8859-3:1988'</code>, <code>'l3'</code>, <code>'latin3'</code></td></tr><tr><td><code>'iso-8859-4'</code></td><td><code>'csisolatin4'</code>, <code>'iso-ir-110'</code>, <code>'iso8859-4'</code>, <code>'iso88594'</code>, <code>'iso_8859-4'</code>, <code>'iso_8859-4:1988'</code>, <code>'l4'</code>, <code>'latin4'</code></td></tr><tr><td><code>'iso-8859-5'</code></td><td><code>'csisolatincyrillic'</code>, <code>'cyrillic'</code>, <code>'iso-ir-144'</code>, <code>'iso8859-5'</code>, <code>'iso88595'</code>, <code>'iso_8859-5'</code>, <code>'iso_8859-5:1988'</code></td></tr><tr><td><code>'iso-8859-6'</code></td><td><code>'arabic'</code>, <code>'asmo-708'</code>, <code>'csiso88596e'</code>, <code>'csiso88596i'</code>, <code>'csisolatinarabic'</code>, <code>'ecma-114'</code>, <code>'iso-8859-6-e'</code>, <code>'iso-8859-6-i'</code>, <code>'iso-ir-127'</code>, <code>'iso8859-6'</code>, <code>'iso88596'</code>, <code>'iso_8859-6'</code>, <code>'iso_8859-6:1987'</code></td></tr><tr><td><code>'iso-8859-7'</code></td><td><code>'csisolatingreek'</code>, <code>'ecma-118'</code>, <code>'elot_928'</code>, <code>'greek'</code>, <code>'greek8'</code>, <code>'iso-ir-126'</code>, <code>'iso8859-7'</code>, <code>'iso88597'</code>, <code>'iso_8859-7'</code>, <code>'iso_8859-7:1987'</code>, <code>'sun_eu_greek'</code></td></tr><tr><td><code>'iso-8859-8'</code></td><td><code>'csiso88598e'</code>, <code>'csisolatinhebrew'</code>, <code>'hebrew'</code>, <code>'iso-8859-8-e'</code>, <code>'iso-ir-138'</code>, <code>'iso8859-8'</code>, <code>'iso88598'</code>, <code>'iso_8859-8'</code>, <code>'iso_8859-8:1988'</code>, <code>'visual'</code></td></tr><tr><td><code>'iso-8859-8-i'</code></td><td><code>'csiso88598i'</code>, <code>'logical'</code></td></tr><tr><td><code>'iso-8859-10'</code></td><td><code>'csisolatin6'</code>, <code>'iso-ir-157'</code>, <code>'iso8859-10'</code>, <code>'iso885910'</code>, <code>'l6'</code>, <code>'latin6'</code></td></tr><tr><td><code>'iso-8859-13'</code></td><td><code>'iso8859-13'</code>, <code>'iso885913'</code></td></tr><tr><td><code>'iso-8859-14'</code></td><td><code>'iso8859-14'</code>, <code>'iso885914'</code></td></tr><tr><td><code>'iso-8859-15'</code></td><td><code>'csisolatin9'</code>, <code>'iso8859-15'</code>, <code>'iso885915'</code>, <code>'iso_8859-15'</code>, <code>'l9'</code></td></tr><tr><td><code>'koi8-r'</code></td><td><code>'cskoi8r'</code>, <code>'koi'</code>, <code>'koi8'</code>, <code>'koi8_r'</code></td></tr><tr><td><code>'koi8-u'</code></td><td><code>'koi8-ru'</code></td></tr><tr><td><code>'macintosh'</code></td><td><code>'csmacintosh'</code>, <code>'mac'</code>, <code>'x-mac-roman'</code></td></tr><tr><td><code>'windows-874'</code></td><td><code>'dos-874'</code>, <code>'iso-8859-11'</code>, <code>'iso8859-11'</code>, <code>'iso885911'</code>, <code>'tis-620'</code></td></tr><tr><td><code>'windows-1250'</code></td><td><code>'cp1250'</code>, <code>'x-cp1250'</code></td></tr><tr><td><code>'windows-1251'</code></td><td><code>'cp1251'</code>, <code>'x-cp1251'</code></td></tr><tr><td><code>'windows-1252'</code></td><td><code>'ansi_x3.4-1968'</code>, <code>'ascii'</code>, <code>'cp1252'</code>, <code>'cp819'</code>, <code>'csisolatin1'</code>, <code>'ibm819'</code>, <code>'iso-8859-1'</code>, <code>'iso-ir-100'</code>, <code>'iso8859-1'</code>, <code>'iso88591'</code>, <code>'iso_8859-1'</code>, <code>'iso_8859-1:1987'</code>, <code>'l1'</code>, <code>'latin1'</code>, <code>'us-ascii'</code>, <code>'x-cp1252'</code></td></tr><tr><td><code>'windows-1253'</code></td><td><code>'cp1253'</code>, <code>'x-cp1253'</code></td></tr><tr><td><code>'windows-1254'</code></td><td><code>'cp1254'</code>, <code>'csisolatin5'</code>, <code>'iso-8859-9'</code>, <code>'iso-ir-148'</code>, <code>'iso8859-9'</code>, <code>'iso88599'</code>, <code>'iso_8859-9'</code>, <code>'iso_8859-9:1989'</code>, <code>'l5'</code>, <code>'latin5'</code>, <code>'x-cp1254'</code></td></tr><tr><td><code>'windows-1255'</code></td><td><code>'cp1255'</code>, <code>'x-cp1255'</code></td></tr><tr><td><code>'windows-1256'</code></td><td><code>'cp1256'</code>, <code>'x-cp1256'</code></td></tr><tr><td><code>'windows-1257'</code></td><td><code>'cp1257'</code>, <code>'x-cp1257'</code></td></tr><tr><td><code>'windows-1258'</code></td><td><code>'cp1258'</code>, <code>'x-cp1258'</code></td></tr><tr><td><code>'x-mac-cyrillic'</code></td><td><code>'x-mac-ukrainian'</code></td></tr><tr><td><code>'gbk'</code></td><td><code>'chinese'</code>, <code>'csgb2312'</code>, <code>'csiso58gb231280'</code>, <code>'gb2312'</code>, <code>'gb_2312'</code>, <code>'gb_2312-80'</code>, <code>'iso-ir-58'</code>, <code>'x-gbk'</code></td></tr><tr><td><code>'gb18030'</code></td><td></td></tr><tr><td><code>'big5'</code></td><td><code>'big5-hkscs'</code>, <code>'cn-big5'</code>, <code>'csbig5'</code>, <code>'x-x-big5'</code></td></tr><tr><td><code>'euc-jp'</code></td><td><code>'cseucpkdfmtjapanese'</code>, <code>'x-euc-jp'</code></td></tr><tr><td><code>'iso-2022-jp'</code></td><td><code>'csiso2022jp'</code></td></tr><tr><td><code>'shift_jis'</code></td><td><code>'csshiftjis'</code>, <code>'ms932'</code>, <code>'ms_kanji'</code>, <code>'shift-jis'</code>, <code>'sjis'</code>, <code>'windows-31j'</code>, <code>'x-sjis'</code></td></tr><tr><td><code>'euc-kr'</code></td><td><code>'cseuckr'</code>, <code>'csksc56011987'</code>, <code>'iso-ir-149'</code>, <code>'korean'</code>, <code>'ks_c_5601-1987'</code>, <code>'ks_c_5601-1989'</code>, <code>'ksc5601'</code>, <code>'ksc_5601'</code>, <code>'windows-949'</code></td></tr></tbody></table>
21551cb0ef41Sopenharmony_ci<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>
21561cb0ef41Sopenharmony_ci
21571cb0ef41Sopenharmony_ci
21581cb0ef41Sopenharmony_ci
21591cb0ef41Sopenharmony_ci
21601cb0ef41Sopenharmony_ci
21611cb0ef41Sopenharmony_ci
21621cb0ef41Sopenharmony_ci
21631cb0ef41Sopenharmony_ci
21641cb0ef41Sopenharmony_ci
21651cb0ef41Sopenharmony_ci
21661cb0ef41Sopenharmony_ci
21671cb0ef41Sopenharmony_ci
21681cb0ef41Sopenharmony_ci
21691cb0ef41Sopenharmony_ci
21701cb0ef41Sopenharmony_ci
21711cb0ef41Sopenharmony_ci
21721cb0ef41Sopenharmony_ci
21731cb0ef41Sopenharmony_ci
21741cb0ef41Sopenharmony_ci
21751cb0ef41Sopenharmony_ci
21761cb0ef41Sopenharmony_ci
21771cb0ef41Sopenharmony_ci<table><thead><tr><th>Encoding</th><th>Aliases</th></tr></thead><tbody><tr><td><code>'utf-8'</code></td><td><code>'unicode-1-1-utf-8'</code>, <code>'utf8'</code></td></tr><tr><td><code>'utf-16le'</code></td><td><code>'utf-16'</code></td></tr><tr><td><code>'utf-16be'</code></td><td></td></tr></tbody></table>
21781cb0ef41Sopenharmony_ci<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>
21791cb0ef41Sopenharmony_ci
21801cb0ef41Sopenharmony_ci
21811cb0ef41Sopenharmony_ci
21821cb0ef41Sopenharmony_ci
21831cb0ef41Sopenharmony_ci
21841cb0ef41Sopenharmony_ci
21851cb0ef41Sopenharmony_ci
21861cb0ef41Sopenharmony_ci
21871cb0ef41Sopenharmony_ci
21881cb0ef41Sopenharmony_ci
21891cb0ef41Sopenharmony_ci
21901cb0ef41Sopenharmony_ci
21911cb0ef41Sopenharmony_ci
21921cb0ef41Sopenharmony_ci
21931cb0ef41Sopenharmony_ci
21941cb0ef41Sopenharmony_ci
21951cb0ef41Sopenharmony_ci
21961cb0ef41Sopenharmony_ci<table><thead><tr><th>Encoding</th><th>Aliases</th></tr></thead><tbody><tr><td><code>'utf-8'</code></td><td><code>'unicode-1-1-utf-8'</code>, <code>'utf8'</code></td></tr><tr><td><code>'utf-16le'</code></td><td><code>'utf-16'</code></td></tr></tbody></table>
21971cb0ef41Sopenharmony_ci<p>The <code>'iso-8859-16'</code> encoding listed in the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a>
21981cb0ef41Sopenharmony_ciis not supported.</p>
21991cb0ef41Sopenharmony_ci<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>
22001cb0ef41Sopenharmony_ci<div class="api_metadata">
22011cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
22021cb0ef41Sopenharmony_ci<table>
22031cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
22041cb0ef41Sopenharmony_ci<tr><td>v11.0.0</td>
22051cb0ef41Sopenharmony_ci<td><p>The class is now available on the global object.</p></td></tr>
22061cb0ef41Sopenharmony_ci<tr><td>v8.3.0</td>
22071cb0ef41Sopenharmony_ci<td><p><span>Added in: v8.3.0</span></p></td></tr>
22081cb0ef41Sopenharmony_ci</tbody></table>
22091cb0ef41Sopenharmony_ci</details>
22101cb0ef41Sopenharmony_ci</div>
22111cb0ef41Sopenharmony_ci<ul>
22121cb0ef41Sopenharmony_ci<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Identifies the <code>encoding</code> that this <code>TextDecoder</code> instance
22131cb0ef41Sopenharmony_cisupports. <strong>Default:</strong> <code>'utf-8'</code>.</li>
22141cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
22151cb0ef41Sopenharmony_ci<ul>
22161cb0ef41Sopenharmony_ci<li><code>fatal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> <code>true</code> if decoding failures are fatal.
22171cb0ef41Sopenharmony_ciThis option is not supported when ICU is disabled
22181cb0ef41Sopenharmony_ci(see <a href="intl.html">Internationalization</a>). <strong>Default:</strong> <code>false</code>.</li>
22191cb0ef41Sopenharmony_ci<li><code>ignoreBOM</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, the <code>TextDecoder</code> will include the byte
22201cb0ef41Sopenharmony_ciorder mark in the decoded result. When <code>false</code>, the byte order mark will
22211cb0ef41Sopenharmony_cibe removed from the output. This option is only used when <code>encoding</code> is
22221cb0ef41Sopenharmony_ci<code>'utf-8'</code>, <code>'utf-16be'</code>, or <code>'utf-16le'</code>. <strong>Default:</strong> <code>false</code>.</li>
22231cb0ef41Sopenharmony_ci</ul>
22241cb0ef41Sopenharmony_ci</li>
22251cb0ef41Sopenharmony_ci</ul>
22261cb0ef41Sopenharmony_ci<p>Creates a new <code>TextDecoder</code> instance. The <code>encoding</code> may specify one of the
22271cb0ef41Sopenharmony_cisupported encodings or an alias.</p>
22281cb0ef41Sopenharmony_ci<p>The <code>TextDecoder</code> class is also available on the global object.</p>
22291cb0ef41Sopenharmony_ci<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>
22301cb0ef41Sopenharmony_ci<ul>
22311cb0ef41Sopenharmony_ci<li><code>input</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> An <code>ArrayBuffer</code>, <code>DataView</code>, or
22321cb0ef41Sopenharmony_ci<code>TypedArray</code> instance containing the encoded data.</li>
22331cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
22341cb0ef41Sopenharmony_ci<ul>
22351cb0ef41Sopenharmony_ci<li><code>stream</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> <code>true</code> if additional chunks of data are expected.
22361cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>false</code>.</li>
22371cb0ef41Sopenharmony_ci</ul>
22381cb0ef41Sopenharmony_ci</li>
22391cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
22401cb0ef41Sopenharmony_ci</ul>
22411cb0ef41Sopenharmony_ci<p>Decodes the <code>input</code> and returns a string. If <code>options.stream</code> is <code>true</code>, any
22421cb0ef41Sopenharmony_ciincomplete byte sequences occurring at the end of the <code>input</code> are buffered
22431cb0ef41Sopenharmony_ciinternally and emitted after the next call to <code>textDecoder.decode()</code>.</p>
22441cb0ef41Sopenharmony_ci<p>If <code>textDecoder.fatal</code> is <code>true</code>, decoding errors that occur will result in a
22451cb0ef41Sopenharmony_ci<code>TypeError</code> being thrown.</p>
22461cb0ef41Sopenharmony_ci<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>
22471cb0ef41Sopenharmony_ci<ul>
22481cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
22491cb0ef41Sopenharmony_ci</ul>
22501cb0ef41Sopenharmony_ci<p>The encoding supported by the <code>TextDecoder</code> instance.</p>
22511cb0ef41Sopenharmony_ci<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>
22521cb0ef41Sopenharmony_ci<ul>
22531cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
22541cb0ef41Sopenharmony_ci</ul>
22551cb0ef41Sopenharmony_ci<p>The value will be <code>true</code> if decoding errors result in a <code>TypeError</code> being
22561cb0ef41Sopenharmony_cithrown.</p>
22571cb0ef41Sopenharmony_ci<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>
22581cb0ef41Sopenharmony_ci<ul>
22591cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
22601cb0ef41Sopenharmony_ci</ul>
22611cb0ef41Sopenharmony_ci<p>The value will be <code>true</code> if the decoding result will include the byte order
22621cb0ef41Sopenharmony_cimark.</p>
22631cb0ef41Sopenharmony_ci</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>
22641cb0ef41Sopenharmony_ci<div class="api_metadata">
22651cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
22661cb0ef41Sopenharmony_ci<table>
22671cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
22681cb0ef41Sopenharmony_ci<tr><td>v11.0.0</td>
22691cb0ef41Sopenharmony_ci<td><p>The class is now available on the global object.</p></td></tr>
22701cb0ef41Sopenharmony_ci<tr><td>v8.3.0</td>
22711cb0ef41Sopenharmony_ci<td><p><span>Added in: v8.3.0</span></p></td></tr>
22721cb0ef41Sopenharmony_ci</tbody></table>
22731cb0ef41Sopenharmony_ci</details>
22741cb0ef41Sopenharmony_ci</div>
22751cb0ef41Sopenharmony_ci<p>An implementation of the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a> <code>TextEncoder</code> API. All
22761cb0ef41Sopenharmony_ciinstances of <code>TextEncoder</code> only support UTF-8 encoding.</p>
22771cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> encoder = <span class="hljs-keyword">new</span> <span class="hljs-title class_">TextEncoder</span>();
22781cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> uint8array = encoder.<span class="hljs-title function_">encode</span>(<span class="hljs-string">'this is some data'</span>);</code> <button class="copy-button">copy</button></pre>
22791cb0ef41Sopenharmony_ci<p>The <code>TextEncoder</code> class is also available on the global object.</p>
22801cb0ef41Sopenharmony_ci<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>
22811cb0ef41Sopenharmony_ci<ul>
22821cb0ef41Sopenharmony_ci<li><code>input</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The text to encode. <strong>Default:</strong> an empty string.</li>
22831cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&#x3C;Uint8Array></a></li>
22841cb0ef41Sopenharmony_ci</ul>
22851cb0ef41Sopenharmony_ci<p>UTF-8 encodes the <code>input</code> string and returns a <code>Uint8Array</code> containing the
22861cb0ef41Sopenharmony_ciencoded bytes.</p>
22871cb0ef41Sopenharmony_ci<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>
22881cb0ef41Sopenharmony_ci<ul>
22891cb0ef41Sopenharmony_ci<li><code>src</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The text to encode.</li>
22901cb0ef41Sopenharmony_ci<li><code>dest</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&#x3C;Uint8Array></a> The array to hold the encode result.</li>
22911cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
22921cb0ef41Sopenharmony_ci<ul>
22931cb0ef41Sopenharmony_ci<li><code>read</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The read Unicode code units of src.</li>
22941cb0ef41Sopenharmony_ci<li><code>written</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The written UTF-8 bytes of dest.</li>
22951cb0ef41Sopenharmony_ci</ul>
22961cb0ef41Sopenharmony_ci</li>
22971cb0ef41Sopenharmony_ci</ul>
22981cb0ef41Sopenharmony_ci<p>UTF-8 encodes the <code>src</code> string to the <code>dest</code> Uint8Array and returns an object
22991cb0ef41Sopenharmony_cicontaining the read Unicode code units and written UTF-8 bytes.</p>
23001cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> encoder = <span class="hljs-keyword">new</span> <span class="hljs-title class_">TextEncoder</span>();
23011cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> src = <span class="hljs-string">'this is some data'</span>;
23021cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> dest = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Uint8Array</span>(<span class="hljs-number">10</span>);
23031cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { read, written } = encoder.<span class="hljs-title function_">encodeInto</span>(src, dest);</code> <button class="copy-button">copy</button></pre>
23041cb0ef41Sopenharmony_ci<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>
23051cb0ef41Sopenharmony_ci<ul>
23061cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
23071cb0ef41Sopenharmony_ci</ul>
23081cb0ef41Sopenharmony_ci<p>The encoding supported by the <code>TextEncoder</code> instance. Always set to <code>'utf-8'</code>.</p>
23091cb0ef41Sopenharmony_ci</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>
23101cb0ef41Sopenharmony_ci<div class="api_metadata">
23111cb0ef41Sopenharmony_ci<span>Added in: v16.8.0, v14.18.0</span>
23121cb0ef41Sopenharmony_ci</div>
23131cb0ef41Sopenharmony_ci<ul>
23141cb0ef41Sopenharmony_ci<li><code>string</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
23151cb0ef41Sopenharmony_ci</ul>
23161cb0ef41Sopenharmony_ci<p>Returns the <code>string</code> after replacing any surrogate code points
23171cb0ef41Sopenharmony_ci(or equivalently, any unpaired surrogate code units) with the
23181cb0ef41Sopenharmony_ciUnicode "replacement character" U+FFFD.</p>
23191cb0ef41Sopenharmony_ci</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>
23201cb0ef41Sopenharmony_ci<div class="api_metadata">
23211cb0ef41Sopenharmony_ci<span>Added in: v18.11.0</span>
23221cb0ef41Sopenharmony_ci</div>
23231cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
23241cb0ef41Sopenharmony_ci<p>Creates and returns an <a href="globals.html#class-abortcontroller" class="type">&#x3C;AbortController></a> instance whose <a href="globals.html#class-abortsignal" class="type">&#x3C;AbortSignal></a> is marked
23251cb0ef41Sopenharmony_cias transferable and can be used with <code>structuredClone()</code> or <code>postMessage()</code>.</p>
23261cb0ef41Sopenharmony_ci</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>
23271cb0ef41Sopenharmony_ci<div class="api_metadata">
23281cb0ef41Sopenharmony_ci<span>Added in: v18.11.0</span>
23291cb0ef41Sopenharmony_ci</div>
23301cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
23311cb0ef41Sopenharmony_ci<ul>
23321cb0ef41Sopenharmony_ci<li><code>signal</code> <a href="globals.html#class-abortsignal" class="type">&#x3C;AbortSignal></a></li>
23331cb0ef41Sopenharmony_ci<li>Returns: <a href="globals.html#class-abortsignal" class="type">&#x3C;AbortSignal></a></li>
23341cb0ef41Sopenharmony_ci</ul>
23351cb0ef41Sopenharmony_ci<p>Marks the given <a href="globals.html#class-abortsignal" class="type">&#x3C;AbortSignal></a> as transferable so that it can be used with
23361cb0ef41Sopenharmony_ci<code>structuredClone()</code> and <code>postMessage()</code>.</p>
23371cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> signal = <span class="hljs-title function_">transferableAbortSignal</span>(<span class="hljs-title class_">AbortSignal</span>.<span class="hljs-title function_">timeout</span>(<span class="hljs-number">100</span>));
23381cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MessageChannel</span>();
23391cb0ef41Sopenharmony_cichannel.<span class="hljs-property">port2</span>.<span class="hljs-title function_">postMessage</span>(signal, [signal]);</code> <button class="copy-button">copy</button></pre>
23401cb0ef41Sopenharmony_ci</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>
23411cb0ef41Sopenharmony_ci<div class="api_metadata">
23421cb0ef41Sopenharmony_ci<span>Added in: v18.16.0</span>
23431cb0ef41Sopenharmony_ci</div>
23441cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
23451cb0ef41Sopenharmony_ci<ul>
23461cb0ef41Sopenharmony_ci<li><code>signal</code> <a href="globals.html#class-abortsignal" class="type">&#x3C;AbortSignal></a></li>
23471cb0ef41Sopenharmony_ci<li><code>resource</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Any non-null entity, reference to which is held weakly.</li>
23481cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a></li>
23491cb0ef41Sopenharmony_ci</ul>
23501cb0ef41Sopenharmony_ci<p>Listens to abort event on the provided <code>signal</code> and
23511cb0ef41Sopenharmony_cireturns a promise that is fulfilled when the <code>signal</code> is
23521cb0ef41Sopenharmony_ciaborted. If the passed <code>resource</code> is garbage collected before the <code>signal</code> is
23531cb0ef41Sopenharmony_ciaborted, the returned promise shall remain pending indefinitely.</p>
23541cb0ef41Sopenharmony_ci
23551cb0ef41Sopenharmony_ci<pre class="with-41-chars"><input class="js-flavor-selector" type="checkbox" aria-label="Show modern ES modules syntax"><code class="language-js cjs"><span class="hljs-keyword">const</span> { aborted } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
23561cb0ef41Sopenharmony_ci
23571cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> dependent = <span class="hljs-title function_">obtainSomethingAbortable</span>();
23581cb0ef41Sopenharmony_ci
23591cb0ef41Sopenharmony_ci<span class="hljs-title function_">aborted</span>(dependent.<span class="hljs-property">signal</span>, dependent).<span class="hljs-title function_">then</span>(<span class="hljs-function">() =></span> {
23601cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Do something when dependent is aborted.</span>
23611cb0ef41Sopenharmony_ci});
23621cb0ef41Sopenharmony_ci
23631cb0ef41Sopenharmony_cidependent.<span class="hljs-title function_">on</span>(<span class="hljs-string">'event'</span>, <span class="hljs-function">() =></span> {
23641cb0ef41Sopenharmony_ci  dependent.<span class="hljs-title function_">abort</span>();
23651cb0ef41Sopenharmony_ci});</code><code class="language-js mjs"><span class="hljs-keyword">import</span> { aborted } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
23661cb0ef41Sopenharmony_ci
23671cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> dependent = <span class="hljs-title function_">obtainSomethingAbortable</span>();
23681cb0ef41Sopenharmony_ci
23691cb0ef41Sopenharmony_ci<span class="hljs-title function_">aborted</span>(dependent.<span class="hljs-property">signal</span>, dependent).<span class="hljs-title function_">then</span>(<span class="hljs-function">() =></span> {
23701cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Do something when dependent is aborted.</span>
23711cb0ef41Sopenharmony_ci});
23721cb0ef41Sopenharmony_ci
23731cb0ef41Sopenharmony_cidependent.<span class="hljs-title function_">on</span>(<span class="hljs-string">'event'</span>, <span class="hljs-function">() =></span> {
23741cb0ef41Sopenharmony_ci  dependent.<span class="hljs-title function_">abort</span>();
23751cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
23761cb0ef41Sopenharmony_ci</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>
23771cb0ef41Sopenharmony_ci<div class="api_metadata">
23781cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
23791cb0ef41Sopenharmony_ci<table>
23801cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
23811cb0ef41Sopenharmony_ci<tr><td>v15.3.0</td>
23821cb0ef41Sopenharmony_ci<td><p>Exposed as <code>require('util/types')</code>.</p></td></tr>
23831cb0ef41Sopenharmony_ci<tr><td>v10.0.0</td>
23841cb0ef41Sopenharmony_ci<td><p><span>Added in: v10.0.0</span></p></td></tr>
23851cb0ef41Sopenharmony_ci</tbody></table>
23861cb0ef41Sopenharmony_ci</details>
23871cb0ef41Sopenharmony_ci</div>
23881cb0ef41Sopenharmony_ci<p><code>util.types</code> provides type checks for different kinds of built-in objects.
23891cb0ef41Sopenharmony_ciUnlike <code>instanceof</code> or <code>Object.prototype.toString.call(value)</code>, these checks do
23901cb0ef41Sopenharmony_cinot inspect properties of the object that are accessible from JavaScript (like
23911cb0ef41Sopenharmony_citheir prototype), and usually have the overhead of calling into C++.</p>
23921cb0ef41Sopenharmony_ci<p>The result generally does not make any guarantees about what kinds of
23931cb0ef41Sopenharmony_ciproperties or behavior a value exposes in JavaScript. They are primarily
23941cb0ef41Sopenharmony_ciuseful for addon developers who prefer to do type checking in JavaScript.</p>
23951cb0ef41Sopenharmony_ci<p>The API is accessible via <code>require('node:util').types</code> or <code>require('node:util/types')</code>.</p>
23961cb0ef41Sopenharmony_ci<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>
23971cb0ef41Sopenharmony_ci<div class="api_metadata">
23981cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
23991cb0ef41Sopenharmony_ci</div>
24001cb0ef41Sopenharmony_ci<ul>
24011cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
24021cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
24031cb0ef41Sopenharmony_ci</ul>
24041cb0ef41Sopenharmony_ci<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
24051cb0ef41Sopenharmony_ci<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer"><code>SharedArrayBuffer</code></a> instance.</p>
24061cb0ef41Sopenharmony_ci<p>See also <a href="#utiltypesisarraybuffervalue"><code>util.types.isArrayBuffer()</code></a> and
24071cb0ef41Sopenharmony_ci<a href="#utiltypesissharedarraybuffervalue"><code>util.types.isSharedArrayBuffer()</code></a>.</p>
24081cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isAnyArrayBuffer</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns true</span>
24091cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isAnyArrayBuffer</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">SharedArrayBuffer</span>());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
24101cb0ef41Sopenharmony_ci<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>
24111cb0ef41Sopenharmony_ci<div class="api_metadata">
24121cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
24131cb0ef41Sopenharmony_ci</div>
24141cb0ef41Sopenharmony_ci<ul>
24151cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
24161cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
24171cb0ef41Sopenharmony_ci</ul>
24181cb0ef41Sopenharmony_ci<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>
24191cb0ef41Sopenharmony_civiews, 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
24201cb0ef41Sopenharmony_ci<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView"><code>ArrayBuffer.isView()</code></a>.</p>
24211cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isArrayBufferView</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Int8Array</span>());  <span class="hljs-comment">// true</span>
24221cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isArrayBufferView</span>(<span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(<span class="hljs-string">'hello world'</span>)); <span class="hljs-comment">// true</span>
24231cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isArrayBufferView</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">DataView</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>(<span class="hljs-number">16</span>)));  <span class="hljs-comment">// true</span>
24241cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isArrayBufferView</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// false</span></code> <button class="copy-button">copy</button></pre>
24251cb0ef41Sopenharmony_ci<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>
24261cb0ef41Sopenharmony_ci<div class="api_metadata">
24271cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
24281cb0ef41Sopenharmony_ci</div>
24291cb0ef41Sopenharmony_ci<ul>
24301cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
24311cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
24321cb0ef41Sopenharmony_ci</ul>
24331cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is an <code>arguments</code> object.</p>
24341cb0ef41Sopenharmony_ci<!-- eslint-disable prefer-rest-params -->
24351cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">foo</span>(<span class="hljs-params"></span>) {
24361cb0ef41Sopenharmony_ci  util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isArgumentsObject</span>(<span class="hljs-variable language_">arguments</span>);  <span class="hljs-comment">// Returns true</span>
24371cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
24381cb0ef41Sopenharmony_ci<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>
24391cb0ef41Sopenharmony_ci<div class="api_metadata">
24401cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
24411cb0ef41Sopenharmony_ci</div>
24421cb0ef41Sopenharmony_ci<ul>
24431cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
24441cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
24451cb0ef41Sopenharmony_ci</ul>
24461cb0ef41Sopenharmony_ci<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.
24471cb0ef41Sopenharmony_ciThis 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
24481cb0ef41Sopenharmony_cidesirable to test for both; See <a href="#utiltypesisanyarraybuffervalue"><code>util.types.isAnyArrayBuffer()</code></a> for that.</p>
24491cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isArrayBuffer</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns true</span>
24501cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isArrayBuffer</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">SharedArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
24511cb0ef41Sopenharmony_ci<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>
24521cb0ef41Sopenharmony_ci<div class="api_metadata">
24531cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
24541cb0ef41Sopenharmony_ci</div>
24551cb0ef41Sopenharmony_ci<ul>
24561cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
24571cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
24581cb0ef41Sopenharmony_ci</ul>
24591cb0ef41Sopenharmony_ci<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>.
24601cb0ef41Sopenharmony_ciThis only reports back what the JavaScript engine is seeing;
24611cb0ef41Sopenharmony_ciin particular, the return value may not match the original source code if
24621cb0ef41Sopenharmony_cia transpilation tool was used.</p>
24631cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isAsyncFunction</span>(<span class="hljs-keyword">function</span> <span class="hljs-title function_">foo</span>(<span class="hljs-params"></span>) {});  <span class="hljs-comment">// Returns false</span>
24641cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isAsyncFunction</span>(<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">foo</span>(<span class="hljs-params"></span>) {});  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
24651cb0ef41Sopenharmony_ci<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>
24661cb0ef41Sopenharmony_ci<div class="api_metadata">
24671cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
24681cb0ef41Sopenharmony_ci</div>
24691cb0ef41Sopenharmony_ci<ul>
24701cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
24711cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
24721cb0ef41Sopenharmony_ci</ul>
24731cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is a <code>BigInt64Array</code> instance.</p>
24741cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBigInt64Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">BigInt64Array</span>());   <span class="hljs-comment">// Returns true</span>
24751cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBigInt64Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">BigUint64Array</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
24761cb0ef41Sopenharmony_ci<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>
24771cb0ef41Sopenharmony_ci<div class="api_metadata">
24781cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
24791cb0ef41Sopenharmony_ci</div>
24801cb0ef41Sopenharmony_ci<ul>
24811cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
24821cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
24831cb0ef41Sopenharmony_ci</ul>
24841cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is a <code>BigUint64Array</code> instance.</p>
24851cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBigUint64Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">BigInt64Array</span>());   <span class="hljs-comment">// Returns false</span>
24861cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBigUint64Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">BigUint64Array</span>());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
24871cb0ef41Sopenharmony_ci<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>
24881cb0ef41Sopenharmony_ci<div class="api_metadata">
24891cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
24901cb0ef41Sopenharmony_ci</div>
24911cb0ef41Sopenharmony_ci<ul>
24921cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
24931cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
24941cb0ef41Sopenharmony_ci</ul>
24951cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is a boolean object, e.g. created
24961cb0ef41Sopenharmony_ciby <code>new Boolean()</code>.</p>
24971cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBooleanObject</span>(<span class="hljs-literal">false</span>);  <span class="hljs-comment">// Returns false</span>
24981cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBooleanObject</span>(<span class="hljs-literal">true</span>);   <span class="hljs-comment">// Returns false</span>
24991cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBooleanObject</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Boolean</span>(<span class="hljs-literal">false</span>)); <span class="hljs-comment">// Returns true</span>
25001cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBooleanObject</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Boolean</span>(<span class="hljs-literal">true</span>));  <span class="hljs-comment">// Returns true</span>
25011cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBooleanObject</span>(<span class="hljs-title class_">Boolean</span>(<span class="hljs-literal">false</span>)); <span class="hljs-comment">// Returns false</span>
25021cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBooleanObject</span>(<span class="hljs-title class_">Boolean</span>(<span class="hljs-literal">true</span>));  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
25031cb0ef41Sopenharmony_ci<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>
25041cb0ef41Sopenharmony_ci<div class="api_metadata">
25051cb0ef41Sopenharmony_ci<span>Added in: v10.11.0</span>
25061cb0ef41Sopenharmony_ci</div>
25071cb0ef41Sopenharmony_ci<ul>
25081cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
25091cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
25101cb0ef41Sopenharmony_ci</ul>
25111cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is any boxed primitive object, e.g. created
25121cb0ef41Sopenharmony_ciby <code>new Boolean()</code>, <code>new String()</code> or <code>Object(Symbol())</code>.</p>
25131cb0ef41Sopenharmony_ci<p>For example:</p>
25141cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBoxedPrimitive</span>(<span class="hljs-literal">false</span>); <span class="hljs-comment">// Returns false</span>
25151cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBoxedPrimitive</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Boolean</span>(<span class="hljs-literal">false</span>)); <span class="hljs-comment">// Returns true</span>
25161cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBoxedPrimitive</span>(<span class="hljs-title class_">Symbol</span>(<span class="hljs-string">'foo'</span>)); <span class="hljs-comment">// Returns false</span>
25171cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBoxedPrimitive</span>(<span class="hljs-title class_">Object</span>(<span class="hljs-title class_">Symbol</span>(<span class="hljs-string">'foo'</span>))); <span class="hljs-comment">// Returns true</span>
25181cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isBoxedPrimitive</span>(<span class="hljs-title class_">Object</span>(<span class="hljs-title class_">BigInt</span>(<span class="hljs-number">5</span>))); <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
25191cb0ef41Sopenharmony_ci<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>
25201cb0ef41Sopenharmony_ci<div class="api_metadata">
25211cb0ef41Sopenharmony_ci<span>Added in: v16.2.0</span>
25221cb0ef41Sopenharmony_ci</div>
25231cb0ef41Sopenharmony_ci<ul>
25241cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
25251cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
25261cb0ef41Sopenharmony_ci</ul>
25271cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if <code>value</code> is a <a href="webcrypto.html#class-cryptokey" class="type">&#x3C;CryptoKey></a>, <code>false</code> otherwise.</p>
25281cb0ef41Sopenharmony_ci<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>
25291cb0ef41Sopenharmony_ci<div class="api_metadata">
25301cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
25311cb0ef41Sopenharmony_ci</div>
25321cb0ef41Sopenharmony_ci<ul>
25331cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
25341cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
25351cb0ef41Sopenharmony_ci</ul>
25361cb0ef41Sopenharmony_ci<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>
25371cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> ab = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>(<span class="hljs-number">20</span>);
25381cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isDataView</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">DataView</span>(ab));  <span class="hljs-comment">// Returns true</span>
25391cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isDataView</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
25401cb0ef41Sopenharmony_ci<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>
25411cb0ef41Sopenharmony_ci<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>
25421cb0ef41Sopenharmony_ci<div class="api_metadata">
25431cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
25441cb0ef41Sopenharmony_ci</div>
25451cb0ef41Sopenharmony_ci<ul>
25461cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
25471cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
25481cb0ef41Sopenharmony_ci</ul>
25491cb0ef41Sopenharmony_ci<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>
25501cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
25511cb0ef41Sopenharmony_ci<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>
25521cb0ef41Sopenharmony_ci<div class="api_metadata">
25531cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
25541cb0ef41Sopenharmony_ci</div>
25551cb0ef41Sopenharmony_ci<ul>
25561cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
25571cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
25581cb0ef41Sopenharmony_ci</ul>
25591cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is a native <code>External</code> value.</p>
25601cb0ef41Sopenharmony_ci<p>A native <code>External</code> value is a special type of object that contains a
25611cb0ef41Sopenharmony_ciraw C++ pointer (<code>void*</code>) for access from native code, and has no other
25621cb0ef41Sopenharmony_ciproperties. Such objects are created either by Node.js internals or native
25631cb0ef41Sopenharmony_ciaddons. 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
25641cb0ef41Sopenharmony_ci<code>null</code> prototype.</p>
25651cb0ef41Sopenharmony_ci<pre><code class="language-c"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&#x3C;js_native_api.h></span></span>
25661cb0ef41Sopenharmony_ci<span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&#x3C;stdlib.h></span></span>
25671cb0ef41Sopenharmony_cinapi_value result;
25681cb0ef41Sopenharmony_ci<span class="hljs-type">static</span> napi_value <span class="hljs-title function_">MyNapi</span><span class="hljs-params">(napi_env env, napi_callback_info info)</span> {
25691cb0ef41Sopenharmony_ci  <span class="hljs-type">int</span>* raw = (<span class="hljs-type">int</span>*) <span class="hljs-built_in">malloc</span>(<span class="hljs-number">1024</span>);
25701cb0ef41Sopenharmony_ci  napi_status status = napi_create_external(env, (<span class="hljs-type">void</span>*) raw, <span class="hljs-literal">NULL</span>, <span class="hljs-literal">NULL</span>, &#x26;result);
25711cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (status != napi_ok) {
25721cb0ef41Sopenharmony_ci    napi_throw_error(env, <span class="hljs-literal">NULL</span>, <span class="hljs-string">"napi_create_external failed"</span>);
25731cb0ef41Sopenharmony_ci    <span class="hljs-keyword">return</span> <span class="hljs-literal">NULL</span>;
25741cb0ef41Sopenharmony_ci  }
25751cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> result;
25761cb0ef41Sopenharmony_ci}
25771cb0ef41Sopenharmony_ci...
25781cb0ef41Sopenharmony_ciDECLARE_NAPI_PROPERTY(<span class="hljs-string">"myNapi"</span>, MyNapi)
25791cb0ef41Sopenharmony_ci...</code> <button class="copy-button">copy</button></pre>
25801cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> native = <span class="hljs-built_in">require</span>(<span class="hljs-string">'napi_addon.node'</span>);
25811cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> data = native.<span class="hljs-title function_">myNapi</span>();
25821cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isExternal</span>(data); <span class="hljs-comment">// returns true</span>
25831cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isExternal</span>(<span class="hljs-number">0</span>); <span class="hljs-comment">// returns false</span>
25841cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isExternal</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">String</span>(<span class="hljs-string">'foo'</span>)); <span class="hljs-comment">// returns false</span></code> <button class="copy-button">copy</button></pre>
25851cb0ef41Sopenharmony_ci<p>For further information on <code>napi_create_external</code>, refer to
25861cb0ef41Sopenharmony_ci<a href="n-api.html#napi_create_external"><code>napi_create_external()</code></a>.</p>
25871cb0ef41Sopenharmony_ci<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>
25881cb0ef41Sopenharmony_ci<div class="api_metadata">
25891cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
25901cb0ef41Sopenharmony_ci</div>
25911cb0ef41Sopenharmony_ci<ul>
25921cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
25931cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
25941cb0ef41Sopenharmony_ci</ul>
25951cb0ef41Sopenharmony_ci<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>
25961cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isFloat32Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
25971cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isFloat32Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float32Array</span>());  <span class="hljs-comment">// Returns true</span>
25981cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isFloat32Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
25991cb0ef41Sopenharmony_ci<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>
26001cb0ef41Sopenharmony_ci<div class="api_metadata">
26011cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
26021cb0ef41Sopenharmony_ci</div>
26031cb0ef41Sopenharmony_ci<ul>
26041cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
26051cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
26061cb0ef41Sopenharmony_ci</ul>
26071cb0ef41Sopenharmony_ci<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>
26081cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isFloat64Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
26091cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isFloat64Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Uint8Array</span>());  <span class="hljs-comment">// Returns false</span>
26101cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isFloat64Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
26111cb0ef41Sopenharmony_ci<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>
26121cb0ef41Sopenharmony_ci<div class="api_metadata">
26131cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
26141cb0ef41Sopenharmony_ci</div>
26151cb0ef41Sopenharmony_ci<ul>
26161cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
26171cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
26181cb0ef41Sopenharmony_ci</ul>
26191cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is a generator function.
26201cb0ef41Sopenharmony_ciThis only reports back what the JavaScript engine is seeing;
26211cb0ef41Sopenharmony_ciin particular, the return value may not match the original source code if
26221cb0ef41Sopenharmony_cia transpilation tool was used.</p>
26231cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isGeneratorFunction</span>(<span class="hljs-keyword">function</span> <span class="hljs-title function_">foo</span>(<span class="hljs-params"></span>) {});  <span class="hljs-comment">// Returns false</span>
26241cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isGeneratorFunction</span>(<span class="hljs-keyword">function</span>* <span class="hljs-title function_">foo</span>(<span class="hljs-params"></span>) {});  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
26251cb0ef41Sopenharmony_ci<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>
26261cb0ef41Sopenharmony_ci<div class="api_metadata">
26271cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
26281cb0ef41Sopenharmony_ci</div>
26291cb0ef41Sopenharmony_ci<ul>
26301cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
26311cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
26321cb0ef41Sopenharmony_ci</ul>
26331cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is a generator object as returned from a
26341cb0ef41Sopenharmony_cibuilt-in generator function.
26351cb0ef41Sopenharmony_ciThis only reports back what the JavaScript engine is seeing;
26361cb0ef41Sopenharmony_ciin particular, the return value may not match the original source code if
26371cb0ef41Sopenharmony_cia transpilation tool was used.</p>
26381cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">function</span>* <span class="hljs-title function_">foo</span>(<span class="hljs-params"></span>) {}
26391cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> generator = <span class="hljs-title function_">foo</span>();
26401cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isGeneratorObject</span>(generator);  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
26411cb0ef41Sopenharmony_ci<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>
26421cb0ef41Sopenharmony_ci<div class="api_metadata">
26431cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
26441cb0ef41Sopenharmony_ci</div>
26451cb0ef41Sopenharmony_ci<ul>
26461cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
26471cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
26481cb0ef41Sopenharmony_ci</ul>
26491cb0ef41Sopenharmony_ci<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>
26501cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isInt8Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
26511cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isInt8Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Int8Array</span>());  <span class="hljs-comment">// Returns true</span>
26521cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isInt8Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
26531cb0ef41Sopenharmony_ci<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>
26541cb0ef41Sopenharmony_ci<div class="api_metadata">
26551cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
26561cb0ef41Sopenharmony_ci</div>
26571cb0ef41Sopenharmony_ci<ul>
26581cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
26591cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
26601cb0ef41Sopenharmony_ci</ul>
26611cb0ef41Sopenharmony_ci<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>
26621cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isInt16Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
26631cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isInt16Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Int16Array</span>());  <span class="hljs-comment">// Returns true</span>
26641cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isInt16Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
26651cb0ef41Sopenharmony_ci<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>
26661cb0ef41Sopenharmony_ci<div class="api_metadata">
26671cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
26681cb0ef41Sopenharmony_ci</div>
26691cb0ef41Sopenharmony_ci<ul>
26701cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
26711cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
26721cb0ef41Sopenharmony_ci</ul>
26731cb0ef41Sopenharmony_ci<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>
26741cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isInt32Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
26751cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isInt32Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Int32Array</span>());  <span class="hljs-comment">// Returns true</span>
26761cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isInt32Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
26771cb0ef41Sopenharmony_ci<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>
26781cb0ef41Sopenharmony_ci<div class="api_metadata">
26791cb0ef41Sopenharmony_ci<span>Added in: v16.2.0</span>
26801cb0ef41Sopenharmony_ci</div>
26811cb0ef41Sopenharmony_ci<ul>
26821cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
26831cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
26841cb0ef41Sopenharmony_ci</ul>
26851cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if <code>value</code> is a <a href="crypto.html#class-keyobject" class="type">&#x3C;KeyObject></a>, <code>false</code> otherwise.</p>
26861cb0ef41Sopenharmony_ci<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>
26871cb0ef41Sopenharmony_ci<div class="api_metadata">
26881cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
26891cb0ef41Sopenharmony_ci</div>
26901cb0ef41Sopenharmony_ci<ul>
26911cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
26921cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
26931cb0ef41Sopenharmony_ci</ul>
26941cb0ef41Sopenharmony_ci<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>
26951cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isMap</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
26961cb0ef41Sopenharmony_ci<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>
26971cb0ef41Sopenharmony_ci<div class="api_metadata">
26981cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
26991cb0ef41Sopenharmony_ci</div>
27001cb0ef41Sopenharmony_ci<ul>
27011cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
27021cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
27031cb0ef41Sopenharmony_ci</ul>
27041cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is an iterator returned for a built-in
27051cb0ef41Sopenharmony_ci<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map"><code>Map</code></a> instance.</p>
27061cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> map = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>();
27071cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isMapIterator</span>(map.<span class="hljs-title function_">keys</span>());  <span class="hljs-comment">// Returns true</span>
27081cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isMapIterator</span>(map.<span class="hljs-title function_">values</span>());  <span class="hljs-comment">// Returns true</span>
27091cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isMapIterator</span>(map.<span class="hljs-title function_">entries</span>());  <span class="hljs-comment">// Returns true</span>
27101cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isMapIterator</span>(map[<span class="hljs-title class_">Symbol</span>.<span class="hljs-property">iterator</span>]());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
27111cb0ef41Sopenharmony_ci<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>
27121cb0ef41Sopenharmony_ci<div class="api_metadata">
27131cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
27141cb0ef41Sopenharmony_ci</div>
27151cb0ef41Sopenharmony_ci<ul>
27161cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
27171cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
27181cb0ef41Sopenharmony_ci</ul>
27191cb0ef41Sopenharmony_ci<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>
27201cb0ef41Sopenharmony_ci<!-- eslint-skip -->
27211cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> ns <span class="hljs-keyword">from</span> <span class="hljs-string">'./a.js'</span>;
27221cb0ef41Sopenharmony_ci
27231cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isModuleNamespaceObject</span>(ns);  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
27241cb0ef41Sopenharmony_ci<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>
27251cb0ef41Sopenharmony_ci<div class="api_metadata">
27261cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
27271cb0ef41Sopenharmony_ci</div>
27281cb0ef41Sopenharmony_ci<ul>
27291cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
27301cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
27311cb0ef41Sopenharmony_ci</ul>
27321cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value was returned by the constructor of a
27331cb0ef41Sopenharmony_ci<a href="https://tc39.es/ecma262/#sec-error-objects">built-in <code>Error</code> type</a>.</p>
27341cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isNativeError</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>()));  <span class="hljs-comment">// true</span>
27351cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isNativeError</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">TypeError</span>()));  <span class="hljs-comment">// true</span>
27361cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isNativeError</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">RangeError</span>()));  <span class="hljs-comment">// true</span></code> <button class="copy-button">copy</button></pre>
27371cb0ef41Sopenharmony_ci<p>Subclasses of the native error types are also native errors:</p>
27381cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">class</span> <span class="hljs-title class_">MyError</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_ inherited__">Error</span> {}
27391cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isNativeError</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">MyError</span>()));  <span class="hljs-comment">// true</span></code> <button class="copy-button">copy</button></pre>
27401cb0ef41Sopenharmony_ci<p>A value being <code>instanceof</code> a native error class is not equivalent to <code>isNativeError()</code>
27411cb0ef41Sopenharmony_cireturning <code>true</code> for that value. <code>isNativeError()</code> returns <code>true</code> for errors
27421cb0ef41Sopenharmony_ciwhich come from a different <a href="https://tc39.es/ecma262/#realm">realm</a> while <code>instanceof Error</code> returns <code>false</code>
27431cb0ef41Sopenharmony_cifor these errors:</p>
27441cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> vm = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:vm'</span>);
27451cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> context = vm.<span class="hljs-title function_">createContext</span>({});
27461cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myError = vm.<span class="hljs-title function_">runInContext</span>(<span class="hljs-string">'new Error()'</span>, context);
27471cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isNativeError</span>(myError)); <span class="hljs-comment">// true</span>
27481cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myError <span class="hljs-keyword">instanceof</span> <span class="hljs-title class_">Error</span>); <span class="hljs-comment">// false</span></code> <button class="copy-button">copy</button></pre>
27491cb0ef41Sopenharmony_ci<p>Conversely, <code>isNativeError()</code> returns <code>false</code> for all objects which were not
27501cb0ef41Sopenharmony_cireturned by the constructor of a native error. That includes values
27511cb0ef41Sopenharmony_ciwhich are <code>instanceof</code> native errors:</p>
27521cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> myError = { <span class="hljs-attr">__proto__</span>: <span class="hljs-title class_">Error</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span> };
27531cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isNativeError</span>(myError)); <span class="hljs-comment">// false</span>
27541cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(myError <span class="hljs-keyword">instanceof</span> <span class="hljs-title class_">Error</span>); <span class="hljs-comment">// true</span></code> <button class="copy-button">copy</button></pre>
27551cb0ef41Sopenharmony_ci<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>
27561cb0ef41Sopenharmony_ci<div class="api_metadata">
27571cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
27581cb0ef41Sopenharmony_ci</div>
27591cb0ef41Sopenharmony_ci<ul>
27601cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
27611cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
27621cb0ef41Sopenharmony_ci</ul>
27631cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is a number object, e.g. created
27641cb0ef41Sopenharmony_ciby <code>new Number()</code>.</p>
27651cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isNumberObject</span>(<span class="hljs-number">0</span>);  <span class="hljs-comment">// Returns false</span>
27661cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isNumberObject</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Number</span>(<span class="hljs-number">0</span>));   <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
27671cb0ef41Sopenharmony_ci<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>
27681cb0ef41Sopenharmony_ci<div class="api_metadata">
27691cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
27701cb0ef41Sopenharmony_ci</div>
27711cb0ef41Sopenharmony_ci<ul>
27721cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
27731cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
27741cb0ef41Sopenharmony_ci</ul>
27751cb0ef41Sopenharmony_ci<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>
27761cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isPromise</span>(<span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">resolve</span>(<span class="hljs-number">42</span>));  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
27771cb0ef41Sopenharmony_ci<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>
27781cb0ef41Sopenharmony_ci<div class="api_metadata">
27791cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
27801cb0ef41Sopenharmony_ci</div>
27811cb0ef41Sopenharmony_ci<ul>
27821cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
27831cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
27841cb0ef41Sopenharmony_ci</ul>
27851cb0ef41Sopenharmony_ci<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>
27861cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> target = {};
27871cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> proxy = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Proxy</span>(target, {});
27881cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isProxy</span>(target);  <span class="hljs-comment">// Returns false</span>
27891cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isProxy</span>(proxy);  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
27901cb0ef41Sopenharmony_ci<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>
27911cb0ef41Sopenharmony_ci<div class="api_metadata">
27921cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
27931cb0ef41Sopenharmony_ci</div>
27941cb0ef41Sopenharmony_ci<ul>
27951cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
27961cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
27971cb0ef41Sopenharmony_ci</ul>
27981cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is a regular expression object.</p>
27991cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isRegExp</span>(<span class="hljs-regexp">/abc/</span>);  <span class="hljs-comment">// Returns true</span>
28001cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isRegExp</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">RegExp</span>(<span class="hljs-string">'abc'</span>));  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
28011cb0ef41Sopenharmony_ci<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>
28021cb0ef41Sopenharmony_ci<div class="api_metadata">
28031cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
28041cb0ef41Sopenharmony_ci</div>
28051cb0ef41Sopenharmony_ci<ul>
28061cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
28071cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28081cb0ef41Sopenharmony_ci</ul>
28091cb0ef41Sopenharmony_ci<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>
28101cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isSet</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Set</span>());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
28111cb0ef41Sopenharmony_ci<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>
28121cb0ef41Sopenharmony_ci<div class="api_metadata">
28131cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
28141cb0ef41Sopenharmony_ci</div>
28151cb0ef41Sopenharmony_ci<ul>
28161cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
28171cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28181cb0ef41Sopenharmony_ci</ul>
28191cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is an iterator returned for a built-in
28201cb0ef41Sopenharmony_ci<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set"><code>Set</code></a> instance.</p>
28211cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> set = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Set</span>();
28221cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isSetIterator</span>(set.<span class="hljs-title function_">keys</span>());  <span class="hljs-comment">// Returns true</span>
28231cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isSetIterator</span>(set.<span class="hljs-title function_">values</span>());  <span class="hljs-comment">// Returns true</span>
28241cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isSetIterator</span>(set.<span class="hljs-title function_">entries</span>());  <span class="hljs-comment">// Returns true</span>
28251cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isSetIterator</span>(set[<span class="hljs-title class_">Symbol</span>.<span class="hljs-property">iterator</span>]());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
28261cb0ef41Sopenharmony_ci<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>
28271cb0ef41Sopenharmony_ci<div class="api_metadata">
28281cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
28291cb0ef41Sopenharmony_ci</div>
28301cb0ef41Sopenharmony_ci<ul>
28311cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
28321cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28331cb0ef41Sopenharmony_ci</ul>
28341cb0ef41Sopenharmony_ci<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.
28351cb0ef41Sopenharmony_ciThis 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
28361cb0ef41Sopenharmony_cidesirable to test for both; See <a href="#utiltypesisanyarraybuffervalue"><code>util.types.isAnyArrayBuffer()</code></a> for that.</p>
28371cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isSharedArrayBuffer</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
28381cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isSharedArrayBuffer</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">SharedArrayBuffer</span>());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
28391cb0ef41Sopenharmony_ci<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>
28401cb0ef41Sopenharmony_ci<div class="api_metadata">
28411cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
28421cb0ef41Sopenharmony_ci</div>
28431cb0ef41Sopenharmony_ci<ul>
28441cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
28451cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28461cb0ef41Sopenharmony_ci</ul>
28471cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is a string object, e.g. created
28481cb0ef41Sopenharmony_ciby <code>new String()</code>.</p>
28491cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isStringObject</span>(<span class="hljs-string">'foo'</span>);  <span class="hljs-comment">// Returns false</span>
28501cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isStringObject</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">String</span>(<span class="hljs-string">'foo'</span>));   <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
28511cb0ef41Sopenharmony_ci<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>
28521cb0ef41Sopenharmony_ci<div class="api_metadata">
28531cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
28541cb0ef41Sopenharmony_ci</div>
28551cb0ef41Sopenharmony_ci<ul>
28561cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
28571cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28581cb0ef41Sopenharmony_ci</ul>
28591cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the value is a symbol object, created
28601cb0ef41Sopenharmony_ciby calling <code>Object()</code> on a <code>Symbol</code> primitive.</p>
28611cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> symbol = <span class="hljs-title class_">Symbol</span>(<span class="hljs-string">'foo'</span>);
28621cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isSymbolObject</span>(symbol);  <span class="hljs-comment">// Returns false</span>
28631cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isSymbolObject</span>(<span class="hljs-title class_">Object</span>(symbol));   <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
28641cb0ef41Sopenharmony_ci<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>
28651cb0ef41Sopenharmony_ci<div class="api_metadata">
28661cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
28671cb0ef41Sopenharmony_ci</div>
28681cb0ef41Sopenharmony_ci<ul>
28691cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
28701cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28711cb0ef41Sopenharmony_ci</ul>
28721cb0ef41Sopenharmony_ci<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>
28731cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isTypedArray</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
28741cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isTypedArray</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Uint8Array</span>());  <span class="hljs-comment">// Returns true</span>
28751cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isTypedArray</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
28761cb0ef41Sopenharmony_ci<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>
28771cb0ef41Sopenharmony_ci<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>
28781cb0ef41Sopenharmony_ci<div class="api_metadata">
28791cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
28801cb0ef41Sopenharmony_ci</div>
28811cb0ef41Sopenharmony_ci<ul>
28821cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
28831cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28841cb0ef41Sopenharmony_ci</ul>
28851cb0ef41Sopenharmony_ci<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>
28861cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint8Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
28871cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint8Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Uint8Array</span>());  <span class="hljs-comment">// Returns true</span>
28881cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint8Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
28891cb0ef41Sopenharmony_ci<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>
28901cb0ef41Sopenharmony_ci<div class="api_metadata">
28911cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
28921cb0ef41Sopenharmony_ci</div>
28931cb0ef41Sopenharmony_ci<ul>
28941cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
28951cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28961cb0ef41Sopenharmony_ci</ul>
28971cb0ef41Sopenharmony_ci<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>
28981cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint8ClampedArray</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
28991cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint8ClampedArray</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Uint8ClampedArray</span>());  <span class="hljs-comment">// Returns true</span>
29001cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint8ClampedArray</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
29011cb0ef41Sopenharmony_ci<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>
29021cb0ef41Sopenharmony_ci<div class="api_metadata">
29031cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
29041cb0ef41Sopenharmony_ci</div>
29051cb0ef41Sopenharmony_ci<ul>
29061cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
29071cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
29081cb0ef41Sopenharmony_ci</ul>
29091cb0ef41Sopenharmony_ci<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>
29101cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint16Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
29111cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint16Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Uint16Array</span>());  <span class="hljs-comment">// Returns true</span>
29121cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint16Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
29131cb0ef41Sopenharmony_ci<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>
29141cb0ef41Sopenharmony_ci<div class="api_metadata">
29151cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
29161cb0ef41Sopenharmony_ci</div>
29171cb0ef41Sopenharmony_ci<ul>
29181cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
29191cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
29201cb0ef41Sopenharmony_ci</ul>
29211cb0ef41Sopenharmony_ci<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>
29221cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint32Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayBuffer</span>());  <span class="hljs-comment">// Returns false</span>
29231cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint32Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Uint32Array</span>());  <span class="hljs-comment">// Returns true</span>
29241cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isUint32Array</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Float64Array</span>());  <span class="hljs-comment">// Returns false</span></code> <button class="copy-button">copy</button></pre>
29251cb0ef41Sopenharmony_ci<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>
29261cb0ef41Sopenharmony_ci<div class="api_metadata">
29271cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
29281cb0ef41Sopenharmony_ci</div>
29291cb0ef41Sopenharmony_ci<ul>
29301cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
29311cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
29321cb0ef41Sopenharmony_ci</ul>
29331cb0ef41Sopenharmony_ci<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>
29341cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isWeakMap</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">WeakMap</span>());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
29351cb0ef41Sopenharmony_ci<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>
29361cb0ef41Sopenharmony_ci<div class="api_metadata">
29371cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
29381cb0ef41Sopenharmony_ci</div>
29391cb0ef41Sopenharmony_ci<ul>
29401cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
29411cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
29421cb0ef41Sopenharmony_ci</ul>
29431cb0ef41Sopenharmony_ci<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>
29441cb0ef41Sopenharmony_ci<pre><code class="language-js">util.<span class="hljs-property">types</span>.<span class="hljs-title function_">isWeakSet</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">WeakSet</span>());  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
29451cb0ef41Sopenharmony_ci<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>
29461cb0ef41Sopenharmony_ci<div class="api_metadata">
29471cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span><span>Deprecated since: v14.0.0</span>
29481cb0ef41Sopenharmony_ci</div>
29491cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <code>value instanceof WebAssembly.Module</code> instead.</div><p></p>
29501cb0ef41Sopenharmony_ci<ul>
29511cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
29521cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
29531cb0ef41Sopenharmony_ci</ul>
29541cb0ef41Sopenharmony_ci<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>
29551cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">WebAssembly</span>.<span class="hljs-title class_">Module</span>(wasmBuffer);
29561cb0ef41Sopenharmony_ciutil.<span class="hljs-property">types</span>.<span class="hljs-title function_">isWebAssemblyCompiledModule</span>(<span class="hljs-variable language_">module</span>);  <span class="hljs-comment">// Returns true</span></code> <button class="copy-button">copy</button></pre>
29571cb0ef41Sopenharmony_ci</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>
29581cb0ef41Sopenharmony_ci<p>The following APIs are deprecated and should no longer be used. Existing
29591cb0ef41Sopenharmony_ciapplications and modules should be updated to find alternative approaches.</p>
29601cb0ef41Sopenharmony_ci<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>
29611cb0ef41Sopenharmony_ci<div class="api_metadata">
29621cb0ef41Sopenharmony_ci<span>Added in: v0.7.5</span><span>Deprecated since: v6.0.0</span>
29631cb0ef41Sopenharmony_ci</div>
29641cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign"><code>Object.assign()</code></a> instead.</div><p></p>
29651cb0ef41Sopenharmony_ci<ul>
29661cb0ef41Sopenharmony_ci<li><code>target</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
29671cb0ef41Sopenharmony_ci<li><code>source</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
29681cb0ef41Sopenharmony_ci</ul>
29691cb0ef41Sopenharmony_ci<p>The <code>util._extend()</code> method was never intended to be used outside of internal
29701cb0ef41Sopenharmony_ciNode.js modules. The community found and used it anyway.</p>
29711cb0ef41Sopenharmony_ci<p>It is deprecated and should not be used in new code. JavaScript comes with very
29721cb0ef41Sopenharmony_cisimilar 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>
29731cb0ef41Sopenharmony_ci<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>
29741cb0ef41Sopenharmony_ci<div class="api_metadata">
29751cb0ef41Sopenharmony_ci<span>Added in: v0.6.0</span><span>Deprecated since: v4.0.0</span>
29761cb0ef41Sopenharmony_ci</div>
29771cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray"><code>Array.isArray()</code></a> instead.</div><p></p>
29781cb0ef41Sopenharmony_ci<ul>
29791cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
29801cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
29811cb0ef41Sopenharmony_ci</ul>
29821cb0ef41Sopenharmony_ci<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>
29831cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is an <code>Array</code>. Otherwise, returns <code>false</code>.</p>
29841cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
29851cb0ef41Sopenharmony_ci
29861cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isArray</span>([]);
29871cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
29881cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isArray</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Array</span>());
29891cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
29901cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isArray</span>({});
29911cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span></code> <button class="copy-button">copy</button></pre>
29921cb0ef41Sopenharmony_ci<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>
29931cb0ef41Sopenharmony_ci<div class="api_metadata">
29941cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
29951cb0ef41Sopenharmony_ci</div>
29961cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <code>typeof value === 'boolean'</code> instead.</div><p></p>
29971cb0ef41Sopenharmony_ci<ul>
29981cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
29991cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
30001cb0ef41Sopenharmony_ci</ul>
30011cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is a <code>Boolean</code>. Otherwise, returns <code>false</code>.</p>
30021cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
30031cb0ef41Sopenharmony_ci
30041cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isBoolean</span>(<span class="hljs-number">1</span>);
30051cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
30061cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isBoolean</span>(<span class="hljs-number">0</span>);
30071cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
30081cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isBoolean</span>(<span class="hljs-literal">false</span>);
30091cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span></code> <button class="copy-button">copy</button></pre>
30101cb0ef41Sopenharmony_ci<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>
30111cb0ef41Sopenharmony_ci<div class="api_metadata">
30121cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
30131cb0ef41Sopenharmony_ci</div>
30141cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <a href="buffer.html#static-method-bufferisbufferobj"><code>Buffer.isBuffer()</code></a> instead.</div><p></p>
30151cb0ef41Sopenharmony_ci<ul>
30161cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
30171cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
30181cb0ef41Sopenharmony_ci</ul>
30191cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is a <code>Buffer</code>. Otherwise, returns <code>false</code>.</p>
30201cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
30211cb0ef41Sopenharmony_ci
30221cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isBuffer</span>({ <span class="hljs-attr">length</span>: <span class="hljs-number">0</span> });
30231cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
30241cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isBuffer</span>([]);
30251cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
30261cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isBuffer</span>(<span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(<span class="hljs-string">'hello world'</span>));
30271cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span></code> <button class="copy-button">copy</button></pre>
30281cb0ef41Sopenharmony_ci<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>
30291cb0ef41Sopenharmony_ci<div class="api_metadata">
30301cb0ef41Sopenharmony_ci<span>Added in: v0.6.0</span><span>Deprecated since: v4.0.0</span>
30311cb0ef41Sopenharmony_ci</div>
30321cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <a href="#utiltypesisdatevalue"><code>util.types.isDate()</code></a> instead.</div><p></p>
30331cb0ef41Sopenharmony_ci<ul>
30341cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
30351cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
30361cb0ef41Sopenharmony_ci</ul>
30371cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is a <code>Date</code>. Otherwise, returns <code>false</code>.</p>
30381cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
30391cb0ef41Sopenharmony_ci
30401cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>());
30411cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
30421cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isDate</span>(<span class="hljs-title class_">Date</span>());
30431cb0ef41Sopenharmony_ci<span class="hljs-comment">// false (without 'new' returns a String)</span>
30441cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isDate</span>({});
30451cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span></code> <button class="copy-button">copy</button></pre>
30461cb0ef41Sopenharmony_ci<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>
30471cb0ef41Sopenharmony_ci<div class="api_metadata">
30481cb0ef41Sopenharmony_ci<span>Added in: v0.6.0</span><span>Deprecated since: v4.0.0</span>
30491cb0ef41Sopenharmony_ci</div>
30501cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <a href="#utiltypesisnativeerrorvalue"><code>util.types.isNativeError()</code></a> instead.</div><p></p>
30511cb0ef41Sopenharmony_ci<ul>
30521cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
30531cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
30541cb0ef41Sopenharmony_ci</ul>
30551cb0ef41Sopenharmony_ci<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
30561cb0ef41Sopenharmony_ci<code>false</code>.</p>
30571cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
30581cb0ef41Sopenharmony_ci
30591cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isError</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>());
30601cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
30611cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isError</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">TypeError</span>());
30621cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
30631cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isError</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">'Error'</span>, <span class="hljs-attr">message</span>: <span class="hljs-string">'an error occurred'</span> });
30641cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span></code> <button class="copy-button">copy</button></pre>
30651cb0ef41Sopenharmony_ci<p>This method relies on <code>Object.prototype.toString()</code> behavior. It is
30661cb0ef41Sopenharmony_cipossible to obtain an incorrect result when the <code>object</code> argument manipulates
30671cb0ef41Sopenharmony_ci<code>@@toStringTag</code>.</p>
30681cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
30691cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> obj = { <span class="hljs-attr">name</span>: <span class="hljs-string">'Error'</span>, <span class="hljs-attr">message</span>: <span class="hljs-string">'an error occurred'</span> };
30701cb0ef41Sopenharmony_ci
30711cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isError</span>(obj);
30721cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
30731cb0ef41Sopenharmony_ciobj[<span class="hljs-title class_">Symbol</span>.<span class="hljs-property">toStringTag</span>] = <span class="hljs-string">'Error'</span>;
30741cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isError</span>(obj);
30751cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span></code> <button class="copy-button">copy</button></pre>
30761cb0ef41Sopenharmony_ci<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>
30771cb0ef41Sopenharmony_ci<div class="api_metadata">
30781cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
30791cb0ef41Sopenharmony_ci</div>
30801cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <code>typeof value === 'function'</code> instead.</div><p></p>
30811cb0ef41Sopenharmony_ci<ul>
30821cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
30831cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
30841cb0ef41Sopenharmony_ci</ul>
30851cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is a <code>Function</code>. Otherwise, returns
30861cb0ef41Sopenharmony_ci<code>false</code>.</p>
30871cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
30881cb0ef41Sopenharmony_ci
30891cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">Foo</span>(<span class="hljs-params"></span>) {}
30901cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> <span class="hljs-title function_">Bar</span> = (<span class="hljs-params"></span>) => {};
30911cb0ef41Sopenharmony_ci
30921cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isFunction</span>({});
30931cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
30941cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isFunction</span>(<span class="hljs-title class_">Foo</span>);
30951cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
30961cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isFunction</span>(<span class="hljs-title class_">Bar</span>);
30971cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span></code> <button class="copy-button">copy</button></pre>
30981cb0ef41Sopenharmony_ci<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>
30991cb0ef41Sopenharmony_ci<div class="api_metadata">
31001cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
31011cb0ef41Sopenharmony_ci</div>
31021cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <code>value === null</code> instead.</div><p></p>
31031cb0ef41Sopenharmony_ci<ul>
31041cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
31051cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
31061cb0ef41Sopenharmony_ci</ul>
31071cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is strictly <code>null</code>. Otherwise, returns
31081cb0ef41Sopenharmony_ci<code>false</code>.</p>
31091cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
31101cb0ef41Sopenharmony_ci
31111cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isNull</span>(<span class="hljs-number">0</span>);
31121cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
31131cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isNull</span>(<span class="hljs-literal">undefined</span>);
31141cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
31151cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isNull</span>(<span class="hljs-literal">null</span>);
31161cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span></code> <button class="copy-button">copy</button></pre>
31171cb0ef41Sopenharmony_ci<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>
31181cb0ef41Sopenharmony_ci<div class="api_metadata">
31191cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
31201cb0ef41Sopenharmony_ci</div>
31211cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use
31221cb0ef41Sopenharmony_ci<code>value === undefined || value === null</code> instead.</div><p></p>
31231cb0ef41Sopenharmony_ci<ul>
31241cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
31251cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
31261cb0ef41Sopenharmony_ci</ul>
31271cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is <code>null</code> or <code>undefined</code>. Otherwise,
31281cb0ef41Sopenharmony_cireturns <code>false</code>.</p>
31291cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
31301cb0ef41Sopenharmony_ci
31311cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isNullOrUndefined</span>(<span class="hljs-number">0</span>);
31321cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
31331cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isNullOrUndefined</span>(<span class="hljs-literal">undefined</span>);
31341cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
31351cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isNullOrUndefined</span>(<span class="hljs-literal">null</span>);
31361cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span></code> <button class="copy-button">copy</button></pre>
31371cb0ef41Sopenharmony_ci<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>
31381cb0ef41Sopenharmony_ci<div class="api_metadata">
31391cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
31401cb0ef41Sopenharmony_ci</div>
31411cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <code>typeof value === 'number'</code> instead.</div><p></p>
31421cb0ef41Sopenharmony_ci<ul>
31431cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
31441cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
31451cb0ef41Sopenharmony_ci</ul>
31461cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is a <code>Number</code>. Otherwise, returns <code>false</code>.</p>
31471cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
31481cb0ef41Sopenharmony_ci
31491cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isNumber</span>(<span class="hljs-literal">false</span>);
31501cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
31511cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isNumber</span>(<span class="hljs-title class_">Infinity</span>);
31521cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
31531cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isNumber</span>(<span class="hljs-number">0</span>);
31541cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
31551cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isNumber</span>(<span class="hljs-title class_">NaN</span>);
31561cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span></code> <button class="copy-button">copy</button></pre>
31571cb0ef41Sopenharmony_ci<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>
31581cb0ef41Sopenharmony_ci<div class="api_metadata">
31591cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
31601cb0ef41Sopenharmony_ci</div>
31611cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated:
31621cb0ef41Sopenharmony_ciUse <code>value !== null &#x26;&#x26; typeof value === 'object'</code> instead.</div><p></p>
31631cb0ef41Sopenharmony_ci<ul>
31641cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
31651cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
31661cb0ef41Sopenharmony_ci</ul>
31671cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is strictly an <code>Object</code> <strong>and</strong> not a
31681cb0ef41Sopenharmony_ci<code>Function</code> (even though functions are objects in JavaScript).
31691cb0ef41Sopenharmony_ciOtherwise, returns <code>false</code>.</p>
31701cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
31711cb0ef41Sopenharmony_ci
31721cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isObject</span>(<span class="hljs-number">5</span>);
31731cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
31741cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isObject</span>(<span class="hljs-literal">null</span>);
31751cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
31761cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isObject</span>({});
31771cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
31781cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isObject</span>(<span class="hljs-function">() =></span> {});
31791cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span></code> <button class="copy-button">copy</button></pre>
31801cb0ef41Sopenharmony_ci<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>
31811cb0ef41Sopenharmony_ci<div class="api_metadata">
31821cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
31831cb0ef41Sopenharmony_ci</div>
31841cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use
31851cb0ef41Sopenharmony_ci<code>(typeof value !== 'object' &#x26;&#x26; typeof value !== 'function') || value === null</code>
31861cb0ef41Sopenharmony_ciinstead.</div><p></p>
31871cb0ef41Sopenharmony_ci<ul>
31881cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
31891cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
31901cb0ef41Sopenharmony_ci</ul>
31911cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is a primitive type. Otherwise, returns
31921cb0ef41Sopenharmony_ci<code>false</code>.</p>
31931cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
31941cb0ef41Sopenharmony_ci
31951cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isPrimitive</span>(<span class="hljs-number">5</span>);
31961cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
31971cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isPrimitive</span>(<span class="hljs-string">'foo'</span>);
31981cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
31991cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isPrimitive</span>(<span class="hljs-literal">false</span>);
32001cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
32011cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isPrimitive</span>(<span class="hljs-literal">null</span>);
32021cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
32031cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isPrimitive</span>(<span class="hljs-literal">undefined</span>);
32041cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
32051cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isPrimitive</span>({});
32061cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
32071cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isPrimitive</span>(<span class="hljs-function">() =></span> {});
32081cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
32091cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isPrimitive</span>(<span class="hljs-regexp">/^$/</span>);
32101cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
32111cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isPrimitive</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>());
32121cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span></code> <button class="copy-button">copy</button></pre>
32131cb0ef41Sopenharmony_ci<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>
32141cb0ef41Sopenharmony_ci<div class="api_metadata">
32151cb0ef41Sopenharmony_ci<span>Added in: v0.6.0</span><span>Deprecated since: v4.0.0</span>
32161cb0ef41Sopenharmony_ci</div>
32171cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated</div><p></p>
32181cb0ef41Sopenharmony_ci<ul>
32191cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
32201cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
32211cb0ef41Sopenharmony_ci</ul>
32221cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is a <code>RegExp</code>. Otherwise, returns <code>false</code>.</p>
32231cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
32241cb0ef41Sopenharmony_ci
32251cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isRegExp</span>(<span class="hljs-regexp">/some regexp/</span>);
32261cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
32271cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isRegExp</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">RegExp</span>(<span class="hljs-string">'another regexp'</span>));
32281cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
32291cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isRegExp</span>({});
32301cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span></code> <button class="copy-button">copy</button></pre>
32311cb0ef41Sopenharmony_ci<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>
32321cb0ef41Sopenharmony_ci<div class="api_metadata">
32331cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
32341cb0ef41Sopenharmony_ci</div>
32351cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <code>typeof value === 'string'</code> instead.</div><p></p>
32361cb0ef41Sopenharmony_ci<ul>
32371cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
32381cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
32391cb0ef41Sopenharmony_ci</ul>
32401cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is a <code>string</code>. Otherwise, returns <code>false</code>.</p>
32411cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
32421cb0ef41Sopenharmony_ci
32431cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isString</span>(<span class="hljs-string">''</span>);
32441cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
32451cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isString</span>(<span class="hljs-string">'foo'</span>);
32461cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
32471cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isString</span>(<span class="hljs-title class_">String</span>(<span class="hljs-string">'foo'</span>));
32481cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
32491cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isString</span>(<span class="hljs-number">5</span>);
32501cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span></code> <button class="copy-button">copy</button></pre>
32511cb0ef41Sopenharmony_ci<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>
32521cb0ef41Sopenharmony_ci<div class="api_metadata">
32531cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
32541cb0ef41Sopenharmony_ci</div>
32551cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <code>typeof value === 'symbol'</code> instead.</div><p></p>
32561cb0ef41Sopenharmony_ci<ul>
32571cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
32581cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
32591cb0ef41Sopenharmony_ci</ul>
32601cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is a <code>Symbol</code>. Otherwise, returns <code>false</code>.</p>
32611cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
32621cb0ef41Sopenharmony_ci
32631cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isSymbol</span>(<span class="hljs-number">5</span>);
32641cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
32651cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isSymbol</span>(<span class="hljs-string">'foo'</span>);
32661cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
32671cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isSymbol</span>(<span class="hljs-title class_">Symbol</span>(<span class="hljs-string">'foo'</span>));
32681cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span></code> <button class="copy-button">copy</button></pre>
32691cb0ef41Sopenharmony_ci<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>
32701cb0ef41Sopenharmony_ci<div class="api_metadata">
32711cb0ef41Sopenharmony_ci<span>Added in: v0.11.5</span><span>Deprecated since: v4.0.0</span>
32721cb0ef41Sopenharmony_ci</div>
32731cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <code>value === undefined</code> instead.</div><p></p>
32741cb0ef41Sopenharmony_ci<ul>
32751cb0ef41Sopenharmony_ci<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
32761cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
32771cb0ef41Sopenharmony_ci</ul>
32781cb0ef41Sopenharmony_ci<p>Returns <code>true</code> if the given <code>object</code> is <code>undefined</code>. Otherwise, returns <code>false</code>.</p>
32791cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
32801cb0ef41Sopenharmony_ci
32811cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> foo = <span class="hljs-literal">undefined</span>;
32821cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isUndefined</span>(<span class="hljs-number">5</span>);
32831cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span>
32841cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isUndefined</span>(foo);
32851cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: true</span>
32861cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">isUndefined</span>(<span class="hljs-literal">null</span>);
32871cb0ef41Sopenharmony_ci<span class="hljs-comment">// Returns: false</span></code> <button class="copy-button">copy</button></pre>
32881cb0ef41Sopenharmony_ci<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>
32891cb0ef41Sopenharmony_ci<div class="api_metadata">
32901cb0ef41Sopenharmony_ci<span>Added in: v0.3.0</span><span>Deprecated since: v6.0.0</span>
32911cb0ef41Sopenharmony_ci</div>
32921cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use a third party module instead.</div><p></p>
32931cb0ef41Sopenharmony_ci<ul>
32941cb0ef41Sopenharmony_ci<li><code>string</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
32951cb0ef41Sopenharmony_ci</ul>
32961cb0ef41Sopenharmony_ci<p>The <code>util.log()</code> method prints the given <code>string</code> to <code>stdout</code> with an included
32971cb0ef41Sopenharmony_citimestamp.</p>
32981cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
32991cb0ef41Sopenharmony_ci
33001cb0ef41Sopenharmony_ciutil.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Timestamped message.'</span>);</code> <button class="copy-button">copy</button></pre></section>
33011cb0ef41Sopenharmony_ci        <!-- API END -->
33021cb0ef41Sopenharmony_ci      </div>
33031cb0ef41Sopenharmony_ci    </div>
33041cb0ef41Sopenharmony_ci  </div>
33051cb0ef41Sopenharmony_ci</body>
33061cb0ef41Sopenharmony_ci</html>
3307