In-Memory Mode
When to Use In-Memory Mode
Section titled “When to Use In-Memory Mode”- Build tools that process tokens from a database or API
- API endpoints that generate token output on request
- Unit tests that verify token output
- Serverless functions with read-only or ephemeral filesystems
Pass a ResolverDocument Directly
Section titled “Pass a ResolverDocument Directly”Instead of a path to a resolver file, pass a ResolverDocument object:
import type { ResolverDocument } from 'dispersa'import { Dispersa, css } from 'dispersa'import { colorToHex, nameKebabCase } from 'dispersa/transforms'
const resolver: ResolverDocument = { version: '2025.10', sets: { base: { sources: [{ color: { primary: { $type: 'color', $value: { colorSpace: 'srgb', components: [0, 0.4, 0.8] }, }, }, }], }, }, resolutionOrder: [{ $ref: '#/sets/base' }],}
const dispersa = new Dispersa({ resolver })Omit buildPath — Output Stays in Memory
Section titled “Omit buildPath — Output Stays in Memory”Do not set buildPath. Omit the file option on outputs. Generated content is available on output.content:
const result = await dispersa.build({ outputs: [ css({ name: 'css', preset: 'bundle', selector: ':root', transforms: [nameKebabCase(), colorToHex()], }), ],})
for (const output of result.outputs) { console.log(output.content) // CSS string}Token Resolution Without Rendering
Section titled “Token Resolution Without Rendering”Use resolveTokens() to resolve tokens for a single permutation without rendering. Pass the same inline resolver used in the constructor:
const tokens = await dispersa.resolveTokens(resolver, { theme: 'light' })// Use tokens for validation, transformation, or custom renderingUse resolveAllPermutations() to get all permutations at once:
const allPermutations = await dispersa.resolveAllPermutations(resolver)// allPermutations is an array of { tokens, modifierInputs } for each modifier combinationTesting Example
Section titled “Testing Example”Write unit tests that verify token output without writing files:
const dispersa = new Dispersa({ resolver: testResolver })const result = await dispersa.build({ outputs: [css({ name: 'css', preset: 'bundle', selector: ':root', transforms: [colorToHex()] })],})expect(result.outputs[0].content).toContain('--color-primary: #0066cc') TypeScript Type Generation Generate TypeScript declaration files from your resolved tokens for type-safe token access.