1.0.2 • Published 5 years ago

data-grouper v1.0.2

Weekly downloads
15
License
-
Repository
github
Last release
5 years ago

data-grouper

This class allows you to group data sets together for ease of use, functionality and data manipulation.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

You will need to have core-js/es6/map at the very least, preferably the entire package. This is because we had issues with backwards compatability when running on older browsers, JFX and the like. The following import is the only dependency in the class.

import * as Map from 'core-js/es6/map';

Installing

npm i data-grouper

How to Use

Begin with json data.

let dataIn = 
[{  
    "revenue":75.00,
    "cost":50.00,
    "grossProfit":25.00,
    "staticVariable":"hello"
},
{  
    "revenue":100.50,
    "cost":50.50,
    "grossProfit":50.00,
    "staticVariable":"hello"
}]

Make sure you are importing the class within your .ts file.

import { Grouper } from '../grouper';

Set a data set variable of some sort.

let dataOut: any;

Then call the grouper builder class methods.

dataOut = new Grouper(dataIn)
  .include('staticVariable')
  .aggSum('revenue', 'cost', 'grossProfit')
  .aggAvg('revenue', 'cost', 'grossProfit')
  .custom('doubleCost', row => ( (row.cost * 2).toFixed(1) )
  .group();

Your dataOut should now look like this:

[{  
    "revenueSum":175.50,
    "costSum":100.50,
    "grossProfitSum":75.00,
    "revenueAvg":87.75,
    "costAvg":50.25,
    "grossProfitAvg":37.50,
    "staticVariable":"hello",
    "doubleCost":201
}]

Built With

Authors

SovietFrontier

GregKosmo

See also the list of contributors who participated in this project.

License

None

Acknowledgments

  • Thank you to all participating coders.