Repository navigation
API Reference
import {
generate, write, stale,
defineConfig, resolveConfig, findConfig, loadConfig,
DEFAULT_COLLECTIONS,
} from "@mrzr/figma-tokens";The package is ESM. The command line is built on these functions: it is findConfig → loadConfig → generate → write (or stale for --check).
generate(config: FigmaTokensConfig, cwd?: string): Promise<OutputFile[]>Reads the input, builds the CSS and returns it. Writes nothing. cwd is the folder that relative input and outDir are resolved against; it defaults to process.cwd(). The result has one entry for css, and one for tailwind unless it is false.
interface OutputFile {
path: string; // absolute
content: string;
}It rejects with the errors in Troubleshooting.
write(files: OutputFile[]): voidCreates the folders and writes each file, overwriting it.
stale(files: OutputFile[]): string[]Returns the paths whose file is missing or whose content differs from what generate returned. An empty array means up to date. This is what --check uses.
import { generate, loadConfig, stale, write } from "@mrzr/figma-tokens";
const config = await loadConfig("figma-tokens.config.yaml");
const files = await generate(config, process.cwd());
if (stale(files).length > 0) write(files);Returns the object you pass. It only gives your editor the types.
resolveConfig(config: FigmaTokensConfig): ResolvedConfigApplies every default (Configuration), merges collections over DEFAULT_COLLECTIONS and lower-cases px and primitives.keep. Throws when input or outDir is missing, and for an option name it does not know. generate calls it for you.
findConfig(cwd: string, explicit?: string): stringReturns the absolute path of the config: explicit resolved against cwd, or the first of the default names found in cwd, in the order listed in CLI. Throws figma-tokens: no config at <file> or figma-tokens: no config found; create figma-tokens.config.yaml (see the README).
loadConfig(file: string): Promise<FigmaTokensConfig>Parses a file ending in .json as JSON and any other file as YAML (JSON is valid YAML, so an rc file may hold either). Throws figma-tokens: <file> is not valid YAML (…) (or JSON), figma-tokens: <file> must hold a mapping of options when the content is not a mapping, and figma-tokens: <file> is a script; the config must be YAML or JSON for a .js, .mjs, .cjs or .ts file. The paths in the result are not resolved: pass the folder of the config file as cwd to generate, as the CLI does.
The collection table from Input-Format, as Record<string, string>.
FigmaTokensConfig, ResolvedConfig and OutputFile are exported as types. The fields of FigmaTokensConfig are the options in Configuration.