Skip to content

Commit 95955a1

Browse files
mscdexrvagg
authored andcommitted
doc: update util methods
PR-URL: #350 Reviewed-By: Rod Vagg <[email protected]>
1 parent d188297 commit 95955a1

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

doc/api/util.markdown

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,180 @@ Returns `true` if the given "object" is an `Error`. `false` otherwise.
223223
// false
224224

225225

226+
## util.isBoolean(object)
227+
228+
Returns `true` if the given "object" is a `Boolean`. `false` otherwise.
229+
230+
var util = require('util');
231+
232+
util.isBoolean(1)
233+
// false
234+
util.isBoolean(0)
235+
// false
236+
util.isBoolean(false)
237+
// true
238+
239+
240+
## util.isNull(object)
241+
242+
Returns `true` if the given "object" is strictly `null`. `false` otherwise.
243+
244+
var util = require('util');
245+
246+
util.isNull(0)
247+
// false
248+
util.isNull(undefined)
249+
// false
250+
util.isNull(null)
251+
// true
252+
253+
254+
## util.isNullOrUndefined(object)
255+
256+
Returns `true` if the given "object" is `null` or `undefined`. `false` otherwise.
257+
258+
var util = require('util');
259+
260+
util.isNullOrUndefined(0)
261+
// false
262+
util.isNullOrUndefined(undefined)
263+
// true
264+
util.isNullOrUndefined(null)
265+
// true
266+
267+
268+
## util.isNumber(object)
269+
270+
Returns `true` if the given "object" is a `Number`. `false` otherwise.
271+
272+
var util = require('util');
273+
274+
util.isNumber(false)
275+
// false
276+
util.isNumber(Infinity)
277+
// true
278+
util.isNumber(0)
279+
// true
280+
util.isNumber(NaN)
281+
// true
282+
283+
284+
## util.isString(object)
285+
286+
Returns `true` if the given "object" is a `String`. `false` otherwise.
287+
288+
var util = require('util');
289+
290+
util.isString('')
291+
// true
292+
util.isString('foo')
293+
// true
294+
util.isString(String('foo'))
295+
// true
296+
util.isString(5)
297+
// false
298+
299+
300+
## util.isSymbol(object)
301+
302+
Returns `true` if the given "object" is a `Symbol`. `false` otherwise.
303+
304+
var util = require('util');
305+
306+
util.isSymbol(5)
307+
// false
308+
util.isSymbol('foo')
309+
// false
310+
util.isSymbol(Symbol('foo'))
311+
// true
312+
313+
314+
## util.isUndefined(object)
315+
316+
Returns `true` if the given "object" is `undefined`. `false` otherwise.
317+
318+
var util = require('util');
319+
320+
var foo;
321+
util.isUndefined(5)
322+
// false
323+
util.isUndefined(foo)
324+
// true
325+
util.isUndefined(null)
326+
// false
327+
328+
329+
## util.isObject(object)
330+
331+
Returns `true` if the given "object" is strictly an `Object`. `false` otherwise.
332+
333+
var util = require('util');
334+
335+
util.isObject(5)
336+
// false
337+
util.isObject(null)
338+
// false
339+
util.isObject({})
340+
// true
341+
342+
343+
## util.isFunction(object)
344+
345+
Returns `true` if the given "object" is a `Function`. `false` otherwise.
346+
347+
var util = require('util');
348+
349+
function Foo() {}
350+
var Bar = function() {};
351+
352+
util.isFunction({})
353+
// false
354+
util.isFunction(Foo)
355+
// true
356+
util.isFunction(Bar)
357+
// true
358+
359+
360+
## util.isPrimitive(object)
361+
362+
Returns `true` if the given "object" is a primitive type. `false` otherwise.
363+
364+
var util = require('util');
365+
366+
util.isPrimitive(5)
367+
// true
368+
util.isPrimitive('foo')
369+
// true
370+
util.isPrimitive(false)
371+
// true
372+
util.isPrimitive(null)
373+
// true
374+
util.isPrimitive(undefined)
375+
// true
376+
util.isPrimitive({})
377+
// false
378+
util.isPrimitive(function() {})
379+
// false
380+
util.isPrimitive(/^$/)
381+
// false
382+
util.isPrimitive(new Date())
383+
// false
384+
385+
386+
## util.isBuffer(object)
387+
388+
Returns `true` if the given "object" is a `Buffer`. `false` otherwise.
389+
390+
var util = require('util');
391+
392+
util.isPrimitive({ length: 0 })
393+
// false
394+
util.isPrimitive([])
395+
// false
396+
util.isPrimitive(new Buffer('hello world'))
397+
// true
398+
399+
226400
## util.inherits(constructor, superConstructor)
227401

228402
Inherit the prototype methods from one

0 commit comments

Comments
 (0)