import * as lodash from 'lodash' ; import type { ImmutableStyleMap } from 'theo' ; import type { DesignToken } from '../types' ; import { getTokenCategories } from '../utils/getTokenCategories' ; import { formatSingleTokensWithTemplate } from '../utils/formatSingleTokensWithTemplate' ; import { formatGroupTokensWithTemplate } from '../utils/formatGroupTokensWithTemplate' ; export const tokenTemplate = ( { name , value } ) : string => `export const ${ lodash . camelCase ( name ) } = "${ value . replace ( /"/g , '\\"' ) }";` ; export const categoryTemplate = ( categoryName , props ) : string => `export const ${ lodash . camelCase ( categoryName ) } = {
${ props . map ( ( prop ) => `${ lodash . camelCase ( prop . name ) },` ) . join ( '\n' ) }
};` ; export const es6TokenFormat = ( result ) : string => { const singleTokens = formatSingleTokensWithTemplate ( result , tokenTemplate ) ; const categories = getTokenCategories ( result ) ; const groupedTokens = formatGroupTokensWithTemplate ( result , categories , categoryTemplate ) ; return [ singleTokens , groupedTokens ] . join ( '\n' ) ; } ;