set-options
Merges default options to the user-given options.
Install
$ npm install set-options --save
set(options, defaults)
Always returns an object. For a key k
, if options
does not have k
as an own property, and defaults
does, defaults[k]
will copied to options
.
var set = require('set-options')
var defaults = {
a: 1
}
function factory (options) {
var config = set(options, defaults)
console.log(config, config === options, config === defaults)
}
factory()
factory(undefined)
factory(null)
factory(1)
factory({})
factory({b: 1})
factory({a: 0})
- options
Object=
can be undefined. - defaults
Object
not defining defaults
is silly, since that's the whole purpose of this lib.
Define whether should override properties
set(options, defaults, filter)
let options = set({a: undefined}, {a: 1}, function (value, key, object) {
return key in object
})
options
Deep merge? Nope
Do something below instead.
options = set(options, defaults)
options.config = set(options.config, default_config)
License
MIT