@mindfiredigital/pivothead
Version:
PivotHead is a powerful and flexible library for creating interactive pivot tables in JavaScript applications. It provides a core engine for data manipulation and, in the future, will be compatible with wrappers for React, Vue, Svelte, and Angular, making
15 lines • 771 B
TypeScript
import type { AggregationType } from '../types/interfaces';
/**
* Calculates an aggregate value for a specific field across a collection of items.
*
* @param items - Array of data records to aggregate.
* @param field - The key of the field to aggregate on each record.
* @param type - The aggregation operation to apply: `'sum'`, `'avg'`, `'min'`, `'max'`, or `'count'`.
* @returns The computed aggregate as a number, or `0` if the array is empty or the type is unrecognised.
*
* @example
* const total = calculateAggregates(rows, 'sales', 'sum');
* const average = calculateAggregates(rows, 'profit', 'avg');
*/
export declare function calculateAggregates<T>(items: T[], field: keyof T, type: AggregationType): number;
//# sourceMappingURL=aggregator.d.ts.map