Skip to content

Commit b504242

Browse files
amarinovmickhansen
authored andcommitted
Include null keys in paths response (#33)
1 parent 306dce7 commit b504242

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

dottie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
for (key in object) {
199199
value = object[key];
200200

201-
if (typeof value === 'object') {
201+
if (typeof value === 'object' && value !== null) {
202202
paths = paths.concat(Dottie.paths(value, prefixes.concat([key])));
203203
} else {
204204
paths.push(prefixes.concat(key).join('.'));

test/paths.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ describe("dottie.paths", function() {
2323

2424
expect(dottie.paths(object)).to.eql(["a", "b.c", "b.d.e"]);
2525
});
26+
27+
it("includes keys of null objects", function() {
28+
var object = {
29+
nonNullKey: 1,
30+
nullKey: null
31+
};
32+
33+
expect(dottie.paths(object)).to.eql(["nonNullKey", "nullKey"]);
34+
});
2635
});

0 commit comments

Comments
 (0)