eoc
v0.1.0
Published
utility to create shallow extended objects, made for use with setting default options in functions
Downloads
16
Maintainers
Readme
eoc
An utility to create shallow extended objects, made for use with setting default options in functions.
How to include
Node.js / Browserify
In your shell:
$ npm install --save eocIn your javascript:
var eoc = require('eoc')Browser ("classic" way)
Just add a script tag with either eoc.js or eoc.min.js from this repos root directory.
This makes the eoc variable globally available.
typeof window.eoc
// --> 'function'API
eoc(<defaults>[, <override>[, <key>]])
Returns a shallow (depth 1) clone of defaults, extended with override.
If override is of any other than than 'object', the returned object will have a property _compat (or key if given) set to override' value.
var defaults = {
method: 'GET',
responseType: 'text'
}
console.log(eoc(defaults, {
method: 'POST',
url: 'http://some.domain.tld'
}))
// --> { method: 'POST', url: 'http://some.domain.tld', responseType: 'text' }
console.log(eoc(defaults, 'http://some.domain.tld'))
// --> { method: 'GET', responseType: 'text', _compat: 'http://some.domain.tld' }
console.log(eoc(defaults, 'http://some.domain.tld', 'url'))
// --> { method: 'GET', responseType: 'text', url: 'http://some.domain.tld' }Testing/Building
Installing development dependencies
$ npm installRunning tests
$ npm testBuilding for the browser
$ npm run build
$ # for building on file change
$ npm run watchLicense
MIT license, see LICENSE.
