You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # object.reduce [![NPM version](https://img.shields.io/npm/v/object.reduce.svg?style=flat)](https://www.npmjs.com/package/object.reduce) [![NPM monthly downloads](https://img.shields.io/npm/dm/object.reduce.svg?style=flat)](https://npmjs.org/package/object.reduce) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/object.reduce.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/object.reduce)
  2. > Reduces an object to a value that is the accumulated result of running each property in the object through a callback.
  3. ## Install
  4. Install with [npm](https://www.npmjs.com/):
  5. ```sh
  6. $ npm install --save object.reduce
  7. ```
  8. Install with [yarn](https://yarnpkg.com):
  9. ```sh
  10. $ yarn add object.reduce
  11. ```
  12. Install with [bower](https://bower.io/)
  13. ```sh
  14. $ bower install object.reduce --save
  15. ```
  16. ## Usage
  17. the initial value (or value from the previous callback call), the `value` of the current property, the `key` of the current property, and the `object` over which the function is iterating. Node.js/JavaScript utility.)_
  18. **Params**
  19. * `object` **{Object}**: The object to iterate over (the iteratee)
  20. * `fn` **{Function}**: The function invoked per iteration.
  21. * `init` **{Object}**: The initial value to use for the accumulator.
  22. * `thisArg` **{Object}**: (optional) Object to use as the invocation context for the iterator (expose as `this` inside the iterator)
  23. Executes the given callback `fn` once for each own enumerable property in the object. The callback receives the following arguments:
  24. * `acc`: the initial value (or value from the previous callback call),
  25. * `value`: the of the current property,
  26. * `key`: the of the current property, and
  27. * the original `object` over which the function is iterating.
  28. **Example**
  29. ```js
  30. var reduce = require('object.reduce');
  31. var a = {a: 'foo', b: 'bar', c: 'baz'};
  32. reduce(a, function(acc, value, key, obj) {
  33. acc[key] = value.toUpperCase();
  34. return acc;
  35. }, {});
  36. //=> {a: 'FOO', b: 'BAR', c: 'BAZ'};
  37. ```
  38. ## About
  39. ### Contributing
  40. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
  41. ### Building docs
  42. _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
  43. To generate the readme, run the following command:
  44. ```sh
  45. $ npm install -g verbose/verb#dev verb-generate-readme && verb
  46. ```
  47. ### Running tests
  48. Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
  49. ```sh
  50. $ npm install && npm test
  51. ```
  52. ### Author
  53. **Jon Schlinkert**
  54. * [github/jonschlinkert](https://github.com/jonschlinkert)
  55. * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
  56. ### License
  57. Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
  58. Released under the [MIT License](LICENSE).
  59. ***
  60. _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 17, 2017._