blood

object inheritance and iteration utilities

npm install blood
41 downloads in the last month

blood

cross-compatible JavaScript object utility module with methods for inheritance and basic tasks like iteration

$ npm install blood

API (0.7)

  • Interoperables: Methods are generally compatible with those in underscore and lodash. Interchange libs based on needs.
  • Parameters labelled with ? are optional.
  • Read annotations and comments in the source.

Creation

  • blood.create(parent) uses Object.create if available
  • blood.twin(source, parent?) clone inheritance
  • blood.keys(object) uses Object.keys if available
  • blood.names(object) uses Object.getOwnPropertyNames if available
  • blood.values(object) get array of own enumerable values
  • blood.methods(object) get array of own enumerable functions
  • blood.pluck(object, key) get array of plucked values
  • blood.object(keys, values) get new object made from keys and values
  • blood.pick(object, *keys) get new object with keys
  • blood.omit(object, *keys) get new object without keys
  • blood.has(object, key) test if object owns key

Extension

  • blood.assign(receiver, supplier) emulates ES6 Object.assign
  • blood.assign(supplier) this receives
  • blood.adopt(supplier) this receives
  • blood.adopt(receiver, supplier, list) assign listed keys

Iteration

accum callbacks receive (result, value, key, object)

  • blood.reduce(object, accum, init?, scope?) uses array-like iteration
  • blood.inject(object, accum, init?, scope?) iterates own properties

fn callbacks receive (value, key, object)

  • blood.every(object, fn, scope?) uses array-like iteration
  • blood.some(object, fn, scope?) uses array-like iteration
  • blood.map(object, fn, scope?) uses array-like iteration
  • blood.all(object, fn, scope?) iterates own properties
  • blood.any(object, fn, scope?) iterates own properties
  • blood.collect(object, fn, scope?) iterates own properties

Developers

Contribute by making edits in /src or reporting issues.

$ npm install
$ grunt jshint:sub
$ grunt aok

Fund

Fund development with tips to @ryanve =)

License

MIT

npm loves you