dotnot

Access object properties using dot notation.

Usage no npm install needed!

<script type="module">
  import dotnot from 'https://cdn.skypack.dev/dotnot';
</script>

README

dotnot

dotnot on Travis dotnot on NPM dotnot Downloads on NPM Standard JavaScript Style

Access object properties using dot notation.

Install

$ npm install dotnot --save

Use

import {
  get,
  set
} from 'dotnot'

const data = {
  a: {
    b: {
      c: {
        d: 1
      }
    }
  },
  e: 1
}

// get (object, path) -> value
get(data, 'a.b')             // returns { c: { d: 1 } }
get(data, 'a.b.c')           // returns { d: 1 }
get(data, 'a.b.c.d')         // returns 1
get(data, 'a.c')             // returns undefined
get(data, 'a.b.d')           // returns undefined
get(data, 'a.b.c.e')         // returns undefined

// set (object, path, value) -> value
set(data, 'a.c', 1)             // returns 1
set(data, 'a.b.d', 1)           // returns 1
set(data, 'a.b.c.e', 1)         // returns 1

License

MIT. © 2018 Michael Cavalea