mout
Version:
Modular Utilities
18 lines (15 loc) • 332 B
text/typescript
import forEach from '../array/forEach';
/**
* Create nested object if non-existent
*/
function namespace(obj, path) {
if (!path) return obj;
forEach(path.split('.'), function(key) {
if (!obj[key]) {
obj[key] = {};
}
obj = obj[key];
});
return obj;
}
export default namespace;