Skip to content
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

feat: add isNil for type checking #645

Merged
merged 2 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down