Mustache
Apparence
Links
Doesn't handle dots in property name
// a solution could be to replace the dots in property names (it uses lodash)
function replaceDotWithUnderscore(obj) {
_.forOwn(obj, (value, key) => {
if (_.includes(key, '.')) {
const cleanKey = _.replace(key, /\./g, '_');
obj[cleanKey] = value;
delete obj[key];
}
// recursive call if the value is an object or an array
if (_.isObject(value)) {
return replaceDotWithUnderscore(value);
}
});
return obj;
}
|