1 | var forEach = require('../array/forEach');
|
2 |
|
3 | /**
|
4 | * Create nested object if non-existent
|
5 | */
|
6 | function namespace(obj, path){
|
7 | if (!path) return obj;
|
8 | forEach(path.split('.'), function(key){
|
9 | if (!obj[key]) {
|
10 | obj[key] = {};
|
11 | }
|
12 | obj = obj[key];
|
13 | });
|
14 | return obj;
|
15 | }
|
16 |
|
17 | module.exports = namespace;
|
18 |
|
19 |
|