Members
isArray
static
isError
static
isBuffer
static
Methods
format(f) → string
static
Returns a formatted string using the first argument as a printf-like format.
The first argument is a string that contains zero or more placeholders. Each placeholder is replaced with the converted value from its corresponding argument. Supported placeholders are:
- %s - String.
- %d - Number (both integer and float).
- %j - JSON.
- % - single percent sign ('%'). This does not consume an argument.
If the placeholder does not have a corresponding argument, the placeholder is not replaced:
util.format('%s:%s', 'foo'); // 'foo:%s'
If there are more arguments than placeholders, the extra arguments are converted to strings with util.inspect() and these strings are concatenated, delimited by a space:
util.format('%s:%s', 'foo', 'bar', 'baz'); // 'foo:bar baz'
If the first argument is not a format string then util.format() returns a string that is the concatenation of all its arguments separated by spaces. Each argument is converted to a string with util.inspect():
util.format(1, 2, 3); // '1 2 3'
Arguments:
-
f
inspect(obj, opts)
inner
Echos the value of a value. Tries to print the value out
in the best way possible given the different types.
Arguments:
-
obj
(Object)
 The object to print out.
-
opts
(Object)
 Optional options object that alters the output.
isBoolean(arg) → boolean
inner
Arguments:
-
arg
isNull(arg) → boolean
inner
Arguments:
-
arg
isNullOrUndefined(arg) → boolean
inner
Arguments:
-
arg
isNumber(arg) → boolean
inner
Arguments:
-
arg
isString(arg) → boolean
inner
Arguments:
-
arg
isSymbol(arg) → boolean
inner
Arguments:
-
arg
isUndefined(arg) → boolean
inner
Arguments:
-
arg
isRegExp(re) → boolean
inner
Arguments:
-
re
isObject(arg) → boolean
inner
Arguments:
-
arg
isDate(d) → boolean
inner
Arguments:
-
d
isFunction(arg) → boolean
inner
Arguments:
-
arg
isPrimitive(arg) → boolean
inner
Arguments:
-
arg
log(msg)
static
Output with timestamp on stdout.
Arguments:
-
msg
(String)
inherits(ctor, superCtor)
static
Inherit the prototype methods from one constructor into another.
The Function.prototype.inherits from lang.js rewritten as a standalone
function (not on Function.prototype). NOTE: If this file is to be loaded
during bootstrapping this function needs to be rewritten using some native
functions as prototype setup using normal JavaScript does not work as
expected during bootstrapping (see mirror.js in r114903).
Arguments:
-
ctor
(function)
 Constructor function which needs to inherit the
prototype.
-
superCtor
(function)
 Constructor function to inherit prototype from.
Throws:
-
Will error if either constructor is null, or if
the super constructor lacks a prototype.
-
-
Type
-
TypeError
print(…arguments)
inner
A synchronous output function. Will block the process, cast each argument to a string then output to stdout. Does not place newlines after each argument:
util.print('one', 'two', 3); // onetwo3
Arguments:
-
...arguments
(*)
- Deprecated:
- Use
console.log
instead
puts(…arguments)
inner
A synchronous output function. Will block the process and output all arguments to stdout with newlines after each argument.
util.puts('one', 'two', 3); // one
// two
// 3
Arguments:
-
...arguments
(*)
- Deprecated:
- Use
console.log
instead
debug(msg)
inner
Will block the process and output string immediately to stderr:
require('util').debug('message on stderr');
Arguments:
-
msg
(*)
- Deprecated:
- Use
console.error
instead
error(…arguments)
inner
Same as util#debug
except this will output all arguments immediately to stderr.
Arguments:
-
...arguments
(*)
- Deprecated:
- Use
console.error
instead
format(f) → string static
Returns a formatted string using the first argument as a printf-like format.
The first argument is a string that contains zero or more placeholders. Each placeholder is replaced with the converted value from its corresponding argument. Supported placeholders are:
- %s - String.
- %d - Number (both integer and float).
- %j - JSON.
- % - single percent sign ('%'). This does not consume an argument.
If the placeholder does not have a corresponding argument, the placeholder is not replaced:
util.format('%s:%s', 'foo'); // 'foo:%s'
If there are more arguments than placeholders, the extra arguments are converted to strings with util.inspect() and these strings are concatenated, delimited by a space:
util.format('%s:%s', 'foo', 'bar', 'baz'); // 'foo:bar baz'
If the first argument is not a format string then util.format() returns a string that is the concatenation of all its arguments separated by spaces. Each argument is converted to a string with util.inspect():
util.format(1, 2, 3); // '1 2 3'
Arguments:
-
f
inspect(obj, opts) inner
Arguments:
-
obj
(Object)
 The object to print out. -
opts
(Object)
 Optional options object that alters the output.
isBoolean(arg) → boolean inner
Arguments:
-
arg
isNull(arg) → boolean inner
Arguments:
-
arg
isNullOrUndefined(arg) → boolean inner
Arguments:
-
arg
isNumber(arg) → boolean inner
Arguments:
-
arg
isString(arg) → boolean inner
Arguments:
-
arg
isSymbol(arg) → boolean inner
Arguments:
-
arg
isUndefined(arg) → boolean inner
Arguments:
-
arg
isRegExp(re) → boolean inner
Arguments:
-
re
isObject(arg) → boolean inner
Arguments:
-
arg
isDate(d) → boolean inner
Arguments:
-
d
isFunction(arg) → boolean inner
Arguments:
-
arg
isPrimitive(arg) → boolean inner
Arguments:
-
arg
log(msg) static
Arguments:
-
msg
(String)
inherits(ctor, superCtor) static
The Function.prototype.inherits from lang.js rewritten as a standalone function (not on Function.prototype). NOTE: If this file is to be loaded during bootstrapping this function needs to be rewritten using some native functions as prototype setup using normal JavaScript does not work as expected during bootstrapping (see mirror.js in r114903).
Arguments:
-
ctor
(function)
 Constructor function which needs to inherit the prototype. -
superCtor
(function)
 Constructor function to inherit prototype from.
Throws:
-
Will error if either constructor is null, or if the super constructor lacks a prototype.
- Type
- TypeError
print(…arguments) inner
A synchronous output function. Will block the process, cast each argument to a string then output to stdout. Does not place newlines after each argument:
util.print('one', 'two', 3); // onetwo3
Arguments:
-
...arguments
(*)
- Deprecated:
- Use
console.log
instead
- Use
puts(…arguments) inner
A synchronous output function. Will block the process and output all arguments to stdout with newlines after each argument.
util.puts('one', 'two', 3); // one
// two
// 3
Arguments:
-
...arguments
(*)
- Deprecated:
- Use
console.log
instead
- Use
debug(msg) inner
Will block the process and output string immediately to stderr:
require('util').debug('message on stderr');
Arguments:
-
msg
(*)
- Deprecated:
- Use
console.error
instead
- Use
error(…arguments) inner
util#debug
except this will output all arguments immediately to stderr.
Arguments:
-
...arguments
(*)
- Deprecated:
- Use
console.error
instead
- Use