Class TokensConverter

This class is used to convert a tokens object into CSS variables.

Constructors

  • Parameters

    • options: Options = {}

      This is an optional object that can be used to customize the output

    Returns TokensConverter

    Example

    const options = {
    unit: 'px',
    transform: (key, value) => {
    * // Skip tokens with unknown CSS properties
    * if (key.includes('unknown-css-property')) {
    * return null;
    * }
    *
    * // Change the value of all font-family tokens to Roboto
    * if (key.includes('font-family')) {
    * return { key, value: 'Roboto' };
    * }
    *
    * // Return the original token
    * return { key, value };
    },
    };

    const tokensConverter = new TokensConverter(options);
    const result = tokensConverter.toCssVariables(tokensObj);

Properties

options: Options

Methods

  • Parameters

    • key: string
    • output: string

    Returns string

  • Parameters

    • css: string

    Returns string

  • Parameters

    • value: any
    • unit: string

    Returns string

  • Parameters

    • key: string
    • value: any
    • prefix: string

    Returns string

  • Parameters

    • key: string
    • tokensObj: Record<string, any>
    • prefix: string
    • output: string

    Returns string

  • Parameters

    • tokensObj: Record<string, any>
    • prefix: string

    Returns string

  • Parameters

    • key: string
    • value: any
    • prefix: string

    Returns string

  • Parameters

    • key: string
    • value: any
    • prefix: string
    • output: string

    Returns string

  • Parameters

    • key: string

    Returns string

  • Parameters

    • tokensObj: Record<string, any>

      The object (key and value) containing the tokens

      Example

      const tokensObj = {
      colors: {
      primary: '#000',
      secondary: '#fff',
      },
      fontSizes: {
      small: '12px',
      medium: '16px',
      large: '20px',
      },
      spacing: {
      small: '8px',
      medium: '16px',
      large: '24px',
      },
      };

    Returns string

  • Parameters

    • tokensObj: Record<string, any>
    • prefix: string = ''

    Returns string