squba

0.1.4 • Public • Published

squba

XO code style

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

Package Sidebar

Install

npm i squba

Weekly Downloads

187

Version

0.1.4

License

MIT

Last publish

Collaborators

  • gillchristian