---
url: /api/packages/utils/src/functions/makeResolver.md
---
[pantoken-root](../../../../index.md) / [packages/utils/src](../index.md) / makeResolver

# Function: makeResolver()

> **makeResolver**(`base`, `options?`): (`value`) => `string`

Beta

Build a resolver that expands `var(--x)` references to concrete leaf values against `base` (plus
any `overrides`). With `mode` it collapses `light-dark()` to that branch; without, it leaves
`light-dark()` in place. A token carrying a [Token.flatValue](../../../core/src/interfaces/Token.md#flatvalue) resolves through that rather
than its CSS-expression `value`, so callers always land on a real colour.

## Parameters

### base

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

The token set to resolve references against.

### options?

[`ResolveOptions`](../interfaces/ResolveOptions.md) = `{}`

[ResolveOptions](../interfaces/ResolveOptions.md).

## Returns

A function that resolves a value string.

(`value`) => `string`

## Examples

**Expand a reference chain to its concrete leaf**

```ts
import { makeResolver } from "@pantoken/utils";
import type { Token } from "@pantoken/model";

const ir: Token[] = [
  { name: "--instui-leaf", syntax: "<color>", inherits: true, value: "#0374B5" },
  { name: "--instui-brand", syntax: "*", inherits: true, value: "var(--instui-leaf)" },
];

const resolve = makeResolver(ir);
resolve("var(--instui-brand)"); // → "#0374B5"
```

**Collapse light-dark() with a mode, or keep it without one**

```ts
import { makeResolver } from "@pantoken/utils";
import type { Token } from "@pantoken/model";

const ir: Token[] = [
  { name: "--instui-bg", syntax: "*", inherits: true, value: "light-dark(#fff, #000)" },
];

makeResolver(ir)("var(--instui-bg)");                 // → "light-dark(#fff, #000)"
makeResolver(ir, { mode: "light" })("var(--instui-bg)"); // → "#fff"
makeResolver(ir, { mode: "dark" })("var(--instui-bg)");  // → "#000"
```

**Layer overrides that win on name collisions**

```ts
import { makeResolver } from "@pantoken/utils";
import type { Token } from "@pantoken/model";

const ir: Token[] = [
  { name: "--instui-leaf", syntax: "<color>", inherits: true, value: "#0374B5" },
  { name: "--instui-brand", syntax: "*", inherits: true, value: "var(--instui-leaf)" },
];
const overrides: Token[] = [
  { name: "--instui-leaf", syntax: "<color>", inherits: true, value: "#000" },
];

makeResolver(ir, { overrides })("var(--instui-brand)"); // → "#000"
```
