groupby
Group a set of objects by some specific semantic property
Last updated 5 years ago by kchan .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install groupby 
SYNC missed versions from official npm registry.

Groupby Build Status

Group a set of objects by some specific semantic property.

Installation

npm install --save groupby

Example

const groupBy = require('groupby');
var data = [
  {
    index: '1',
    name: 'foo'
  },
  {
    index: '1.1',
    name: 'bar'
  },
  {
    index: '2.2',
    name: 'hoo'
  },
  {
    index: '3.1',
    name: 'hia'
  }
];
// by default it's grouped by `index`
data = groupBy(data);
// output
{
  "1": {
    "1": {
      "name": "bar"
    },
    "name": "foo"
  },
  "2": {
    "2": {
      "name": "hoo"
    }
  },
  "3": {
    "1": {
      "name": "hia"
    }
  }
}

Why

It's useful for managing something with multi-level structure, for example a book, it has chapter 1, chapter 1.1 or even chapter 1.2.1. You can put all files in the same folder and use groupby to structure them when you need the whole book index, like you want to build an API for the book.

License

MIT © EGOIST

Current Tags

  • 0.1.1                                ...           latest (5 years ago)

2 Versions

  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (2)
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |