0.1.0 • Published 10 years ago

eoc v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
10 years ago

eoc

npm version Travis CI Badge (master branch)

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 eoc

In 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 install

Running tests

$ npm test

Building for the browser

$ npm run build
$ # for building on file change
$ npm run watch

License

MIT license, see LICENSE.