export interface SectionHeaderOptions { groupBySegment: number; allowedGroups?: string[]; } export function getGroupName(tokenName: string, options: SectionHeaderOptions): string { const { groupBySegment, allowedGroups } = options; const rawGroup = tokenName.split('.')[groupBySegment] || ''; if (allowedGroups && !allowedGroups.includes(rawGroup)) { return 'miscellaneous'; } return rawGroup; } export function shouldShowSectionHeader( currentName: string, previousName: string | undefined, options: SectionHeaderOptions, ): boolean { const currentGroup = getGroupName(currentName, options); if (!previousName) return true; const previousGroup = getGroupName(previousName, options); return currentGroup !== previousGroup; } export function getTokenAlternativeSyntaxes(name: string) { return { figma: name.replace(/\./g, '/'), less: `@${name.replace(/\./g, '-')}`, scss: `$${name.replace(/\./g, '-')}`, }; }