Skip to content

callmecavs/dotnot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Access object properties using dot notation.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published