saffy
Safest way to get and set properties in Javascript
Installation
$ npm i saffy
or
$ bower i saffy
Usage
Having the following object
var obj = user: id: 1234 city: 'Springfield' info: name: firstName: 'Homer' ;
You want to set obj.user.info.name.lastName = "Simpson"
. Easy right? But wait... this is Javascript, so, maybe you end having something like this :\
if obj && objuser && objuserinfo && objuserinfoname objuserinfonamelastName = 'Simpson';
Ok, now let's see how looks using Saffy
; ;
And same thing with get
; ;
Others goodies
Playing with Arrays
; let obj = cars: 'mercedes' 'bmw' 'audi' food: 'paella' 'bravas' 'pizza' 'spaghetti' === 'mercedes'; === 'audi'; === 'bmw'; === 'spaghetti'; === 'bravas'; === 2;
Playing with Functions
; let obj = foo: 'bar' { return thisfoo; } { return a: thisfoo ; } === 'bar'; === 'bar';
Motivation
Inspired by @sindresorhus words...
You make small focused modules for reusability and to make it possible to build larger more advanced things that are easier to reason about
Full Post https://github.com/sindresorhus/ama/issues/10#issuecomment-117766328