---
url: /api/formats/dtcg/src/functions/toDtcg.md
---
[pantoken-root](../../../../index.md) / [formats/dtcg/src](../index.md) / toDtcg

# Function: toDtcg()

> **toDtcg**(`tokens`, `mode?`): `Record`<`string`, [`DtcgNode`](../type-aliases/DtcgNode.md)>

Beta

Convert an IR token list into a DTCG document.

## Parameters

### tokens

readonly [`Token`](../../../../packages/core/src/interfaces/Token.md)\[]

The IR (e.g. from `@pantoken/tokens`).

### mode?

[`Mode`](../type-aliases/Mode.md) = `"light"`

Which colour mode to resolve (default `"light"`).

## Returns

`Record`<`string`, [`DtcgNode`](../type-aliases/DtcgNode.md)>

A nested DTCG token tree.

## Examples

**Convert the default IR to a DTCG tree**

```ts
import { toDtcg } from "@pantoken/dtcg";
import { tokens } from "@pantoken/tokens";

const doc = toDtcg(tokens);
// doc.color.background.brand === { $value: "#0374b5", $type: "color" }
```

**Resolve the dark mode of another theme**

```ts
import { toDtcg } from "@pantoken/dtcg";
import { byTheme } from "@pantoken/tokens";

toDtcg(byTheme("canvas"), "dark");
```
