Skip to content
Open
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
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ function unflatten (target, opts) {
type === '[object Object]' ||
type === '[object Array]'
)


// if is a prototype key assign undefined value
if (typeof recipient[key1] === 'function') {
recipient[key1] = undefined;
}

// do not write over falsey, non-undefined values if overwrite is false
if (!overwrite && !isobject && typeof recipient[key1] !== 'undefined') {
return
Expand Down
26 changes: 26 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,32 @@ suite('Order of Keys', function () {
})
})

suite('Object Prototype Keys', function () {
test('Should be able to unflatten object prototype keys (constructor, toString, valueOf, etc.)', function () {
assert.deepStrictEqual({
a: {
constructor: {
constructor: 'hello'
}
},
b: {
toString: {
toString: 'hello'
}
},
c: {
valueOf: {
valueOf: 'hello'
}
}
}, unflatten({
'a.constructor.constructor': 'hello',
'b.toString.toString': 'hello',
'c.valueOf.valueOf': 'hello',
}))
})
})

suite('CLI', function () {
test('can take filename', function (done) {
const cli = path.resolve(__dirname, '..', pkg.bin)
Expand Down