Index - Node documentation

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:

const util = require('node:util');

Classes

c
MIMEParams

The MIMEParams API provides read and write access to the parameters of aMIMEType.

c
MIMEType

An implementation of the MIMEType class.

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 is fulfilled when the signal is aborted. If the passed resource is garbage collected before the signal is aborted, the returned promise shall remain pending indefinitely.

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 Promiseresolved), 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
getSystemErrorMap

Returns a Map of all system error codes available from the Node.js API. The mapping between error codes and error names is platform-dependent. See Common System Errors for the names of common errors.

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 andextends 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
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
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

Creates and returns an AbortController instance whose AbortSignal is marked as transferable and can be used with structuredClone() or postMessage().

f
transferableAbortSignal

Marks the given AbortSignal as transferable so that it can be used withstructuredClone() and postMessage().

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
types.isArrayBuffer

Returns true if the value is a built-in ArrayBuffer instance. This does not include SharedArrayBuffer instances. Usually, it is desirable to test for both; See util.types.isAnyArrayBuffer() for that.

f
types.isArrayBufferView

Returns true if the value is an instance of one of the ArrayBuffer views, such as typed array objects or DataView. Equivalent to ArrayBuffer.isView().

f
types.isAsyncFunction

Returns true if the value is an async function. This only reports back what the JavaScript engine is seeing; in particular, the return value may not match the original source code if a transpilation tool was used.

f
types.isBigInt64Array

Returns true if the value is a BigInt64Array instance.

f
types.isBigUint64Array

Returns true if the value is a BigUint64Array instance.

f
types.isBooleanObject

Returns true if the value is a boolean object, e.g. created by new Boolean().

f
types.isBoxedPrimitive

Returns true if the value is any boxed primitive object, e.g. created by new Boolean(), new String() or Object(Symbol()).

f
types.isCryptoKey

Returns true if value is a CryptoKey, false otherwise.

f
types.isDataView

Returns true if the value is a built-in DataView instance.

f
types.isDate

Returns true if the value is a built-in Date instance.

f
types.isExternal

Returns true if the value is a native External value.

f
types.isFloat32Array

Returns true if the value is a built-in Float32Array instance.

f
types.isFloat64Array

Returns true if the value is a built-in Float64Array instance.

f
types.isGeneratorFunction

Returns true if the value is a generator function. This only reports back what the JavaScript engine is seeing; in particular, the return value may not match the original source code if a transpilation tool was used.

f
types.isGeneratorObject

Returns true if the value is a generator object as returned from a built-in generator function. This only reports back what the JavaScript engine is seeing; in particular, the return value may not match the original source code if a transpilation tool was used.

f
types.isInt16Array

Returns true if the value is a built-in Int16Array instance.

f
types.isInt32Array

Returns true if the value is a built-in Int32Array instance.

f
types.isInt8Array

Returns true if the value is a built-in Int8Array instance.

f
types.isKeyObject

Returns true if value is a KeyObject, false otherwise.

f
types.isMap

Returns true if the value is a built-in Map instance.

f
types.isMapIterator

Returns true if the value is an iterator returned for a built-in Map instance.

f
types.isModuleNamespaceObject

Returns true if the value is an instance of a Module Namespace Object.

f
types.isNativeError

Returns true if the value was returned by the constructor of a built-in Error type.

f
types.isNumberObject

Returns true if the value is a number object, e.g. created by new Number().

f
types.isPromise

Returns true if the value is a built-in Promise.

f
types.isProxy

Returns true if the value is a Proxy instance.

f
types.isRegExp

Returns true if the value is a regular expression object.

f
types.isSet

Returns true if the value is a built-in Set instance.

f
types.isSetIterator

Returns true if the value is an iterator returned for a built-in Set instance.

f
types.isSharedArrayBuffer

Returns true if the value is a built-in SharedArrayBuffer instance. This does not include ArrayBuffer instances. Usually, it is desirable to test for both; See util.types.isAnyArrayBuffer() for that.

f
types.isStringObject

Returns true if the value is a string object, e.g. created by new String().

f
types.isSymbolObject

Returns true if the value is a symbol object, created by calling Object() on a Symbol primitive.

f
types.isTypedArray

Returns true if the value is a built-in TypedArray instance.

f
types.isUint16Array

Returns true if the value is a built-in Uint16Array instance.

f
types.isUint32Array

Returns true if the value is a built-in Uint32Array instance.

f
types.isUint8Array

Returns true if the value is a built-in Uint8Array instance.

f
types.isUint8ClampedArray

Returns true if the value is a built-in Uint8ClampedArray instance.

f
types.isWeakMap

Returns true if the value is a built-in WeakMap instance.

f
types.isWeakSet

Returns true if the value is a built-in WeakSet instance.

f
f
isBoolean

Returns true if the given object is a Boolean. Otherwise, returns false.

f
isBuffer

Returns true if the given object is a Buffer. Otherwise, returns false.

f
isDate

Returns true if the given object is a Date. Otherwise, returns false.

f
isError

Returns true if the given object is an Error. Otherwise, returnsfalse.

f
isFunction

Returns true if the given object is a Function. Otherwise, returnsfalse.

f
isNull

Returns true if the given object is strictly null. Otherwise, returnsfalse.

f
isNullOrUndefined

Returns true if the given object is null or undefined. Otherwise, returns false.

f
isNumber

Returns true if the given object is a Number. Otherwise, returns false.

f
isObject

Returns true if the given object is strictly an Objectand not aFunction (even though functions are objects in JavaScript). Otherwise, returns false.

f
isPrimitive

Returns true if the given object is a primitive type. Otherwise, returnsfalse.

f
isRegExp

Returns true if the given object is a RegExp. Otherwise, returns false.

f
isString

Returns true if the given object is a string. Otherwise, returns false.

f
isSymbol

Returns true if the given object is a Symbol. Otherwise, returns false.

f
isUndefined

Returns true if the given object is undefined. Otherwise, returns false.

f
log

The util.log() method prints the given string to stdout with an included timestamp.

Interfaces

I
CustomPromisifyLegacy
No documentation available
I
CustomPromisifySymbol
No documentation available
I
DebugLogger
No documentation available
I
EncodeIntoResult
No documentation available
I
InspectOptions
No documentation available
I
InspectOptionsStylized
No documentation available
I
ParseArgsConfig
No documentation available
I
ParseArgsOptionConfig
No documentation available
I
ParseArgsOptionsConfig
No documentation available

Namespaces

N
types
No documentation available

Type Aliases

T
CustomInspectFunction
No documentation available
T
CustomPromisify
No documentation available
T
DebugLoggerFunction
No documentation available
T
ExtractOptionValue
No documentation available
T
IfDefaultsFalse
No documentation available
T
IfDefaultsTrue
No documentation available
T
OptionToken
No documentation available
T
ParsedOptionToken
No documentation available
T
ParsedPositionals
No documentation available
T
ParsedPositionalToken
No documentation available
T
ParsedResults
No documentation available
T
ParsedTokens
No documentation available
T
ParsedValues
No documentation available
T
PreciseParsedResults
No documentation available
T
PreciseTokenForOptions
No documentation available
T
Style
No documentation available
T
Token
No documentation available
T
TokenForOptions
No documentation available

Variables

v
debug
No documentation available
v
inspect.colors
No documentation available
v
inspect.custom

That can be used to declare custom inspect functions.

v
inspect.defaultOptions
No documentation available
v
inspect.replDefaults

Allows changing inspect settings from the repl.

v
inspect.styles
No documentation available
v
promisify.custom

That can be used to declare custom promisified variants of functions.