get-or-else
Simple Get Or Else module written in JavaScript ES5.
Request an object property at a given namespace with a backup value, incase the desired namespace does not yield a result.
Useful if you have an untrustworthy or deeply nested data source. It will probably save you a bit of if, else-ery.
Example ES5
var get = ; windowa = x: 4 ; ;// returns {} as window.a.b.c does not exist, so `else` is used ;// returns { x: 4 } as window.a does exist, so expected value is returned
Example ES6 Redux
; const name = { };
Example ES6 React
see this repo get-or-else-demo
;;; const nameObj = details: salutation: undefined name: first: 'Margaret' ; const NameComponent = <h1> Welcome <span> </span> <span> </span> </h1>; ReactDOM; /* NameComponent Renders `<h1> Welcome back<span> Margaret</span><span></span></h1>` nameObj.details.salutation does not exist so the backup value is usednameObj.details.name.last does not exist so it does not display*/
NPM Package
Browser compatibility
IE 9 or greater - Array.every on Mozilla's compatibility chart
Run the tests
Given you have Node installed, cd
into this folder and:
npm install
npm test