Fancy extractor for js objects that is like destructuring but safer.
npm install --save @gdurastanti/js-extract
import extract from @gdurastanti/'js-extract'
OR
var extract = require('@gdurastanti/js-extract').default
const data = {
one: {
num: 1,
str: 'one',
foo: {
bar: 'baz',
},
},
two: {
num: 2,
str: 'two',
foo: {
bar: 'baz',
},
}
};
const selector = `
one: {
str
},
two: {
num,
foo
}
`
extract(selector).from(data);
Result:
{
one: {
str: 'one'
},
two: {
num: 2,
foo: {
bar: 'baz'
}
}
}