JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2545
  • Score
    100M100P100Q97203F
  • License ISC

Easily use dot notation to `get`, or `set` a property of a nested object.

Package Exports

  • object-dot

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (object-dot) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

📦 object-dot

CircleCI codecov npm

Easily use dot notation to get, or set a property of a nested object. A Node.js library.

Usage

set

Create the nested chain of objects with set and dot notation with one simple statement.

const objectd = require('object-dot')

console.log(
  objectd.set({ object: {}, path: 'a.b.c', value: 'foo' })
)
// => { a: { b: { c: 'foo' } } }

// Array of the property chain will work too!
console.log(
  objectd.set({ object: {}, path: ['a', 'b', 'c'], value: 'foo' })
)

// Alternatively you may use arguments as parameters instead of an object.
console.log(
  objectd.set({}, 'a.b.c', 'foo')
)

get

Get the value of a nested chain of objects without checking each object in the chain for its existence.

const objectd = require('object-dot')

// when one of the properties in the chain is undefined. Safely return undefined.
let object = { foo: { bar: 'you!' }}
console.log(
  objectd.get({ object, path: 'foo.bar.c.d'})
)
//=> undefined

// return a default value if property is undefined
object = { foo: { bar: 'you!' }}
console.log(
  objectd.get({ object, path: 'foo.bar.c.d', value: 'my default value'})
)
//=> 'my default value'

// When the property exist.
object = { a: { foo: { bar: 'you!' } }}
console.log(
  objectd.get({ object, path: 'a.foo'})
)
//=> { bar: 'you!' }

Install

$ npm install object-dot --save

License

ISC