Permalink
Browse files

Add docs for the type checking functions in `util.js`.

  • Loading branch information...
1 parent 677a894 commit 86f969898044c770ef352415f355f83cefc48305 @TooTallNate committed Oct 26, 2011
Showing with 56 additions and 0 deletions.
  1. +56 −0 doc/api/util.markdown
View
@@ -70,6 +70,62 @@ Example of inspecting all properties of the `util` object:
console.log(util.inspect(util, true, null));
+### util.isArray(object)
+
+Returns `true` if the given "object" is an `Array`. `false` otherwise.
+
+ var util = require('util');
+
+ util.isArray([])
+ // true
+ util.isArray(new Array)
+ // true
+ util.isArray({})
+ // false
+
+
+### util.isRegExp(object)
+
+Returns `true` if the given "object" is a `RegExp`. `false` otherwise.
+
+ var util = require('util');
+
+ util.isRegExp(/some regexp/)
+ // true
+ util.isRegExp(new RegExp('another regexp'))
+ // true
+ util.isRegExp({})
+ // false
+
+
+### util.isDate(object)
+
+Returns `true` if the given "object" is a `Date`. `false` otherwise.
+
+ var util = require('util');
+
+ util.isDate(new Date())
+ // true
+ util.isDate(Date())
+ // false (without 'new' returns a String)
+ util.isDate({})
+ // false
+
+
+### util.isError(object)
+
+Returns `true` if the given "object" is an `Error`. `false` otherwise.
+
+ var util = require('util');
+
+ util.isError(new Error())
+ // true
+ util.isError(new TypeError())
+ // true
+ util.isError({ name: 'Error', message: 'an error occurred' })
+ // false
+
+
### util.pump(readableStream, writableStream, [callback])
Experimental

0 comments on commit 86f9698

Please sign in to comment.