Page MenuHomeSealhub

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

Authored By
Unknown
Size
532 B
Referenced Files
None
Subscribers
None

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
application/javascript
Expires
Fri, Nov 27, 16:18 (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1223160
Default Alt Text
flatten-object-to-dot-notation.js (532 B)

Event Timeline