safechainjs
v1.0.2
Published
safechainjs will allow javascript or typescript to chain data safely.
Downloads
2
Readme
safechainjs
A simple, light and safe way to access object's property in any level. It also assign back the fallback value if there is no given properties.
- First parameter is object to look into.
- Multiple parameters as string as property of object.
- Last parameter is fallback value to be returned, if request value is not present.
Installation
npm install safechainjs --save
Usage
Javascript
const safechain = require('safechainjs');
const obj = {
name: {
firstName: "Albert",
lastName: "Einstein"
},
dob: "1897/03/14",
wife: ['Maric', 'Elsa']
};
const propertyWife = 'wife';
const fname = safechain(obj, 'name', 'firstName', 'Unknown'); // Albert
const address = safechain(obj, 'address', 'postcode', 0); // 0
const wives = safechain(obj, propertyWife, []); // ['Maric', 'Elsa']
Test
npm run test