squba

safely access nested properties

  • squba

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
squba
400.1.47 years ago8 years agoMinified + gzip package size for squba in KB

Readme

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