Skip to content

Commit

Permalink
Merge branch '1-npm-obj-unflatten' of https://github.com/418sec/obj-u…
Browse files Browse the repository at this point in the history
…nflatten into new-version
  • Loading branch information
IonicaBizau committed Dec 18, 2020
2 parents 46bd91c + 00606d7 commit 34b7f74
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/index.js
Expand Up @@ -4,6 +4,16 @@ const iterateObject = require("iterate-object")
, isUndefined = require("is-undefined")
;


/**
* Returns true, if given key is included in the blacklisted
* keys.
* @param key key for check, string.
*/
function isPrototypePolluted(key) {
return ['__proto__', 'prototype', 'constructor'].includes(key);
}

/**
* unflattenObject
* Convert flatten objects in nested ones.
Expand All @@ -28,6 +38,8 @@ module.exports = function unflattenObject(flatten, separator) {
;

iterateObject(subkeys, subkey => {
if (isPrototypePolluted(subkey)) return;

parentObj[subkey] = isUndefined(parentObj[subkey])
? {}
: parentObj[subkey]
Expand Down

0 comments on commit 34b7f74

Please sign in to comment.