In-memory analytics: groupBy with multi-key aggregations, having filters, and pivot helper.
Group rows of data by keys, compute sums/averages/counts per group, filter on aggregates, and pivot tables. Zero dependencies, typed aggregation config, suitable for reports and dashboards.
export function groupBy(rows, keys, aggregates?, having?, orderBy?) → GroupResult[]
export function pivot(rows, rowKey, colKey, valueAgg?, valueKey?) → GroupResult[]npm install @ferrow/group-aggregateimport { groupBy, pivot } from 'group-aggregate';
const sales = [
{ product: 'A', region: 'US', amount: 100 },
{ product: 'A', region: 'EU', amount: 150 },
{ product: 'B', region: 'US', amount: 200 },
];
const totals = groupBy(sales, ['product'], { total: 'sum' }, undefined, (a, b) => b.total - a.total);
// => [ { product: 'B', total: 200 }, { product: 'A', total: 250 } ]
const pivotTable = pivot(sales, 'product', 'region', 'sum', 'amount');
// => [ { product: 'A', US: 100, EU: 150 }, { product: 'B', US: 200 } ]- Aggregations compute only on numeric columns; non-numeric values become undefined.
- In-memory only; rows larger than available RAM will fail.
- No query optimization; scans entire dataset once per groupBy call.
Part of the ferrow-toolkit collection · Sponsored by Ferrow