Page MenuHomeSealhub

flatten-object-to-dot-notation.js
No OneTemporary

flatten-object-to-dot-notation.js

module.exports = function(context, obj) {
const prefix = typeof context === "string" ? context + "." : "";
return flattenObjectToDotNotation(prefix, obj);
};
function flattenObjectToDotNotation(prefix, obj) {
return Object.keys(obj).reduce((flattened, prop) => {
const new_prop = prefix + prop;
if (obj[prop] && typeof obj[prop] === "object") {
Object.assign(
flattened,
flattenObjectToDotNotation(new_prop + ".", obj[prop])
);
} else {
flattened[new_prop] = obj[prop];
}
return flattened;
}, {});
}

File Metadata

Mime Type
text/plain
Expires
Wed, Aug 13, 17:19 (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
872833
Default Alt Text
flatten-object-to-dot-notation.js (532 B)

Event Timeline