Skip to content

Commit

Permalink
fix: handle null as the root object
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Feb 21, 2017
1 parent 9c7867e commit 9a1631a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/undefsafe.js
Expand Up @@ -40,6 +40,11 @@ function undefsafe(obj, path, value) {
return res;
}

// bail if there's nothing
if (obj === undefined || obj === null) {
return undefined;
}

var parts = split(path);
var key = null;
var type = typeof obj;
Expand Down
6 changes: 6 additions & 0 deletions test/undefsafe.test.js
Expand Up @@ -8,6 +8,12 @@ test('should handle primatives', function (t) {
t.end();
});

test('should handle null', function (t) {
var r = undefsafe(null, 'foo');
t.equal(r, undefined, 'undefsafe works with null');
t.end();
});

test('should handle empty objects', function (t) {
var value = {};
var r;
Expand Down

0 comments on commit 9a1631a

Please sign in to comment.