Files
entdb-entitlements-iOS/src/lib/tokenizer.ts
T
cc 5e30a8b930 Add responsive header with quick filter tokens for entitlement keys
- Move filter controls into sticky header via React portal
- Responsive layout: wraps to 2 rows on mobile, single row on desktop
- Keys/Files nav shows icons only on mobile, icons+text on larger screens
- Add tokenizer that extracts frequent terms from entitlement keys
- Display clickable token pills for quick filtering (apple, security, etc.)
- Move item counts below header, above lists
- Fix light mode contrast (darken muted-foreground)
- Reduce homepage spacing
2026-04-15 19:06:23 +02:00

35 lines
1003 B
TypeScript

export function tokenizeKeys(keys: string[]): Map<string, number> {
const freq = new Map<string, number>();
for (const key of keys) {
// Split by dots, dashes, underscores
const parts = key.split(/[.\-_]/);
for (const part of parts) {
// Further split camelCase: "AppBundles" -> ["App", "Bundles"]
const camelParts = part.split(/(?=[A-Z])/).filter((p) => p.length > 0);
for (const token of camelParts) {
const lower = token.toLowerCase();
// Skip very short or numeric tokens
if (lower.length < 3 || /^\d+$/.test(lower)) continue;
freq.set(lower, (freq.get(lower) || 0) + 1);
}
}
}
return freq;
}
export function getTopTokens(
freq: Map<string, number>,
limit = 20,
minCount = 5
): Array<{ token: string; count: number }> {
return Array.from(freq.entries())
.filter(([, count]) => count >= minCount)
.sort((a, b) => b[1] - a[1])
.slice(0, limit)
.map(([token, count]) => ({ token, count }));
}