JavaScript (and TypeScript)

Terrazzo’s JS plugin generates JavaScript, TypeScript, and JSON output from your tokens.

Setup

npm i -D @terrazzo/plugin-js
import pluginJS from "@terrazzo/plugin-js";

/** @type {import("@terrazzo/cli").Config} */
export default {
  plugins: [
    pluginJS({
      output: {
        js: "index.js",
        ts: "index.d.ts",
        json: false, // set to a filename to generate JSON
      },
    }),
  ],
};

Usage

import token from "./tokens/index.js";

token("color.blue.500");

Config

Configure options in terrazzo.config.js:

import pluginJS from "@terrazzo/plugin-js";

/** @type {import("@terrazzo/cli").Config} */
export default {
  plugins: [
    pluginJS({
      /* options */
    }),
  ],
};

Options

NameTypeDescription
jsstring | booleanSet to a filename, or false to disable (default: index.js).
tsstring | booleanSet to a filename, or false to disable (default: index.d.ts) Note: this can’t be enabled if js is disabled).
jsonstring | booleanSet to a filename, or false to disable (default: false).