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

dtcg-partial-parser

v0.2.0

Published

A partial DTCG file parser

Readme

dtcg-partial-parser

⚠️ This library is in the early stages of development, so breaking changes are likely until the API stablises. Use at your own risk!

A library for partially parsing DTCG files, which:

  1. traverses the DTCG data,
  2. identifies design tokens and groups,
  3. passes the design token / group properties into callback functions you provide, along with any inheritable props (e.g. $type and $deprecated) from parent groups.

Be aware that it does not:

  • ❌ check whether the props have valid values (it just passes the raw value to your callback function)
  • ❌ have any means of dereferencing alias tokens

Use-cases

This library can be useful for building:

  • A fully-featured DTCG file parser (just add some parsing/validation of the prop values and de-referencing logic and you're practically there!)
  • Utilities to analyse or pre-processs DTCG files in some way
    • E.g. if you have a tool that outputs not-quite-valid DTCG data, you could use this to make a script that cleans it up to produce valid DTCG for other tools to consume
  • Prototypes and proof-of-concepts (POCs) of proposals to the DTCG format spec itself
    • Since this library does not validate values and is quite configurable, it lends itself to exploring features or changes that do not currently exist in the DTCG format spec.

Usage

import { parseDtcg } from "dtcg-partial-parser";

// Given some DTCG data, which could be obtained
// by reading a .tokens.json file and passing the
// contents into JSON.parse()...
const dtcgData = {
  token1: {
    $type: "number",
    $value: 123,
  },

  groupA: {
    $type: "dimension",

    token2: {
      $value: {
        value: 1.25,
        unit: "em",
      },
    },
  },
};

// ...and a function that will be called for each
// design token object (i.e. anything with a `$value`)
// property in `dtcgData`...
function logDesignToken(path, combinedProps) {
  console.log(`Found token "${path.join(".")}" with combined props: `, combinedProps);
}

// ...you can parse the data as follows:
parseDtcg(dtcgData, {
  handleDesignToken: logDesignToken,
});

Which will log:

Found token "token1" with combined props:  { '$type': 'number', '$value': 123 }

Found token "groupA.token2" with combined props:  { '$value': { value: 1.25, unit: 'em' }, '$type': 'dimension' }

Note how "token2" inherited its $type from "groupA"! The combinedProps passed into the design token handler function automatically include any inheritable properties from the nearest parent group (currently $type and $deprecated).

You can find additional examples in the examples/ folder.