@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
35 lines • 1.89 kB
TypeScript
import type { SortConfig, GroupConfig, Group, DataRecord } from '../types/interfaces';
/**
* Sorts an array of data records according to one or more sort descriptors.
*
* Records are compared using each {@link SortConfig} in order; the next config is
* only consulted when the current one considers two records equal (stable
* multi-column sort). Dimension fields are compared lexicographically; measure
* fields are compared numerically via {@link calculateMeasureValue}.
*
* @param data - The array of records to sort. The original array is not mutated.
* @param sortConfig - Ordered list of sort descriptors. An empty array returns `data` unchanged.
* @param groupConfig - Unused in the current implementation; reserved for future
* group-aware sorting strategies.
* @returns A new sorted array; the input `data` array is never mutated.
*
* @example
* const sorted = applySort(rows, [{ field: 'region', direction: 'asc', type: 'dimension' }]);
*/
export declare function applySort<T extends DataRecord>(data: T[], sortConfig: SortConfig[], groupConfig?: GroupConfig | null): T[];
/**
* Sorts an array of pre-computed {@link Group} objects by their aggregate values.
*
* Each group's `aggregates` map is keyed as `"<aggregation>_<field>"` (e.g. `"sum_sales"`).
* Groups are compared in `sortConfig` order, falling back to the next descriptor on a tie.
*
* @param groups - The groups to sort. The original array is not mutated.
* @param sortConfig - Ordered list of sort descriptors referencing measure fields.
* An empty array returns `groups` unchanged.
* @returns A new sorted array of groups.
*
* @example
* const sorted = sortGroups(groups, [{ field: 'sales', direction: 'desc', aggregation: 'sum', type: 'measure' }]);
*/
export declare function sortGroups(groups: Group[], sortConfig: SortConfig[]): Group[];
//# sourceMappingURL=sorter.d.ts.map