{ "source": "doc/api/util.md", "modules": [ { "textRaw": "util", "name": "util", "stability": 2, "stabilityText": "Stable", "desc": "
The util
module is primarily designed to support the needs of Node.js' own\ninternal APIs. However, many of the utilities are useful for application and\nmodule developers as well. It can be accessed using:
const util = require('util');\n
\n",
"methods": [
{
"textRaw": "util.debuglog(section)",
"type": "method",
"name": "debuglog",
"meta": {
"added": [
"v0.11.3"
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Function} The logging function ",
"name": "return",
"type": "Function",
"desc": "The logging function"
},
"params": [
{
"textRaw": "`section` {String} A string identifying the portion of the application for which the `debuglog` function is being created. ",
"name": "section",
"type": "String",
"desc": "A string identifying the portion of the application for which the `debuglog` function is being created."
}
]
},
{
"params": [
{
"name": "section"
}
]
}
],
"desc": "The util.debuglog()
method is used to create a function that conditionally\nwrites debug messages to stderr
based on the existence of the NODE_DEBUG
\nenvironment variable. If the section
name appears within the value of that\nenvironment variable, then the returned function operates similar to\nconsole.error()
. If not, then the returned function is a no-op.
For example:
\nconst util = require('util');\nconst debuglog = util.debuglog('foo');\n\ndebuglog('hello from foo [%d]', 123);\n
\nIf this program is run with NODE_DEBUG=foo
in the environment, then\nit will output something like:
FOO 3245: hello from foo [123]\n
\nwhere 3245
is the process id. If it is not run with that\nenvironment variable set, then it will not print anything.
Multiple comma-separated section
names may be specified in the NODE_DEBUG
\nenvironment variable. For example: NODE_DEBUG=fs,net,tls
.
The util.deprecate()
method wraps the given function
or class in such a way that\nit is marked as deprecated.
const util = require('util');\n\nexports.puts = util.deprecate(function() {\n for (var i = 0, len = arguments.length; i < len; ++i) {\n process.stdout.write(arguments[i] + '\\n');\n }\n}, 'util.puts: Use console.log instead');\n
\nWhen called, util.deprecate()
will return a function that will emit a\nDeprecationWarning
using the process.on('warning')
event. By default,\nthis warning will be emitted and printed to stderr
exactly once, the first\ntime it is called. After the warning is emitted, the wrapped function
\nis called.
If either the --no-deprecation
or --no-warnings
command line flags are\nused, or if the process.noDeprecation
property is set to true
prior to\nthe first deprecation warning, the util.deprecate()
method does nothing.
If the --trace-deprecation
or --trace-warnings
command line flags are set,\nor the process.traceDeprecation
property is set to true
, a warning and a\nstack trace are printed to stderr
the first time the deprecated function is\ncalled.
If the --throw-deprecation
command line flag is set, or the\nprocess.throwDeprecation
property is set to true
, then an exception will be\nthrown when the deprecated function is called.
The --throw-deprecation
command line flag and process.throwDeprecation
\nproperty take precedence over --trace-deprecation
and\nprocess.traceDeprecation
.
The util.format()
method returns a formatted string using the first argument\nas a printf
-like format.
The first argument is a string containing zero or more placeholder tokens.\nEach placeholder token is replaced with the converted value from the\ncorresponding argument. Supported placeholders are:
\n%s
- String.%d
- Number (both integer and float).%j
- JSON. Replaced with the string '[Circular]'
if the argument\ncontains circular references.%%
- single percent sign ('%'
). This does not consume an argument.If the placeholder does not have a corresponding argument, the placeholder is\nnot replaced.
\nutil.format('%s:%s', 'foo');\n// Returns: 'foo:%s'\n
\nIf there are more arguments passed to the util.format()
method than the\nnumber of placeholders, the extra arguments are coerced into strings (for\nobjects and symbols, util.inspect()
is used) then concatenated to the\nreturned string, each delimited by a space.
util.format('%s:%s', 'foo', 'bar', 'baz'); // 'foo:bar baz'\n
\nIf the first argument is not a format string then util.format()
returns\na string that is the concatenation of all arguments separated by spaces.\nEach argument is converted to a string using util.inspect()
.
util.format(1, 2, 3); // '1 2 3'\n
\n"
},
{
"textRaw": "util.inherits(constructor, superConstructor)",
"type": "method",
"name": "inherits",
"meta": {
"added": [
"v0.3.0"
]
},
"desc": "Note: usage of util.inherits()
is discouraged. Please use the ES6 class
and\nextends
keywords to get language level inheritance support. Also note that\nthe two styles are semantically incompatible.
constructor
{Function}superConstructor
{Function}Inherit the prototype methods from one constructor into another. The\nprototype of constructor
will be set to a new object created from\nsuperConstructor
.
As an additional convenience, superConstructor
will be accessible\nthrough the constructor.super_
property.
const util = require('util');\nconst EventEmitter = require('events');\n\nfunction MyStream() {\n EventEmitter.call(this);\n}\n\nutil.inherits(MyStream, EventEmitter);\n\nMyStream.prototype.write = function(data) {\n this.emit('data', data);\n};\n\nconst stream = new MyStream();\n\nconsole.log(stream instanceof EventEmitter); // true\nconsole.log(MyStream.super_ === EventEmitter); // true\n\nstream.on('data', (data) => {\n console.log(`Received data: "${data}"`);\n});\nstream.write('It works!'); // Received data: "It works!"\n
\nES6 example using class
and extends
const EventEmitter = require('events');\n\nclass MyStream extends EventEmitter {\n constructor() {\n super();\n }\n write(data) {\n this.emit('data', data);\n }\n}\n\nconst stream = new MyStream();\n\nstream.on('data', (data) => {\n console.log(`Received data: "${data}"`);\n});\nstream.write('With ES6');\n
\n",
"signatures": [
{
"params": [
{
"name": "constructor"
},
{
"name": "superConstructor"
}
]
}
]
},
{
"textRaw": "util.inspect(object[, options])",
"type": "method",
"name": "inspect",
"meta": {
"added": [
"v0.3.0"
]
},
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} Any JavaScript primitive or Object. ",
"name": "object",
"type": "any",
"desc": "Any JavaScript primitive or Object."
},
{
"textRaw": "`options` {Object} ",
"options": [
{
"textRaw": "`showHidden` {boolean} If `true`, the `object`'s non-enumerable symbols and properties will be included in the formatted result. Defaults to `false`. ",
"name": "showHidden",
"type": "boolean",
"desc": "If `true`, the `object`'s non-enumerable symbols and properties will be included in the formatted result. Defaults to `false`."
},
{
"textRaw": "`depth` {number} Specifies the number of times to recurse while formatting the `object`. This is useful for inspecting large complicated objects. Defaults to `2`. To make it recurse indefinitely pass `null`. ",
"name": "depth",
"type": "number",
"desc": "Specifies the number of times to recurse while formatting the `object`. This is useful for inspecting large complicated objects. Defaults to `2`. To make it recurse indefinitely pass `null`."
},
{
"textRaw": "`colors` {boolean} If `true`, the output will be styled with ANSI color codes. Defaults to `false`. Colors are customizable, see [Customizing `util.inspect` colors][]. ",
"name": "colors",
"type": "boolean",
"desc": "If `true`, the output will be styled with ANSI color codes. Defaults to `false`. Colors are customizable, see [Customizing `util.inspect` colors][]."
},
{
"textRaw": "`customInspect` {boolean} If `false`, then custom `inspect(depth, opts)` functions exported on the `object` being inspected will not be called. Defaults to `true`. ",
"name": "customInspect",
"type": "boolean",
"desc": "If `false`, then custom `inspect(depth, opts)` functions exported on the `object` being inspected will not be called. Defaults to `true`."
},
{
"textRaw": "`showProxy` {boolean} If `true`, then objects and functions that are `Proxy` objects will be introspected to show their `target` and `handler` objects. Defaults to `false`. ",
"name": "showProxy",
"type": "boolean",
"desc": "If `true`, then objects and functions that are `Proxy` objects will be introspected to show their `target` and `handler` objects. Defaults to `false`."
},
{
"textRaw": "`maxArrayLength` {number} Specifies the maximum number of array and `TypedArray` elements to include when formatting. Defaults to `100`. Set to `null` to show all array elements. Set to `0` or negative to show no array elements. ",
"name": "maxArrayLength",
"type": "number",
"desc": "Specifies the maximum number of array and `TypedArray` elements to include when formatting. Defaults to `100`. Set to `null` to show all array elements. Set to `0` or negative to show no array elements."
},
{
"textRaw": "`breakLength` {number} The length at which an object's keys are split across multiple lines. Set to `Infinity` to format an object as a single line. Defaults to 60 for legacy compatibility. ",
"name": "breakLength",
"type": "number",
"desc": "The length at which an object's keys are split across multiple lines. Set to `Infinity` to format an object as a single line. Defaults to 60 for legacy compatibility."
}
],
"name": "options",
"type": "Object",
"optional": true
}
]
},
{
"params": [
{
"name": "object"
},
{
"name": "options",
"optional": true
}
]
}
],
"desc": "The util.inspect()
method returns a string representation of object
that is\nprimarily useful for debugging. Additional options
may be passed that alter\ncertain aspects of the formatted string.
The following example inspects all properties of the util
object:
const util = require('util');\n\nconsole.log(util.inspect(util, { showHidden: true, depth: null }));\n
\nValues may supply their own custom inspect(depth, opts)
functions, when\ncalled these receive the current depth
in the recursive inspection, as well as\nthe options object passed to util.inspect()
.
Color output (if enabled) of util.inspect
is customizable globally\nvia the util.inspect.styles
and util.inspect.colors
properties.
util.inspect.styles
is a map associating a style name to a color from\nutil.inspect.colors
.
The default styles and associated colors are:
\nnumber
- yellow
boolean
- yellow
string
- green
date
- magenta
regexp
- red
null
- bold
undefined
- grey
special
- cyan
(only applied to functions at this time)name
- (no styling)The predefined color codes are: white
, grey
, black
, blue
, cyan
,\ngreen
, magenta
, red
and yellow
. There are also bold
, italic
,\nunderline
and inverse
codes.
Color styling uses ANSI control codes that may not be supported on all\nterminals.
\n" }, { "textRaw": "Custom inspection functions on Objects", "name": "Custom inspection functions on Objects", "type": "misc", "desc": "Objects may also define their own [util.inspect.custom](depth, opts)
\n(or, equivalently inspect(depth, opts)
) function that util.inspect()
will\ninvoke and use the result of when inspecting the object:
const util = require('util');\n\nclass Box {\n constructor(value) {\n this.value = value;\n }\n\n inspect(depth, options) {\n if (depth < 0) {\n return options.stylize('[Box]', 'special');\n }\n\n const newOptions = Object.assign({}, options, {\n depth: options.depth === null ? null : options.depth - 1\n });\n\n // Five space padding because that's the size of "Box< ".\n const padding = ' '.repeat(5);\n const inner = util.inspect(this.value, newOptions).replace(/\\n/g, '\\n' + padding);\n return options.stylize('Box', 'special') + '< ' + inner + ' >';\n }\n}\n\nconst box = new Box(true);\n\nutil.inspect(box);\n// Returns: "Box< true >"\n
\nCustom [util.inspect.custom](depth, opts)
functions typically return a string\nbut may return a value of any type that will be formatted accordingly by\nutil.inspect()
.
const util = require('util');\n\nconst obj = { foo: 'this will not show up in the inspect() output' };\nobj[util.inspect.custom] = function(depth) {\n return { bar: 'baz' };\n};\n\nutil.inspect(obj);\n// Returns: "{ bar: 'baz' }"\n
\nA custom inspection method can alternatively be provided by exposing\nan inspect(depth, opts)
method on the object:
const util = require('util');\n\nconst obj = { foo: 'this will not show up in the inspect() output' };\nobj.inspect = function(depth) {\n return { bar: 'baz' };\n};\n\nutil.inspect(obj);\n// Returns: "{ bar: 'baz' }"\n
\n"
}
],
"modules": [
{
"textRaw": "util.inspect.defaultOptions",
"name": "util.inspect.defaultoptions",
"meta": {
"added": [
"v6.4.0"
]
},
"desc": "The defaultOptions
value allows customization of the default options used by\nutil.inspect
. This is useful for functions like console.log
or\nutil.format
which implicitly call into util.inspect
. It shall be set to an\nobject containing one or more valid util.inspect()
options. Setting\noption properties directly is also supported.
const util = require('util');\nconst arr = Array(101);\n\nconsole.log(arr); // logs the truncated array\nutil.inspect.defaultOptions.maxArrayLength = null;\nconsole.log(arr); // logs the full array\n
\n",
"type": "module",
"displayName": "util.inspect.defaultOptions"
},
{
"textRaw": "util.inspect.custom",
"name": "util.inspect.custom",
"meta": {
"added": [
"v6.6.0"
]
},
"desc": "A Symbol that can be used to declare custom inspect functions, see\nCustom inspection functions on Objects.
\n", "type": "module", "displayName": "util.inspect.custom" } ] } ], "modules": [ { "textRaw": "Deprecated APIs", "name": "deprecated_apis", "desc": "The following APIs have been deprecated and should no longer be used. Existing\napplications and modules should be updated to find alternative approaches.
\n", "methods": [ { "textRaw": "util.debug(string)", "type": "method", "name": "debug", "meta": { "added": [ "v0.3.0" ], "deprecated": [ "v0.11.3" ] }, "stability": 0, "stabilityText": "Deprecated: Use [`console.error()`][] instead.", "signatures": [ { "params": [ { "textRaw": "`string` {String} The message to print to `stderr` ", "name": "string", "type": "String", "desc": "The message to print to `stderr`" } ] }, { "params": [ { "name": "string" } ] } ], "desc": "Deprecated predecessor of console.error
.
Deprecated predecessor of console.error
.
Internal alias for Array.isArray
.
Returns true
if the given object
is an Array
. Otherwise, returns false
.
const util = require('util');\n\nutil.isArray([]);\n// Returns: true\nutil.isArray(new Array);\n// Returns: true\nutil.isArray({});\n// Returns: false\n
\n"
},
{
"textRaw": "util.isBoolean(object)",
"type": "method",
"name": "isBoolean",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is a Boolean
. Otherwise, returns false
.
const util = require('util');\n\nutil.isBoolean(1);\n// Returns: false\nutil.isBoolean(0);\n// Returns: false\nutil.isBoolean(false);\n// Returns: true\n
\n"
},
{
"textRaw": "util.isBuffer(object)",
"type": "method",
"name": "isBuffer",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated: Use [`Buffer.isBuffer()`][] instead.",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is a Buffer
. Otherwise, returns false
.
const util = require('util');\n\nutil.isBuffer({ length: 0 });\n// Returns: false\nutil.isBuffer([]);\n// Returns: false\nutil.isBuffer(Buffer.from('hello world'));\n// Returns: true\n
\n"
},
{
"textRaw": "util.isDate(object)",
"type": "method",
"name": "isDate",
"meta": {
"added": [
"v0.6.0"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is a Date
. Otherwise, returns false
.
const util = require('util');\n\nutil.isDate(new Date());\n// Returns: true\nutil.isDate(Date());\n// false (without 'new' returns a String)\nutil.isDate({});\n// Returns: false\n
\n"
},
{
"textRaw": "util.isError(object)",
"type": "method",
"name": "isError",
"meta": {
"added": [
"v0.6.0"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is an Error
. Otherwise, returns\nfalse
.
const util = require('util');\n\nutil.isError(new Error());\n// Returns: true\nutil.isError(new TypeError());\n// Returns: true\nutil.isError({ name: 'Error', message: 'an error occurred' });\n// Returns: false\n
\nNote that this method relies on Object.prototype.toString()
behavior. It is\npossible to obtain an incorrect result when the object
argument manipulates\n@@toStringTag
.
const util = require('util');\nconst obj = { name: 'Error', message: 'an error occurred' };\n\nutil.isError(obj);\n// Returns: false\nobj[Symbol.toStringTag] = 'Error';\nutil.isError(obj);\n// Returns: true\n
\n"
},
{
"textRaw": "util.isFunction(object)",
"type": "method",
"name": "isFunction",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is a Function
. Otherwise, returns\nfalse
.
const util = require('util');\n\nfunction Foo() {}\nconst Bar = function() {};\n\nutil.isFunction({});\n// Returns: false\nutil.isFunction(Foo);\n// Returns: true\nutil.isFunction(Bar);\n// Returns: true\n
\n"
},
{
"textRaw": "util.isNull(object)",
"type": "method",
"name": "isNull",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is strictly null
. Otherwise, returns\nfalse
.
const util = require('util');\n\nutil.isNull(0);\n// Returns: false\nutil.isNull(undefined);\n// Returns: false\nutil.isNull(null);\n// Returns: true\n
\n"
},
{
"textRaw": "util.isNullOrUndefined(object)",
"type": "method",
"name": "isNullOrUndefined",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is null
or undefined
. Otherwise,\nreturns false
.
const util = require('util');\n\nutil.isNullOrUndefined(0);\n// Returns: false\nutil.isNullOrUndefined(undefined);\n// Returns: true\nutil.isNullOrUndefined(null);\n// Returns: true\n
\n"
},
{
"textRaw": "util.isNumber(object)",
"type": "method",
"name": "isNumber",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is a Number
. Otherwise, returns false
.
const util = require('util');\n\nutil.isNumber(false);\n// Returns: false\nutil.isNumber(Infinity);\n// Returns: true\nutil.isNumber(0);\n// Returns: true\nutil.isNumber(NaN);\n// Returns: true\n
\n"
},
{
"textRaw": "util.isObject(object)",
"type": "method",
"name": "isObject",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is strictly an Object
and not a\nFunction
. Otherwise, returns false
.
const util = require('util');\n\nutil.isObject(5);\n// Returns: false\nutil.isObject(null);\n// Returns: false\nutil.isObject({});\n// Returns: true\nutil.isObject(function(){});\n// Returns: false\n
\n"
},
{
"textRaw": "util.isPrimitive(object)",
"type": "method",
"name": "isPrimitive",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is a primitive type. Otherwise, returns\nfalse
.
const util = require('util');\n\nutil.isPrimitive(5);\n// Returns: true\nutil.isPrimitive('foo');\n// Returns: true\nutil.isPrimitive(false);\n// Returns: true\nutil.isPrimitive(null);\n// Returns: true\nutil.isPrimitive(undefined);\n// Returns: true\nutil.isPrimitive({});\n// Returns: false\nutil.isPrimitive(function() {});\n// Returns: false\nutil.isPrimitive(/^$/);\n// Returns: false\nutil.isPrimitive(new Date());\n// Returns: false\n
\n"
},
{
"textRaw": "util.isRegExp(object)",
"type": "method",
"name": "isRegExp",
"meta": {
"added": [
"v0.6.0"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is a RegExp
. Otherwise, returns false
.
const util = require('util');\n\nutil.isRegExp(/some regexp/);\n// Returns: true\nutil.isRegExp(new RegExp('another regexp'));\n// Returns: true\nutil.isRegExp({});\n// Returns: false\n
\n"
},
{
"textRaw": "util.isString(object)",
"type": "method",
"name": "isString",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is a string
. Otherwise, returns false
.
const util = require('util');\n\nutil.isString('');\n// Returns: true\nutil.isString('foo');\n// Returns: true\nutil.isString(String('foo'));\n// Returns: true\nutil.isString(5);\n// Returns: false\n
\n"
},
{
"textRaw": "util.isSymbol(object)",
"type": "method",
"name": "isSymbol",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is a Symbol
. Otherwise, returns false
.
const util = require('util');\n\nutil.isSymbol(5);\n// Returns: false\nutil.isSymbol('foo');\n// Returns: false\nutil.isSymbol(Symbol('foo'));\n// Returns: true\n
\n"
},
{
"textRaw": "util.isUndefined(object)",
"type": "method",
"name": "isUndefined",
"meta": {
"added": [
"v0.11.5"
],
"deprecated": [
"v4.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated",
"signatures": [
{
"params": [
{
"textRaw": "`object` {any} ",
"name": "object",
"type": "any"
}
]
},
{
"params": [
{
"name": "object"
}
]
}
],
"desc": "Returns true
if the given object
is undefined
. Otherwise, returns false
.
const util = require('util');\n\nconst foo = undefined;\nutil.isUndefined(5);\n// Returns: false\nutil.isUndefined(foo);\n// Returns: true\nutil.isUndefined(null);\n// Returns: false\n
\n"
},
{
"textRaw": "util.log(string)",
"type": "method",
"name": "log",
"meta": {
"added": [
"v0.3.0"
],
"deprecated": [
"v6.0.0"
]
},
"stability": 0,
"stabilityText": "Deprecated: Use a third party module instead.",
"signatures": [
{
"params": [
{
"textRaw": "`string` {String} ",
"name": "string",
"type": "String"
}
]
},
{
"params": [
{
"name": "string"
}
]
}
],
"desc": "The util.log()
method prints the given string
to stdout
with an included\ntimestamp.
const util = require('util');\n\nutil.log('Timestamped message.');\n
\n"
},
{
"textRaw": "util.print([...strings])",
"type": "method",
"name": "print",
"meta": {
"added": [
"v0.3.0"
],
"deprecated": [
"v0.11.3"
]
},
"stability": 0,
"stabilityText": "Deprecated: Use [`console.log()`][] instead.",
"desc": "Deprecated predecessor of console.log
.
Deprecated predecessor of console.log
.
The util._extend()
method was never intended to be used outside of internal\nNode.js modules. The community found and used it anyway.
It is deprecated and should not be used in new code. JavaScript comes with very\nsimilar built-in functionality through Object.assign()
.