Skip to content

Commit a61e9eb

Browse files
committed
checkpoint
1 parent 3d1caec commit a61e9eb

1 file changed

Lines changed: 60 additions & 11 deletions

File tree

README.md

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
[![npm version](https://img.shields.io/npm/v/dtcg-tools.svg)](https://www.npmjs.com/package/dtcg-tools)
66
[![License](https://img.shields.io/badge/license-MIT--0-blue.svg)](LICENSE.md)
77

8-
> TypeScript types for the Design Tokens Community Group (DTCG) 2025.10 format and resolver schemas.
8+
> TypeScript types and runtime tools for the [Design Tokens Community Group](https://www.designtokens.org/) (DTCG) 2025.10 format and resolver schemas.
99
1010
## Features
1111

12-
- Type-only package with no runtime API
13-
- Root exports for `Format`, `Resolver`, and related schema types
14-
- Subpath exports for specific token, group, resolver, and value types
12+
- **Types** — Full TypeScript types for the DTCG Format and Resolver specifications, including tokens, groups, sets, modifiers, and value types.
13+
- **Loader** — Runtime loader that reads DTCG resolver documents, resolves `$ref` sources, and merges token sets into a single token tree. Ships with a Node.js filesystem adapter and a pluggable `LoaderSys` interface for any environment.
14+
- **Object Model** — Experimental Typed-OM-like API that represents every token, group, and value as a typed node. Supports alias and JSON Pointer reference resolution, cycle detection, and computed value extraction.
1515

1616
## Installation
1717

@@ -21,6 +21,8 @@ npm install dtcg-tools
2121

2222
## Usage
2323

24+
### Types
25+
2426
```ts
2527
import type { Format, Resolver, Token } from "dtcg-tools";
2628

@@ -39,20 +41,67 @@ const resolver = {
3941
} satisfies Resolver;
4042
```
4143

42-
## Subpath imports
44+
### Loader
45+
46+
```ts
47+
import { LoaderHost } from "dtcg-tools/loader";
48+
import { nodeSys } from "dtcg-tools/loader/node";
49+
50+
const host = new LoaderHost(nodeSys);
51+
const { tokens, sources } = host.load("path/to/resolver.json");
52+
```
53+
54+
Provide a custom `LoaderSys` to run in any environment:
55+
56+
```ts
57+
import { LoaderHost, type LoaderSys } from "dtcg-tools/loader";
58+
59+
const browserSys: LoaderSys = {
60+
readFile: (url) =>
61+
fileMap.get(url.href) ??
62+
(() => {
63+
throw new Error(`Not found: ${url}`);
64+
})(),
65+
currentDirectory: () => new URL("./", location.href),
66+
};
67+
68+
const host = new LoaderHost(browserSys);
69+
```
70+
71+
### Object Model (experimental)
4372

4473
```ts
45-
import type { TokenType } from "dtcg-tools/types/format/tokenType";
46-
import type { DimensionValue } from "dtcg-tools/types/format/values/dimension";
74+
import { OMLoaderHost, getToken, compute, createEvalContext } from "dtcg-tools/loader";
75+
import { nodeSys } from "dtcg-tools/loader/node";
76+
77+
const host = new OMLoaderHost(nodeSys);
78+
const { doc, ctx } = host.load("path/to/resolver.json");
79+
80+
const token = getToken(doc, "color.primary");
81+
if (token) {
82+
const resolved = compute(token.value, ctx);
83+
}
4784
```
4885

86+
## Subpath exports
87+
88+
| Export | Description |
89+
| ------------------------ | ------------------------------------------------------------------ |
90+
| `dtcg-tools` | Type-only — `Format`, `Resolver`, `Token`, and all related types |
91+
| `dtcg-tools/loader` | `LoaderHost`, `OMLoaderHost`, node traversal helpers, `RAW` symbol |
92+
| `dtcg-tools/loader/node` | `nodeSys` adapter and convenience `load()` for Node.js |
93+
| `dtcg-tools/types` | All format and resolver types |
94+
| `dtcg-tools/types/*` | Individual type modules (e.g. `types/format/tokenType`) |
95+
4996
## Development
5097

5198
```bash
52-
npm run lint
53-
npm run type-check
54-
npm run build
55-
npm run test:node
99+
npm run build # compile TypeScript
100+
npm run type-check # type-check without emitting
101+
npm run lint # lint with Biome
102+
npm run format # format with dprint
103+
npm run test:node # run tests in Node.js
104+
npm run test # run tests in Node.js + Chromium, Firefox, and WebKit
56105
```
57106

58107
## License

0 commit comments

Comments
 (0)