getter.js
v1.1.0
Published
The Promise based get object parameters for the modern browsers and node.
Downloads
3
Maintainers
Readme
Getter.js
The Promise based get object parameters for the modern browsers and node.
Installation
$ npm install --save getter.js
Before
var dataObj = {
test: 'testString',
test2: 'testString2',
getTest: () => {
const self = this;
return new Promise(resolve => resolve(self.test));
},
getTest2: () => {
const self = this;
return new Promise(resolve => resolve(self.test2));
}
}
dataObj
.getTest()
.then(response => console.log(response));
After
import getter from 'getter.js'
let dataObj = {
test: 'testString',
test2: 'testString2'
};
dataObj = getter(dataObj);
const asyncTestValue = await dataObj.getTest();
let config = {
async: false,
multiple: false
};
dataObj = getter(dataObj, config);
const testValue = dataObj.get('test');
API
getter({Object} Object, {Object} [Config])
Object - provided argument where you want to add get functions. Config - provided configuration object for additional options Config.async - default true - getter functions returns Promise Config.multiple - default true - if true you would add to object x getKey functions if false you would get only get('key') function