perfect-postcode/frontend/src/lib/features.ts
2026-05-09 09:26:40 +01:00

22 lines
615 B
TypeScript

import type { FeatureMeta, FeatureGroup } from '../types';
export function groupFeaturesByCategory(features: FeatureMeta[]): FeatureGroup[] {
const groups: FeatureGroup[] = [];
const seen = new Map<string, FeatureMeta[]>();
for (const feature of features) {
if (!feature.group) {
throw new Error(`Feature '${feature.name}' is missing its group`);
}
const groupName = feature.group;
let arr = seen.get(groupName);
if (!arr) {
arr = [];
seen.set(groupName, arr);
groups.push({ name: groupName, features: arr });
}
arr.push(feature);
}
return groups;
}