Skip to main content

Usage in Deno

import * as mod from "node:util";

The node:util module supports the needs of Node.js internal APIs. Many of the utilities are useful for application and module developers as well. To access it:

import util from 'node:util';

Classes #

c
c
v
TextDecoder

An implementation of the WHATWG Encoding Standard TextDecoder API.

c
v
TextEncoder

An implementation of the WHATWG Encoding Standard TextEncoder API. All instances of TextEncoder only support UTF-8 encoding.

Functions #

f
aborted

Listens to abort event on the provided signal and returns a promise that resolves when the signal is aborted. If resource is provided, it weakly references the operation's associated object, so if resource is garbage collected before the signal aborts, then returned promise shall remain pending. This prevents memory leaks in long-running or non-cancelable operations.

    f
    callbackify

    Takes an async function (or a function that returns a Promise) and returns a function following the error-first callback style, i.e. taking an (err, value) => ... callback as the last argument. In the callback, the first argument will be the rejection reason (or null if the Promise resolved), and the second argument will be the resolved value.

      f
      debuglog

      The util.debuglog() method is used to create a function that conditionally writes debug messages to stderr based on the existence of the NODE_DEBUGenvironment variable. If the section name appears within the value of that environment variable, then the returned function operates similar to console.error(). If not, then the returned function is a no-op.

        f
        deprecate

        The util.deprecate() method wraps fn (which may be a function or class) in such a way that it is marked as deprecated.

          f
          format

          The util.format() method returns a formatted string using the first argument as a printf-like format string which can contain zero or more format specifiers. Each specifier is replaced with the converted value from the corresponding argument. Supported specifiers are:

            f
            formatWithOptions

            This function is identical to format, except in that it takes an inspectOptions argument which specifies options that are passed along to inspect.

              f
              getCallSites

              Returns an array of call site objects containing the stack of the caller function.

                f
                getSystemErrorMap
                No documentation available
                  f
                  getSystemErrorMessage

                  Returns the string message for a numeric error code that comes from a Node.js API. The mapping between error codes and string messages is platform-dependent.

                    f
                    getSystemErrorName

                    Returns the string name for a numeric error code that comes from a Node.js API. The mapping between error codes and error names is platform-dependent. See Common System Errors for the names of common errors.

                      f
                      inherits

                      Usage of util.inherits() is discouraged. Please use the ES6 class and extends keywords to get language level inheritance support. Also note that the two styles are semantically incompatible.

                        f
                        N
                        inspect

                        The util.inspect() method returns a string representation of object that is intended for debugging. The output of util.inspect may change at any time and should not be depended upon programmatically. Additional options may be passed that alter the result. util.inspect() will use the constructor's name and/or @@toStringTag to make an identifiable tag for an inspected value.

                          f
                          isDeepStrictEqual

                          Returns true if there is deep strict equality between val1 and val2. Otherwise, returns false.

                            f
                            parseArgs

                            Provides a higher level API for command-line argument parsing than interacting with process.argv directly. Takes a specification for the expected arguments and returns a structured object with the parsed options and positionals.

                              f
                              parseEnv

                              Stability: 1.1 - Active development Given an example .env file:

                                f
                                N
                                promisify

                                Takes a function following the common error-first callback style, i.e. taking an (err, value) => ... callback as the last argument, and returns a version that returns promises.

                                  f
                                  stripVTControlCharacters

                                  Returns str with any ANSI escape codes removed.

                                    f
                                    styleText

                                    This function returns a formatted text considering the format passed.

                                      f
                                      toUSVString

                                      Returns the string after replacing any surrogate code points (or equivalently, any unpaired surrogate code units) with the Unicode "replacement character" U+FFFD.

                                        f
                                        transferableAbortController
                                        No documentation available
                                          f
                                          transferableAbortSignal
                                          No documentation available
                                            f
                                            types.isAnyArrayBuffer

                                            Returns true if the value is a built-in ArrayBuffer or SharedArrayBuffer instance.

                                              f
                                              types.isArgumentsObject

                                              Returns true if the value is an arguments object.

                                                f