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 🙏

© 2026 – Pkg Stats / Ryan Hefner

figvar2dtcg

v0.0.3

Published

Export Figma variables to JSON in the Design Tokens Community Group format with a flexible, extensible API.

Readme

figvar2dtcg

Export Figma variables to JSON in the Design Tokens Community Group format using a flexible, extensible API.

This package is fully typed and works with both ESM and CommonJS modules.

Why use this?

Design systems often require synchronizing tokens from Figma to code. And access to Figma Enterprise plan and Variables REST API is not always possible. Existing plugins might work for most cases, but what if you need something custom?

  • Exclude certain tokens?
  • Use a specific color format?
  • Map dimensions in a unique way?
  • Build a company-specific plugin with full control?

figvar2dtcg gives you the power to tailor your workflow.

DTCG Tokens format can be then utilzed by other tools, like style-dictionary

Getting started

Basic usage

Export all token collections to DTCG format:

import { figvar2dtcg, type DesignTokensFormat } from 'figvar2dtcg'

(async () => {
  const collections = await figma.variables.getLocalVariableCollectionsAsync()
  const tokens: Record<string, DesignTokensFormat> = {}

  for (let collection of collections) {
    tokens[collection.name] = await figvar2dtcg(collection)
  }

  console.log(tokens)
})()

Resolving values for a mode

Automatically resolve token values for a specific mode, including aliases, by following connected collections:

import { figvar2dtcg } from 'figvar2dtcg'
import { getColorsCollection } from './get-colors-collection'

(async () => {
  const collection = await getColorsCollection()
  const tokens = await figvar2dtcg(collection, 'Dark') // Specify the mode name
})()

Using aliases or final values

Control whether to use final values or aliases:

import { figvar2dtcg } from 'figvar2dtcg'
import { getColorsCollection } from './get-colors-collection'

(async () => {
  const collection = await getColorsCollection()

  const withValues = await figvar2dtcg(collection, undefined, { resolveAliases: true })
  const withAliases = await figvar2dtcg(collection, undefined, { resolveAliases: false })

  console.log(withValues)
  console.log(withAliases)
})()

Custom token names

Use custom name resolvers to modify token names (e.g., replace / with ., change case). Resolvers can be asynchronous:

import { figvar2dtcg, nameResolvers } from 'figvar2dtcg'
import { kebabCase } from 'case'

(async () => {
  const collection = await getColorsCollection()
  const tokens = await figvar2dtcg(collection, undefined, {
    nameResolvers: [
      (variable) => kebabCase(variable.name),
      ...nameResolvers,
    ],
  })

  console.log(tokens)
})()

Custom token values

Define custom resolvers to adjust token values. For example, use hsl() for colors or modify dimensions:

import { figvar2dtcg, valueResolvers } from 'figvar2dtcg'
import { convertToHsl } from './colors'

(async () => {
  const collection = await getColorsCollection()
  const modeId = collection.defaultModeId

  const tokens = await figvar2dtcg(collection, undefined, {
    valueResolvers: [
      ...valueResolvers,
      (value, type, variable) => {
        if (type === 'color') return convertToHsl(variable.valuesForMode[modeId])
      },
    ],
  })

  console.log(tokens)
})()

Custom token types

Set custom types for tokens, which can then be used in value resolvers:

{
  "colors": {
    "button": {
      "$type": "myCustomType",
      "$value": "..."
    }
  }
}
import { figvar2dtcg, typeResolvers } from 'figvar2dtcg'

(async () => {
  const collection = await getColorsCollection()

  const tokens = await figvar2dtcg(collection, undefined, {
    typeResolvers: {
      ...typeResolvers,
      myCustomType: (variable) => variable.scopes.includes('ALL_SCOPES'),
    },
  })

  console.log(tokens)
})()