0.1.4 • Published 7 years ago
squba v0.1.4
squba
Safely access deeply nested properties.
Install
npm i -S squba
or
npm i -S squba
Use
import squba from 'squba'
// OR
const squba = require('squba')
const foo = {
bar: {
arr: ['a', 'b', 'c'],
objs: [ { name: 'Mike', address: { street: 'Lemontree st.' } } ]
}
}
squba(foo, ['bar', 'objs', 0, 'name']) // 'Mike'
squba(foo, 'bar.objs.0.name') // 'Mike'
squba(foo, ['bar', 'objs', 0, 'address', 'street']) // 'Lemontree st.'
squba(foo, 'bar.objs.0.address.street') // 'Lemontree st.'
squba(foo, ['bar', 'arr', 4]) // undefined
squba(foo, 'bar.arr.4') // undefined
squba(foo, ['bar', 'baz']) // undefined
squba(foo, 'bar.baz') // undefined
FAQ
- Why such small module? Sindre gives a good answer to this.