@lyngs/digger
provides a function for user to dig value out of a target.
Use digger()
method to get
orset
value, from deep inside of an object
orarray
.
npm install @lyngs/digger
// import @lyngs/digger
import digger from '@lyngs/digger';
const target = {
people: [
{ name: 'shook' }
],
};
console.log(digger(target, 'people[0].name')); // 'shook'
digger(target, 'people[0].name', 'oral'); // 'oral'
// people[1] does'nt exists
digger(target, 'people[1].name', 'who'); // undefined
// layer extended when function context can't find certain property
digger(target, 'people[1].name', 'who', { extend: true }); // 'who'
// people[0].name has been updated to anomymous function
digger(target, 'people[0].name', () => 'oral'); // [Function (anonymous)]
// param 'update' has been untied to get the result of function
digger(target, 'people[0].name', () => 'oral', { untie: true }); // 'oral'
npm run build
npm run test