Skip to content
/ mb Public
forked from burakcan/mb

Exception-free nested nullable attribute accessor

License

Notifications You must be signed in to change notification settings

aborjinik/mb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mb

goat

Exception-free nested nullable attribute accessor. An alternative to facebookincubator/idx in 57 bytes.


Install

Just copy/paste this function into your project:

var mb=(f,...p)=>(o,i=o[f])=>i&&p[0]!=null?mb(...p)(i):i

Alternatively, you can download mb.js.

Use

var getHello = mb('a', 'b', 0, 'hello');

var obj1 = {
  a: {
    b: [{ hello: 'world' }]
  }
};

var obj2 = {
  c: {
    d: 'e'
  }
};

getHello(obj1); // world
getHello(obj2); // undefined

Contribution and Code-Golfing

  1. Clone and shorten current code.
  2. Please open test.html in your browser and open console to see if all the tests pass.

Contributors

About

Exception-free nested nullable attribute accessor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 91.0%
  • HTML 9.0%