Skip to content

Filters

Filters include or exclude tokens from an output. A token is included only when every filter returns true. Use filters to output only colors to one file, only spacing to another, or only aliases for debugging.

type Filter = {
filter: (token: ResolvedToken) => boolean
}

Return true to include the token, false to exclude it.

Import filters from dispersa/filters:

import { byType, byPath, isAlias, isBase } from 'dispersa/filters'
FilterDescriptionExample
byType(type)Include only tokens of a given typebyType('color')
byPath(pattern)Include tokens matching a string prefix or RegExpbyPath('color.brand') or byPath(/^spacing/)
isAlias()Include only tokens that were alias referencesisAlias()
isBase()Include only base (non-alias) tokensisBase()
import { css } from 'dispersa'
import { byType, isAlias } from 'dispersa/filters'
import { nameKebabCase, colorToHex } from 'dispersa/transforms'
css({
name: 'colors',
file: 'colors.css',
filters: [byType('color')],
transforms: [nameKebabCase(), colorToHex()],
})

This output includes only color tokens, transforms names to kebab-case, and converts values to hex.

  • Global — Filters in BuildConfig reduce the token set for all outputs. A token excluded by a global filter never reaches any output.
  • Per-output — Filters in OutputConfig further reduce tokens for that output only.