New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

token-transformer

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

token-transformer

A utility that transforms tokens from Tokens Studio for Figma (formerly known as Figma Tokens) to a format that is readable by Style Dictionary.

  • 0.0.33
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Token Transformer

Converts tokens from Tokens Studio for Figma to something Style Dictionary can read, removing any math operations or aliases, only resulting in raw values.

CLI usage

How to use

Install (either globally or local) npm install token-transformer -g

node token-transformer input output sets excludes

node token-transformer input.json output.json global,dark,components global

node token-transformer input.json output.json --expandTypography=false

node token-transformer input.json output.json --expandTypography=false --expandShadow=false

node token-transformer input.json output.json --expandTypography=false --expandShadow=false --expandComposition=false

node token-transformer input.json output.json --expandTypography=false --expandShadow=false --expandComposition=false --expandBorder=false

node token-transformer input.json output.json --expandTypography=false --expandShadow=false --expandComposition=false --expandBorder=false --preserveRawValue=true

node token-transformer input.json output.json --expandTypography=false --expandShadow=false --expandComposition=false --expandBorder=false --preserveRawValue=true resolveReferences=false

You can also set a directory as an input instead of providing just one file.

node token-transformer src output.json core/colors,themes/dark core/colors

Parameters

Input: Filename of input

Output: Filename of output

Sets: Sets to be used, comma-seperated

Excludes: Sets that should not be part of the export (e.g. a global color scale)

--expandTypography: true|false to enable/disable automatic expansion of typography types (default: false)

--expandShadow: true|false to enable/disable automatic expansion of boxShadow types (default: false)

--preserveRawValue: true|false to enable/disable addition of a rawValue key containing the unresolved value (default: false)

--throwErrorWhenNotResolved: true|false to enable/disable throwing errors when a reference fails to resolve (default: false)

--resolveReferences: true|false|'math' to enable/disable resolving references, removing any aliases or math expressions (default: true)

Programmatic usage

This library can also be used programmatically to resolve tokens without giving it access to the underlying file system.

const { transformTokens } = require('token-transformer');

const rawTokens = {
    setA:{
        "sizing": {
            "base": {
            "value": "4",
            "description": "Alias value",
            "type": "sizing"
            },
            "large": {
            "value": "$sizing.base * 2",
            "description": "Math value",
            "type": "sizing"
            }
        }
    }
};

const setsToUse = ['setA'];
const excludes = [];

const transformerOptions = {
  expandTypography: true,
  expandShadow: true,
  expandComposition: true,
  expandBorder: true,
  preserveRawValue: false,
  throwErrorWhenNotResolved:  true,
  resolveReferences:true
}

const resolved = transformTokens(rawTokens,setsToUse, excludes,transformerOptions);

/*{
  sizing: {
    base: { value: 4, description: 'Alias value', type: 'sizing' },
    large: { value: 8, description: 'Math value', type: 'sizing' } 
  }
}*/

FAQs

Package last updated on 25 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc