npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

token-transformer

v0.0.33

Published

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

Downloads

271,535

Readme

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' } 
  }
}*/