Make My Life Easier when manipulate with namespace
npm install mmle-namespace --save-dev
└── dist
└── mmle-namespace.js
Setter.
var cats = {};
var name = namespace(cats, 'yellow.small.happy', 'paul');
console.log(cats); // { 'yellow': { 'small': { 'happy': 'paul' } } }
console.log(name); // 'paul'
// when the namespace is already existed
var name = namespace(cats, 'yellow.small.happy', 'thammin');
// throw error
// overwrite the existing namespace
var name = namespace(cats, 'yellow.small.happy', 'thammin', true);
console.log(cats); // { 'yellow': { 'small': { 'happy': 'thammin' } } }
console.log(name); // 'thammin'
Getter.
var cats = {
yellow: {
small: {
happy: 'thammin'
}
}
};
var name = namespace(cats, 'yellow.small.happy');
console.log(name); // 'thammin'