existential-assign
Check for the existential value of a variable/object. Assign one if the value doesn't exist.
Very useful to setup a object with default values if the user preferences are empty. Works fine with deep objects:
var defaults = timeout: 3000 {} user: name: 'someone' url: 'github.com' var objt = user: name: 'Kiko Beats' url: 'github.com' // {// timeout: 3000,// cb: function() {},// user: {// name: 'Kiko Beats'// url: 'github.com'// }// }
Notes that is slightly different than Object.assign
.
Install
npm install existential-assign
If you want to use in the browser (powered by Browserify):
bower install existential-assign --save
and later link in your HTML:
Usage
First load the library:
var existsAssign = ;
Working with something that is not a Object
:
; // => 'hello world'; // => 'hello'
Working with Object
:
// => {hello: 'world'} // => {hello: 'world'}
You can provide more than one source:
// => {hello: 'world'}
It's equivalent to:
// => {hello: 'world'}
License
MIT © Kiko Beats