JSPM

reduce-object

0.1.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 58744
  • Score
    100M100P100Q143399F

Reduces an object to a value that is the accumulated result of running each property in the object through a callback. Executes the callback function once for each own enumerable property in the object, receiving four arguments: 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.

Package Exports

  • reduce-object

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (reduce-object) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

reduce-object NPM version

Reduces an object to a value that is the accumulated result of running each property in the object through a callback.

Install

Install with npm:

npm i reduce-object --save

Run tests

npm test

Usage

Executes the callback function once for each own enumerable property in the object, receiving four arguments:

  • acc: the initial value (or value from the previous callback call),
  • value: the of the current property,
  • key: the of the current property, and
  • the original object over which the function is iterating.
var reduce = require('reduce-object');

var a = {a: 'foo', b: 'bar', c: {}};

var obj = reduce(a, function (acc, value, key, orig) {
  if (typeof value === 'object') {
    acc[key] = {what: 'huh?'};
  } else {
    acc[key] = value.toUpperCase(); // why?
  }
  return acc;
}, {});

console.log(obj);
//=> {a: 'FOO', b: 'BAR', c: {what: 'huh?'}};

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors. Released under the MIT license


This file was generated by verb-cli on September 20, 2014.