Skip to content

doc: update util methods #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions doc/api/util.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,180 @@ Returns `true` if the given "object" is an `Error`. `false` otherwise.
// false


## util.isBoolean(object)

Returns `true` if the given "object" is a `Boolean`. `false` otherwise.

var util = require('util');

util.isBoolean(1)
// false
util.isBoolean(0)
// false
util.isBoolean(false)
// true


## util.isNull(object)

Returns `true` if the given "object" is strictly `null`. `false` otherwise.

var util = require('util');

util.isNull(0)
// false
util.isNull(undefined)
// false
util.isNull(null)
// true


## util.isNullOrUndefined(object)

Returns `true` if the given "object" is `null` or `undefined`. `false` otherwise.

var util = require('util');

util.isNullOrUndefined(0)
// false
util.isNullOrUndefined(undefined)
// true
util.isNullOrUndefined(null)
// true


## util.isNumber(object)

Returns `true` if the given "object" is a `Number`. `false` otherwise.

var util = require('util');

util.isNumber(false)
// false
util.isNumber(Infinity)
// true
util.isNumber(0)
// true
util.isNumber(NaN)
// true


## util.isString(object)

Returns `true` if the given "object" is a `String`. `false` otherwise.

var util = require('util');

util.isString('')
// true
util.isString('foo')
// true
util.isString(String('foo'))
// true
util.isString(5)
// false


## util.isSymbol(object)

Returns `true` if the given "object" is a `Symbol`. `false` otherwise.

var util = require('util');

util.isSymbol(5)
// false
util.isSymbol('foo')
// false
util.isSymbol(Symbol('foo'))
// true


## util.isUndefined(object)

Returns `true` if the given "object" is `undefined`. `false` otherwise.

var util = require('util');

var foo;
util.isUndefined(5)
// false
util.isUndefined(foo)
// true
util.isUndefined(null)
// false


## util.isObject(object)

Returns `true` if the given "object" is strictly an `Object`. `false` otherwise.

var util = require('util');

util.isObject(5)
// false
util.isObject(null)
// false
util.isObject({})
// true


## util.isFunction(object)

Returns `true` if the given "object" is a `Function`. `false` otherwise.

var util = require('util');

function Foo() {}
var Bar = function() {};

util.isFunction({})
// false
util.isFunction(Foo)
// true
util.isFunction(Bar)
// true


## util.isPrimitive(object)

Returns `true` if the given "object" is a primitive type. `false` otherwise.

var util = require('util');

util.isPrimitive(5)
// true
util.isPrimitive('foo')
// true
util.isPrimitive(false)
// true
util.isPrimitive(null)
// true
util.isPrimitive(undefined)
// true
util.isPrimitive({})
// false
util.isPrimitive(function() {})
// false
util.isPrimitive(/^$/)
// false
util.isPrimitive(new Date())
// false


## util.isBuffer(object)

Returns `true` if the given "object" is a `Buffer`. `false` otherwise.

var util = require('util');

util.isPrimitive({ length: 0 })
// false
util.isPrimitive([])
// false
util.isPrimitive(new Buffer('hello world'))
// true


## util.inherits(constructor, superConstructor)

Inherit the prototype methods from one
Expand Down