{"name":"object-loops","version":"0.4.0","description":"Functional methods like forEach, map, filter, and other ES5 Array methods for Objects in javascript","main":"index.js","directories":{"test":"test"},"scripts":{"test":"lab -t 100 -a code","test-watch":"nodemon --exec npm test","lint":"standard","format":"standard --format"},"repository":{"type":"git","url":"https://github.com/tjmehta/object-loops.git"},"keywords":["object","functional","methods","forEach","map","map keys","keys","mapKeys","reduce","filter","some","every","extended","function"],"author":{"name":"Tejesh Mehta"},"license":"MIT","bugs":{"url":"https://github.com/tjmehta/object-loops/issues"},"homepage":"https://github.com/tjmehta/object-loops","dependencies":{"101":"^1.2.0","dasherize":"^2.0.0"},"devDependencies":{"code":"^1.5.0","lab":"^6.2.0","nodemon":"^1.8.1","sinon":"^1.17.2","standard":"^5.4.1"},"gitHead":"d15e39edbfabeaadfc8c8f8130945de5db4c1ecf","_id":"object-loops@0.4.0","_shasum":"a37d44b72969baa909063c96468fdd8c2597506d","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"tjmehta","email":"tj_mehta@hotmail.com"},"maintainers":[{"name":"tjmehta","email":"tj_mehta@hotmail.com"}],"dist":{"shasum":"a37d44b72969baa909063c96468fdd8c2597506d","tarball":"http://registry-npm.ywwl.com/object-loops/download/object-loops-0.4.0.tgz","integrity":"sha512-lcjrItFLP1ZXdmCghFZg9WRy+NDKa8EGA2FC9ac/XcNb2nBhHRGYn+32YU9NGTk7dc8z0V4IoCuD5WLBJVbQzw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDtzBxp6cUm9AN+4S/c5Xs2BIhmLbhlx21qtOE4rgrNnAIhAPPMvPkC1AuCEbr6BoFuCyrckG++oEXEqO9LR00uc9CY"}],"size":7707,"noattachment":false,"key":"/object-loops/-/object-loops-0.4.0.tgz"},"readme":"object-loops [![Build Status](https://travis-ci.org/tjmehta/object-loops.svg)](https://travis-ci.org/tjmehta/object-loops)\n============\n\nFunctional methods like forEach, map, filter, and other Array methods for Objects in javascript\n\n# Installation\n\n`npm install object-loops`\n\n# Index\n\n[chain](https://github.com/tjmehta/object-loops#usage)\n\n[every](https://github.com/tjmehta/object-loops#every)\n\n[inverse](https://github.com/tjmehta/object-loops#inverse)\n\n[filter](https://github.com/tjmehta/object-loops#filter)\n\n[findKey](https://github.com/tjmehta/object-loops#findKey)\n\n[find](https://github.com/tjmehta/object-loops#find)\n\n[forEach](https://github.com/tjmehta/object-loops#forEach)\n\n[keys](https://github.com/tjmehta/object-loops#keys)\n\n[keysIn](https://github.com/tjmehta/object-loops#keysIn)\n\n[mapKeys](https://github.com/tjmehta/object-loops#mapKeys)\n\n[map](https://github.com/tjmehta/object-loops#map)\n\n[reduce](https://github.com/tjmehta/object-loops#reduce)\n\n[some](https://github.com/tjmehta/object-loops#some)\n\n[values](https://github.com/tjmehta/object-loops#values)\n\n[valuesIn](https://github.com/tjmehta/object-loops#valuesIn)\n\n# Usage\n\n#### You can require each method individually `object-loops/<loop>`\n\n```js\nvar filter = require('object-loops/filter')\nvar forEach = require('object-loops/for-each')\nvar mapKeys = require('object-loops/map-keys')\nvar map = require('object-loops/map')\nvar reduce = require('object-loops/reduce')\n//... and more\n// usage\nforEach({ x:10, y: 20 }, callback)\nfilter({ x:10, y: 20 }, callback)\nmapKeys({ x:10, y: 20 }, callback)\nmap({ x:10, y: 20 }, callback)\nreduce({ x:10, y: 20 }, callback)\n```\n\n#### If you want to chain multiple object-loops use `object-loops/chain`\n\n```js\nvar chain = require('object-loops/chain')\nchain({ x:10, y: 20 })\n  .filter(callback)\n  .mapKeys(callback)\n  .map(callback)\n  .reduce(callback)\n  .toJSON() // must be called at the end to return modified object\n\n```\n\n#### If you want to use forEach, map, reduce, filter, etc methods directly on objects:\n\n```js\nrequire('object-loops')() // extends Object.prototype\nobj.forEach(callback)\nobj.filter(callback)\nobj.mapKeys(callback)\nobj.map(callback)\nobj.reduce(callback)\n```\n\n## every\n\nTests whether every value in the object passes the test implemented by the callback.\n\n * @function module:object-loops/every\n * @param {object} [obj] - object to iterate through, not accepted if being used directly on Object.prototype\n * @param {everyCallback} callback - function to test each value in the object. return falsey to end the loop, truthy otherwise.\n * @param {*} [thisArg] - optional. context to bind to callback\n * @returns {boolean} if callback returns false, the loop is ended and false is returned (else false)\n\n```js\nvar every = require('object-loops/every')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30,\n  qux: 40,\n}\nvar allGreaterThan25 = every(obj, function (val, key, obj) {\n  return val > 25\n})\nallGreaterThan25 // false\n*/\n```\n\n## inverse\n\nCreates a new object with keys and values flipped.\n\n* @param {object} [obj] - object to inverse keys and values, not accepted if being used directly on Object.prototype\n* @returns {object} newly created object with inversed values\n\n```js\nvar inverse = require('object-loops/inverse')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30\n}\nvar inversedObj = inverse(obj)\ninversedObj /* keys and vals are flipped\n{\n  '10': 'foo',\n  '20': 'bar',\n  '30': 'baz'\n}\n*/\n```\n\n## filter\n\nCreates a new object with all entries that pass the test implemented by the provided function.\n\n * @param {object} [obj] - object to filter values, not accepted if being used directly on Object.prototype\n * @param {function} callback - function to test each value in the object. return true to keep that entry, false otherwise.\n * @param {*} [thisArg] - optional. context to bind to callback\n * @returns {object} newly created object with filtered values\n\n```js\nvar filter = require('object-loops/filter')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30,\n  qux: 40,\n}\nvar filteredObj = filter(obj, function (val, key, obj) {\n  return val > 25\n})\nfilteredObj /* Only has entries with vals greater than 25\n{\n  baz: 30,\n  qux: 40\n}\n*/\n```\n\n## find\n\nFind the value of the the object that passes the test implemented by the callback.\n\n* @param {object} [obj] - object to iterate through, not accepted if being used directly on Object.prototype\n* @param {findCallback} callback - function to test each value in the object. return truthy to end the loop and return index, falsey otherwise.\n* @param {*} [thisArg] - optional. context to bind to callback\n* @returns {*} if callback returns true, the loop is ended and the passing `val` is returned (else undefined)\n\n```js\nvar find = require('object-loops/find')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30,\n  qux: 40,\n}\nvar key = find(obj, function (val, key, obj) {\n  return val > 25\n})\nkey // 30\nvar notfound = find(obj, function (val, key, obj) {\n  return val > 100\n})\nnotfound // undefined\n*/\n```\n\n## findKey\n\nFind the key of the the object that passes the test implemented by the callback. Very similar to `Array.prototype.findIndex`\n\n* @param {object} [obj] - object to iterate through, not accepted if being used directly on Object.prototype\n* @param {findKeyCallback} callback - function to test each value in the object. return truthy to end the loop and return index, falsey otherwise.\n* @param {*} [thisArg] - optional. context to bind to callback\n* @returns {*} if callback returns true, the loop is ended and the passing `key` is returned (else undefined)\n\n```js\nvar findKey = require('object-loops/find-key')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30,\n  qux: 40,\n}\nvar key = findKey(obj, function (val, key, obj) {\n  return val > 25\n})\nkey // 'baz'\nvar notfound = findKey(obj, function (val, key, obj) {\n  return val > 100\n})\nnotfound // undefined\n*/\n```\n\n## forEach\n\nExecutes a provided function once per each object value.\n\n * @param {object} [obj] - object to forEach, not accepted if being used directly on Object.prototype\n * @param {function} callback - function that will be invoked once for each key-value pair\n * @param {*} [thisArg] - optional. context to bind to callback\n\n```js\nvar forEach = require('object-loops/for-each')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30\n}\nvar keyConcat = ''\nvar valSum = 0\nforEach(obj, function (val, key, obj) {\n  keyConcat += key\n  valSum += val\n})\nkeyConcat // = 'foobarbaz'\nvalSum    // = 60\n```\n\n## keys\n\nEquivalent to `Object.keys`. Implemented specifically for chain.\n\n```js\nvar chain = require('object-loops/chain')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30\n}\nchain(obj)\n  .keys()\n  .toJSON()\n// ['foo', 'bar', 'baz']\n```\n\n## keysIn\n\nLike to `keys`, but includes enumerable keys from the prototype chain.\n\n```js\nvar keysIn = require('object-loops/keys-in')\n\nfunction Person (name) {\n  this.name = name\n}\nPerson.prototype.getName = function () {\n  return this.name\n}\n\nvar person = new Person('foo')\nkeysIn(obj)\n// ['name', 'getName']\n// for comparison, `keys` would return ['name']\n```\n\n## mapKeys\n\nCreates a new object with the results of calling a provided function on every key in the object.\n\n * @param {object} [obj] - object to map keys, not accepted if being used directly on Object.prototype\n * @param {mapKeysCallback} callback - function that produces the new key for the new mapped object\n * @param {*} [thisArg] - optional. context to bind to callback\n * @returns {object} newly created object with mapped keys\n\n```js\nvar mapKeys = require('object-loops/map-keys')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30\n}\nvar mappedObj = mapKeys(obj, function (key, val, obj) {\n  return key + 'New'\n})\nmappedObj /* Each key is concated w/ 'New'\n{\n  fooNew: 10,\n  barNew: 20,\n  bazNew: 30\n}\n*/\n```\n\n## map\n\nCreates a new object with the results of calling a provided function on every value in the object.\n\n * @param {object} [obj] - object to map values, not accepted if being used directly on Object.prototype\n * @param {function} callback - function that produces the new value for the new, mapped object\n * @param {*} [thisArg] - optional. context to bind to callback\n * @returns {object} newly created object with mapped values\n\n```js\nvar map = require('object-loops/map')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30\n}\nvar mappedObj = map(obj, function (val, key, obj) {\n  return val*2\n})\nmappedObj /* Each val multiplied by 2\n{\n  foo: 20,\n  bar: 40,\n  baz: 60\n}\n*/\n```\n\n## reduce\n\nApplies a function against an accumulator and each value of the object to reduce it to a single value.\n\n * @param {object} [obj] - object to reduce values, not accepted if being used directly on Object.prototype\n * @param {function} callback - function to test each value in the object. return true to keep that entry, false otherwise.\n * @param {*} [initialValue] - optional. object to use as the first argument to the first call of the callback\n * @returns {*} finalValue - final value returned by reduction, or just first val if only one exists.\n\n```js\nvar reduce = require('object-loops/reduce')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30\n}\nvar sum = reduce(obj, function (prevVal, val, key, obj) {\n  return prevVal + val\n})\nsum // 60\n```\n\n## some\n\nTests whether some value in the object passes the test implemented by the callback.\n\n * @function module:object-loops/some\n * @param {object} [obj] - object to iterate through, not accepted if being used directly on Object.prototype\n * @param {someCallback} callback - function to test each value in the object. return truthy to end the loop, falsey otherwise.\n * @param {*} [thisArg] - optional. context to bind to callback\n * @returns {boolean} if callback returns true, the loop is ended and true is returned (else false)\n\n```js\nvar some = require('object-loops/some')\n\nvar obj = {\n  foo: 10,\n  bar: 20,\n  baz: 30,\n  qux: 40,\n}\nvar anyGreaterThan25 = some(obj, function (val, key, obj) {\n  return val > 25\n})\nanyGreaterThan25 // true\n*/\n```\n\n## values\n\nLike to `keys`, but returns direct enumerable values.\n\n```js\nvar values = require('object-loops/values')\n\nfunction Person (name) {\n  this.name = name\n}\nPerson.prototype.getName = function () {\n  return this.name\n}\n\nvar person = new Person('foo')\nvalues(obj)\n// ['foo']\n// for comparison, `valuesIn` would return ['foo', Person.prototype.getName]\n```\n\n## valuesIn\n\nLike to `keys`, but returns direct enumerable values including prototype chain.\n\n```js\nvar valuesIn = require('object-loops/values-in')\n\nfunction Person (name) {\n  this.name = name\n}\nPerson.prototype.getName = function () {\n  return this.name\n}\n\nvar person = new Person('foo')\nvaluesIn(obj)\n// ['foo', Person.prototype.getName]\n```\n\n## License\n\nMIT\n","publish_time":1449129200672,"_cnpm_publish_time":1449129200672,"dist-tags":{"latest":"0.8.0"}}