{"_id":"objectfn","_rev":"2169339","name":"objectfn","description":"map, reduce, and filter for objects, lazy evaluation and no dependencies","dist-tags":{"latest":"2.0.0"},"maintainers":[{"name":"declandewet","email":"declandewet@me.com"},{"name":"jescalan","email":"hello@jenius.me"}],"time":{"modified":"2022-01-05T02:57:48.000Z","created":"2016-06-14T17:48:16.241Z","2.0.0":"2016-06-20T13:44:37.078Z","1.0.0":"2016-06-14T17:48:16.241Z"},"users":{},"author":{"name":"jescalan"},"repository":{"type":"git","url":"git+https://github.com/jescalan/objectfn.git"},"versions":{"2.0.0":{"name":"objectfn","description":"map, reduce, and filter for objects, lazy evaluation and no dependencies","version":"2.0.0","author":{"name":"jescalan"},"ava":{"verbose":"true"},"bugs":{"url":"https://github.com/jescalan/objectfn/issues"},"contributors":[{"name":"Declan DeWet"}],"devDependencies":{"ava":"0.15.x","coveralls":"2.x","nyc":"6.x","standard":"7.x"},"engines":{"node":">= 6.0.0"},"homepage":"https://github.com/jescalan/objectfn","keywords":["filter","functional","map","object","reduce","utility"],"license":"MIT","main":"index.js","repository":{"type":"git","url":"git+https://github.com/jescalan/objectfn.git"},"scripts":{"coverage":"nyc ava","coveralls":"nyc --reporter=lcov ava && cat ./coverage/lcov.info | coveralls","lint":"standard","test":"ava"},"gitHead":"37ba245c15dd5613ae6fbfc5d32d26384545ae5c","_id":"objectfn@2.0.0","_shasum":"3fbc9d2c43690bf2b418ba5e3486e3cbb5b99e95","_from":".","_npmVersion":"3.8.9","_nodeVersion":"6.2.0","_npmUser":{"name":"jenius","email":"jeff@carrotcreative.com"},"dist":{"shasum":"3fbc9d2c43690bf2b418ba5e3486e3cbb5b99e95","size":3856,"noattachment":false,"key":"/objectfn/-/objectfn-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/objectfn/download/objectfn-2.0.0.tgz"},"maintainers":[{"name":"declandewet","email":"declandewet@me.com"},{"name":"jescalan","email":"hello@jenius.me"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/objectfn-2.0.0.tgz_1466430274474_0.797068533487618"},"directories":{},"publish_time":1466430277078,"_cnpm_publish_time":1466430277078,"_hasShrinkwrap":false},"1.0.0":{"name":"objectfn","description":"map, reduce, and filter for objects, lazy evaluation and no dependencies","version":"1.0.0","author":{"name":"jescalan"},"ava":{"verbose":"true"},"bugs":{"url":"https://github.com/jescalan/objectfn/issues"},"contributors":[{"name":"Declan DeWet"}],"devDependencies":{"ava":"0.15.x","coveralls":"2.x","nyc":"6.x","standard":"7.x"},"engines":{"node":">= 6.0.0"},"homepage":"https://github.com/jescalan/objectfn","keywords":["filter","functional","map","object","reduce","utility"],"license":"MIT","main":"index.js","repository":{"type":"git","url":"git+https://github.com/jescalan/objectfn.git"},"scripts":{"coverage":"nyc ava","coveralls":"nyc --reporter=lcov ava && cat ./coverage/lcov.info | coveralls","lint":"standard","test":"ava"},"gitHead":"667d85b2f5958097f70b175cf6fca47e6aec32f5","_id":"objectfn@1.0.0","_shasum":"0a70d17c264dfcd2001b3b071693373860b1821a","_from":".","_npmVersion":"3.8.9","_nodeVersion":"6.2.0","_npmUser":{"name":"jenius","email":"jeff@carrotcreative.com"},"dist":{"shasum":"0a70d17c264dfcd2001b3b071693373860b1821a","size":2236,"noattachment":false,"key":"/objectfn/-/objectfn-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/objectfn/download/objectfn-1.0.0.tgz"},"maintainers":[{"name":"declandewet","email":"declandewet@me.com"},{"name":"jescalan","email":"hello@jenius.me"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/objectfn-1.0.0.tgz_1465926493782_0.12136342818848789"},"directories":{},"publish_time":1465926496241,"_cnpm_publish_time":1465926496241,"_hasShrinkwrap":false}},"readme":"# ObjectFn\n\n[![npm](http://img.shields.io/npm/v/objectfn.svg?style=flat)](https://badge.fury.io/js/objectfn) [![tests](http://img.shields.io/travis/jescalan/objectfn/master.svg?style=flat)](https://travis-ci.org/jescalan/objectfn) [![dependencies](http://img.shields.io/david/jescalan/objectfn.svg?style=flat)](https://david-dm.org/jescalan/objectfn) [![coverage](http://img.shields.io/coveralls/jescalan/objectfn.svg?style=flat)](https://coveralls.io/github/jescalan/objectfn)\n\n`map`, `reduce`, `forEach`, and `filter` for plain objects. Lazy evaluation, supports functional and imperative syntax, no dependencies.\n\n### Why should you care?\n\nI wanted a library that has no dependencies and gives me the basic map/reduce/filter for use on objects. Any existing library I found has boatloads of dependencies, provides tons more extra tools, and/or is unmaintained. So here's `ObjectFn`, just for you!\n\nAlso, big props to [@declandewet](https://github.com/declandewet) for the initial implementation of this library!\n\n### Requirements\n\n- [Node.js v.6+](http://nodejs.org)\n\n### Installation\n\nUsing a terminal:\n\n```sh\n$ npm install objectfn -S\n```\n\n### Usage\n\nUsage is straightforward. Just import what you need and use it on an object.\n\n#### Imperative style\n\nTakes data first, callback last.\n\n```js\nconst {map, reduce, filter, forEach} = require('objectfn')\n\nconst obj = { foo: 'bar', wow: 'doge' }\n\nmap(obj, (val) => val.toUpperCase())\n// { foo: 'BAR', wow: 'DOGE' }\n\nreduce(obj, (acc, val, key) => (acc[key.toUpperCase()] = val, acc), {})\n// { FOO: 'bar', WOW: 'doge' }\n\nfilter(obj, (val, key) => key !== 'foo')\n// { wow: 'doge' }\n\nforEach(obj, console.log.bind(console))\n// bar foo 0 { foo: 'bar', wow: 'doge' }\n// doge wow 1 { foo: 'bar', wow: 'doge' }\n```\n\n#### Functional style\n\nTakes callback first, data last. Each method is automatically curried.\n\n```js\nconst {map, reduce, filter, forEach} = require('objectfn')\n\nconst obj = { foo: 'bar', wow: 'doge' }\n\nconst upcaseValues = map((val) => val.toUpperCase())\nupcaseValues(obj)\n// { foo: 'BAR', wow: 'DOGE' }\n\nconst upcaseKeys = reduce((acc, val, key) => (acc[key.toUpperCase()] = key, acc), {})\nupcaseKeys(obj)\n// { FOO: 'bar', WOW: 'doge' }\n\nconst ignoreFoo = filter((val, key) => key !== 'foo')\nignoreFoo(obj)\n// { wow: 'doge' }\n\nconst logValues = forEach(console.log.bind(console))\nlogValues(obj)\n// bar foo 0 { foo: 'bar', wow: 'doge' }\n// doge wow 1 { foo: 'bar', wow: 'doge' }\n```\n\n### Method Signature\n\n- Each callback has a method signature of `(value, key, index, object)` with the exception of `reduce`.\n  - `value` is the current key's value\n  - `key` is the current key's name\n  - `index` is the 0-based index of the current key\n  - `object` is the original object.\n- `reduce` has a method signature of `(accumulator, value, key, index, object)`.\n  - `accumulator` is any initial value onto which you want to iteratively reduce from `object`.\n\n### Differences in `reduce`\n\nIn `objectfn`, the act of passing an accumulator to the `reduce` method is _required_, which is better for readability/accessibility (developer intentions are made more obvious), has no immediate disadvantages and is one of the two reasons `objectfn` is able to support both functional and imperative syntaxes.\n\nThis means that this will work:\n\n```js\nlet obj = { one: 1, two: 2, three: 3, four: 4 }\nreduce(obj, (acc, val) => acc + val, 0) // => 10\n```\n\nBut this will not:\n\n```js\nlet obj = { one: 1, two: 2, three: 3, four: 4 }\nreduce(obj, (prevVal, currVal) => prevVal + currVal) // => wat?\n```\n\n### Binding `this`\n\n`objectfn` offers no mechanism for binding the `this` context of the callback via the last parameter. This is one of two reasons why `objectfn` is able to support both functional and imperative syntaxes. If you want this behavior, it is still possible (and far more readable) to do so using `Function.prototype.bind`:\n\n```js\nmap(obj, fn.bind(/* value to use as `this` goes here */))\n```\n\n### License & Contributing\n\n- Details on the license [can be found here](LICENSE.md)\n- Details on running tests and contributing [can be found here](contributing.md)\n","_attachments":{},"homepage":"https://github.com/jescalan/objectfn","bugs":{"url":"https://github.com/jescalan/objectfn/issues"},"license":"MIT"}