Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@terrazzo/parser

terrazzoapp63.9kMIT0.8.1TypeScript support: included

Parser/validator for the Design Tokens Community Group (DTCG) standard.

design tokens, dtcg, cli, w3c, design system, typescript, sass, css, style tokens, style system, linting, lint

readme

⛋ @terrazzo/parser

The JS API is a lower-level API than the CLI that can be used to build Design Token systems. The JS API runs anywhere JavaScript does, including in Node.js, the browser, and serverless functions.

Basic Usage

npm i -D @terrazzo/parser

And here’s a basic example showing config, parse, and build steps:

import { defineConfig, parse, build } from "@terrazzo/parser";

const config = defineConfig(
  {
    // config options
  },
  { cwd: new URL(import.meta.url) }
);

const rawTokens = "(any JSON or YAML)";
const { tokens, sources } = await parse(
  [{ filename: new URL("file:///tokens.json"), src: rawTokens }],
  { config }
);
const buildResult = await build(tokens, { sources, config });

It’s worth noting the JS API is a little more manual work than the CLI:

  • parse() and build() are distinct steps that each do some of the work.
  • defineConfig() needs a cwd so it can resolve files (this can even be a remote URL, so long as it’s a URL())
  • The AST generated from parse() must get passed into build() so the error messages can point to the right lines in the source file.
  • The build() step only returns a final array of outputFilesin memory but doesn’t write them to disk. It’s up to you to write them to disk, upload them somewhere, etc.

Full documentation

changelog

@terrazzo/parser

0.8.1

Patch Changes

0.8.0

Minor Changes

Patch Changes

0.7.3

Patch Changes

0.7.2

Patch Changes

0.7.1

Patch Changes

0.7.0

Minor Changes

  • #454 44ff082 Thanks @drwpow! - ⚠️ Breaking change: the new color token object format uses "components" instead of "channels". Please update your tokens accordingly.

Patch Changes

0.6.3

Patch Changes

0.6.2

Patch Changes

0.6.1

Patch Changes

0.6.0

Minor Changes

  • #425 9a98ab0 Thanks @drwpow! - feat: ⚠️ Breaking change: aliasing to specific modes (# character) is deprecated. It was an experimental feature in Cobalt 1.0 with unpredictable behavior. In some upcoming spec changes it will be incompatible with advanced usecases.

  • #425 9a98ab0 Thanks @drwpow! - fix: Improvements to mode aliasing and mode overrides. typography tokens only have to partially-declare overrides for modes, while keeping their core set. While this has been supported, behavior was buggy and sometimes was inconsistent.

  • #425 9a98ab0 Thanks @drwpow! - ⚠️ Breaking change: cubicBezier tokens no longer support aliases as values, in line with the spec.

Patch Changes

  • #425 9a98ab0 Thanks @drwpow! - fix: Improved handling of modes partially overriding object tokens (e.g. typography modes modifying a single value). In plugin-css, for instance, you may notice more output, but it’s done for safer style generation.

  • #425 9a98ab0 Thanks @drwpow! - feat: Further improved reverse alias lookups to be more accurate and more complete

  • #425 9a98ab0 Thanks @drwpow! - fix: Better error messages on alias mismatches

  • #425 9a98ab0 Thanks @drwpow! - fix: [plugin-css] Font Family names without spaces no longer get quotes.

    fix: Font Family tokens are always normalized to an array internally for easier parsing.

  • #425 9a98ab0 Thanks @drwpow! - feat: @terrazzo/plugin-css now returns entire token for variableName. This is a minor breaking change from variableName(name: string)variableName(token: Token), but current users can just use token.id to get the same value as before.

    ⚠️ Minor internal breaking change as a result: transformCSSValue() in @terrazzo/token-tools now requires entire token️ to make this possible.

  • #425 9a98ab0 Thanks @drwpow! - fix: ⚠️ [plugin-css] Minor breaking change: transition tokens no longer generate variables for sub-parts. This is a change done in service to better protect “allowed” token usage. If you want consumers to be able to “break apart” tokens, then they must also exist as individual tokens that get aliased.

  • Updated dependencies [9a98ab0, 9a98ab0, 9a98ab0, 9a98ab0, 9a98ab0, 9a98ab0, 9a98ab0, 9a98ab0, 9a98ab0]:

0.5.0

Minor Changes

  • #420 ff3d9d1 Thanks @drwpow! - fix: ⚠️ Breaking change: CSS aliases will revert to original 1.0 behavior and be “shallow,” meaning they’ll be preserved as-written. Terrazzo 2.0 (beta) attempted to simplify aliases to only be single-depth, but that results in unintentional behavior.

Patch Changes

  • #420 ff3d9d1 Thanks @drwpow! - fix: Improve reverse alias lookups (needed for plugin-css, where redeclared base tokens need downstream aliases to be redeclared too, so the values aren’t stale)

  • #419 3962918 Thanks @drwpow! - Improve CLI logging and debugging for performance testing

  • #420 ff3d9d1 Thanks @drwpow! - fix: Minor performance improvements and cleanup

  • #420 ff3d9d1 Thanks @drwpow! - fix: CSS utilities alphabetize declarations to produce more consistent output. Reordering tokens should be a plugin-level concern; parser will preserve token authoring order.

  • Updated dependencies [ff3d9d1, 3962918, ff3d9d1, ff3d9d1, ff3d9d1]:

0.4.0

Minor Changes

  • #416 822c956 Thanks @drwpow! - fix: ⚠️ Breaking change: CSS variables updated to closer match Cobalt 1.0 behavior

Patch Changes

0.3.5

Patch Changes

0.3.4

Patch Changes

0.3.3

Patch Changes

0.3.2

Patch Changes

0.3.1

Patch Changes

0.3.0

Minor Changes

  • #391 8e6810c Thanks @drwpow! - fix: ⚠️ Breaking change: Remove dash around numbers in CSS var names

Patch Changes

0.2.9

Patch Changes

0.2.8

Patch Changes

0.2.7

Patch Changes

0.2.6

Patch Changes

0.2.5

Patch Changes

0.2.4

Patch Changes

0.2.3

Patch Changes

0.2.2

Patch Changes

0.2.1

Patch Changes

0.2.0

Minor Changes

Patch Changes

0.1.3

Patch Changes

0.1.2

Patch Changes

0.1.1

Patch Changes

0.1.0

Minor Changes

Patch Changes

0.0.19

Patch Changes

0.0.18

Patch Changes

0.0.17

Patch Changes

  • #302 d0a9df4 Thanks @drwpow! - Fix parser bug with partialAliasOf that would lead to incorrect final values when aliasing

0.0.13

Patch Changes

0.0.12

Patch Changes