diff --git a/lib/index.js b/lib/index.js index f06c7f8..9c05665 100755 --- a/lib/index.js +++ b/lib/index.js @@ -917,6 +917,20 @@ function StreamRedirect(to) { this.to = to; } +/** + * Returns true if `x` is the end of stream marker. + * + * @id isNil + * @section Streams + * @name _.isNil(x) + * @param x - the object to test + * @api public + */ + +_.isNil = function (x) { + return x === _.nil; +}; + /** * Returns true if `x` is a Highland Stream. * diff --git a/test/test.js b/test/test.js index 1e0c3a7..9ebf8a6 100755 --- a/test/test.js +++ b/test/test.js @@ -324,6 +324,19 @@ exports.seq = function (test) { test.done(); }; +exports.isNilTest = function (test) { + test.ok(_.isNil(_.nil)); + test.ok(!_.isNil()); + test.ok(!_.isNil(undefined)); + test.ok(!_.isNil(null)); + test.ok(!_.isNil(123)); + test.ok(!_.isNil({})); + test.ok(!_.isNil([])); + test.ok(!_.isNil('foo')); + test.ok(!_.isNil(_())); + test.done(); +}; + exports.isStream = function (test) { test.ok(!_.isStream()); test.ok(!_.isStream(undefined));