import type { NameTransform, PlatformConfig, TransformedToken } from 'style-dictionary/types'; /** * Style Dictionary transform that removes "base" suffix from token names * while preserving "narrow" suffixes. * * This transform ensures backward compatibility where "base" tokens represent * the default responsive behavior without needing the suffix in the output. * * @example * Input: typography.font-family.page-heading-1.base * Output: typography-font-family-page-heading-1 * * Input: typography.font-family.page-heading-1.narrow * Output: typography-font-family-page-heading-1-narrow */ export const removeBaseVariantTransform: NameTransform = { name: 'name/remove-base-variant', type: 'name', /** * Filter to apply transform only to tokens ending with "base" or "narrow" */ filter: (token: TransformedToken) => { const lastSegment = token.path[token.path.length - 1]; return lastSegment === 'base' || lastSegment === 'narrow'; }, /** * Transform function that removes "base" from token name and path * while preserving "narrow" */ transform: (token: TransformedToken, platformConfig: PlatformConfig) => { const lastSegment = token.path[token.path.length - 1]; const prefix = platformConfig.prefix || ''; if (lastSegment === 'base') { // Remove "base" from the path for generating the name const pathWithoutBase = token.path.slice(0, -1); // Return the name without "base", including the prefix return prefix ? `${prefix}-${pathWithoutBase.join('-')}` : pathWithoutBase.join('-'); } // For "narrow" and other cases, return the full name with prefix const name = token.path.join('-'); return prefix ? `${prefix}-${name}` : name; }, };