JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 67232
  • Score
    100M100P100Q190858F
  • License MIT

Group array of objects into lists.

Package Exports

  • group-array

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 (group-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

group-array NPM version Build Status

Group array of objects into lists.

Install with npm

$ npm i group-array --save

Usage

var groupArray = require('group-array');

API

groupBy

Create groupings from array's values.

Params

  • arr {Array}: Array to group.
  • grouper {Function}: Optional grouping function that takes acc, value, i, arr, setter
  • setter {Function}: Optional setter function that takes acc, group, value, i, arr
  • acc {Object|Array}: Optional accumulator object or array passed to the setter function.
  • returns {Object|Array}: Object or array containing groups as keys and list of objects as values in the group.

Example

function grouper (acc, value, i, arr, setter) {
  return value.group;
}

function setter (acc, group, value, i, arr) {
  acc[group] = acc[group] || [];
  acc[group].push(value);
}

var arr = [
  { group: 'one', content: 'A'},
  { group: 'one', content: 'B'},
  { group: 'two', content: 'C'},
  { group: 'two', content: 'D'},
  { group: 'three', content: 'E'},
  { group: 'three', content: 'F'}
];

var groups = groupBy(arr, grouper, setter);
//=> {
//=>   one: [
//=>     { group: 'one', content: 'A'},
//=>     { group: 'one', content: 'B'}
//=>   ],
//=>   two: [
//=>     { group: 'two', content: 'C'},
//=>     { group: 'two', content: 'D'}
//=>   ],
//=>   three: [
//=>     { group: 'three', content: 'E'},
//=>     { group: 'three', content: 'F'}
//=>   ]
//=> }
  • group-object: Group object keys and values into lists.
  • get-value: Use property paths ( a.b.c) to get a nested value from an object.
  • union-value: Set an array of unique values as the property of an object. Supports setting deeply… more

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Brian Woodward

License

Copyright © 2015 Brian Woodward Released under the MIT license.


This file was generated by verb-cli on July 19, 2015.