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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@quartzds/style-dictionary-extensions

v2.1.0

Published

Style Dictionary extensions and helpers for the Quartz design tokens

Downloads

35

Readme


SPDX-FileCopyrightText: © 2025 Schneider Electric

SPDX-License-Identifier: Apache-2.0

Style Dictionary extensions for the Quartz design tokens

CI Status NPM Package License REUSE status

💡 Overview

This package provides extensions and helper functions to transform Quartz design tokens into resources for developers using Style Dictionary. Those design tokens are edited using the Tokens Studio Figma plugin.

Prerequisites

  • A hierarchy of JSON files produced by the Tokens Studio Figma plugin in the "legacy" format (do not enable the DTCG format in the Figma plugin).
  • node ^18.0.0 || >=20.0.0

Token transformation rules

Translating design tokens into platform-specific assets requires rules. Quartz uses specific rules based on its own conventions. The goal of this library is to package all those transformation rules into a convenient API for Style Dictionary.

Supported platforms

  • CSS

Experimental support:

  • Android
  • Swift
  • XAML

Coming later:

  • JavaScript
  • TypeScript

💿 Installation

npm install @quartzds/style-dictionary-extensions

📖 Usage

Create a build script that will configure and run Style Dictionary to output tokens to several formats, using the helpers provided by this package. See the Transformation rules page for the list of transformations provided for each target format.

The general algorithm is as follows:

  1. Create a base StyleDictionary object, pre-configured with Quartz's custom transforms.
  2. For every token set you want to export (desktop, tablet, mobile, dark, light, etc.):
    • create a Style Dictionary Config object using the helpers from this package
    • call the extend(config) method of the base StyleDictionary object to get a new instance from a specific configuration
    • let that Style Dictionary instance generate the files using the buildAllPlatforms() function

Get a base StyleDictionary object

The getPresetStyleDictionary() function registers Quartz extensions and returns a fresh Style Dictionary instance to use as the base to export to one or more formats:

import { getPresetStyleDictionary } from '@quartzds/style-dictionary-extensions'

const baseSD = await getPresetStyleDictionary()

Create Style Dictionary configurations

This package provides transform groups for supported target formats, as well as helper functions to help you set up Style Dictionary configuration objects.

Use the get<Format>PlatformConfig(sourceType, destination, options?) functions to get ready-made PlatformConfig objects to use in your Style Dictionary Config object:

import {
  getAndroidPlatformConfig,
  getCSSPlatformConfig,
  getSwiftPlatformConfig,
} from '@quartzds/style-dictionary-extensions'

const sdConfig = {
  platforms: {
    android: getAndroidPlatformConfig(...),
    css: getCSSPlatformConfig(...),
    swift: getSwiftPlatformConfig(...),
  },
  ...other config properties...
},

Run Style Dictionary generation

Finally, let Style Dictionary build all the platforms for your configuration objects:

var sd = baseSD.extend(desktopConfig)
sd.buildAllPlatforms()

sd = baseSD.extend(lightThemeConfig)
sd.buildAllPlatforms()

// etc.

📓 Simple example

This example assumes the following structure of design tokens files generated by the Tokens Studio Figma plugin:

src/
└── tokens
    ├── private.json <-- don't export these tokens (internal bindings)
    ├── platform
    │   ├── desktop.json
    │   └── mobile.json
    └── theme
        ├── dark.json
        └── light.json

We want to transform these tokens into the following platform-specific assets:

dist/
├── platform
│   ├── desktop.css
│   ├── desktop.swift
│   ├── desktop.xml
│   └── mobile.css
│   └── mobile.swift
│   └── mobile.xml
└── theme
    ├── dark.css
    ├── dark.swift
    ├── dark.xml
    └── light.css
    └── light.swift
    └── light.xml

Here is the script to achieve that:

import {
  getAndroidPlatformConfig,
  getCSSPlatformConfig,
  getPresetStyleDictionary,
  getSwiftPlatformConfig,
  SourceType,
} from '@quartzds/style-dictionary-extensions'
import type { Config, FileHeader } from 'style-dictionary/types'

const baseSD = await getPresetStyleDictionary()

const copyrightFileHeader: FileHeader = (defaultMessage, options) => (...)

const lightThemeConfig: Config = {
  platforms: {
    android: getAndroidPlatformConfig(
      SourceType.theme,
      `dist/theme/light.xml`,
      {
        fileHeader: copyrightFileHeader,
      },
    ),
    css: getCSSPlatformConfig(
      SourceType.theme,
      `dist/theme/light.css`,
      {
        fileHeader: copyrightFileHeader,
        selector: '.qds-theme-light',
      },
    ),
    swift: getSwiftPlatformConfig(
      SourceType.theme,
      `dist/theme/light.swift`,
      {
        fileHeader: copyrightFileHeader,
        className: 'Light',
      },
    ),
  },

  include: [`./tokens/private.json`],
  source: [`./tokens/theme/light.json`],
}

const darkThemeConfig: Config = {
  /* ... */
}

const desktopConfig: Config = {
  /* ... */
}

const mobileConfig: Config = {
  /* ... */
}

const allConfigs = [
  lightThemeConfig,
  darkThemeConfig,
  desktopConfig,
  mobileConfig,
]

for (const config of allConfigs) {
  const sd = StyleDictionary.extend(config)
  sd.cleanAllPlatforms() // Optional
  sd.buildAllPlatforms()
}

⚖️ License

See the LICENSE file for license rights and limitations.