# 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.

Latest version **0.0.33** (published 2023-05-25) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install token-transformer
pnpm add token-transformer
yarn add token-transformer
bun add token-transformer
```

Provides the command `token-transformer`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.33 |
| Published | 2023-05-25 |
| First published | 2021-09-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 148.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | six7 |
| Maintainers | six7 |

## Links

- npm: https://www.npmjs.com/package/token-transformer
- Repository: https://github.com/tokens-studio/figma-plugin
- Homepage: https://github.com/tokens-studio/figma-plugin#readme
- Issues: https://github.com/tokens-studio/figma-plugin/issues
- npm.io page: https://npm.io/package/token-transformer

## Dependencies (1)

- [yargs](https://npm.io/package/yargs.md) ^17.6.2

## Recent versions

- 0.0.33 (latest) — 2023-05-25
- 0.0.32 — 2023-03-24
- 0.0.31 — 2023-03-24
- 0.0.30 — 2023-02-22
- 0.0.29 — 2023-01-05
- 0.0.28 — 2022-12-01
- 0.0.27 — 2022-09-15
- 0.0.26 — 2022-09-08
- 0.0.25 — 2022-08-13
- 0.0.24 — 2022-06-27
- 0.0.23 — 2022-05-24
- 0.0.22 — 2022-05-06
- 0.0.21 — 2022-05-04
- 0.0.20 — 2022-04-01
- 0.0.19 — 2022-02-24
- … 18 more at https://npm.io/package/token-transformer/versions

## 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.

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

```

---
_Source: https://npm.io/package/token-transformer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
