Filters Reference
Filter Type
Section titled “Filter Type”type Filter = { filter: (token: ResolvedToken) => boolean}Return true to include the token, false to exclude it. A token is included only when every filter returns true.
Import from dispersa/filters:
import { byType, byPath, isAlias, isBase } from 'dispersa/filters'byType(type)
Section titled “byType(type)”Include only tokens of a given type.
byType(type: TokenType): FilterTokenType: 'color' | 'dimension' | 'fontFamily' | 'fontWeight' | 'duration' | 'cubicBezier' | 'number' | 'shadow' | 'typography' | 'border' | 'strokeStyle' | 'transition' | 'gradient'
Examples
Section titled “Examples”import { byType } from 'dispersa/filters'
byType('color') // Colors onlybyType('dimension') // Dimensions only (spacing, size, etc.)byType('fontFamily') // Font familiesbyType('fontWeight') // Font weightsbyType('duration') // Durations (for animations)byType('shadow') // Shadow tokensbyType('typography') // Typography compositescss({ name: 'colors', file: 'colors.css', filters: [byType('color')],})byPath(pattern)
Section titled “byPath(pattern)”Include tokens whose path matches a string prefix or RegExp.
byPath(pattern: RegExp | string): FilterString pattern (prefix match)
Section titled “String pattern (prefix match)”Matches tokens whose path starts with the given string (exact prefix, using startsWith).
import { byPath } from 'dispersa/filters'
byPath('color.brand') // color.brand.primary, color.brand.secondary, etc.byPath('spacing') // spacing.sm, spacing.md, spacing.lg, etc.byPath('typography.h1') // typography.h1.fontSize, typography.h1.lineHeight, etc.RegExp pattern
Section titled “RegExp pattern”Full path matching with regex.
byPath(/^color\.(brand|semantic)/) // color.brand.* or color.semantic.*byPath(/spacing\.(sm|md|lg)$/) // Ends with spacing.sm, .md, or .lgbyPath(/\.primary$/) // Any path ending in .primarycss({ name: 'brand', file: 'brand.css', filters: [byPath(/^color\.brand/)],})isAlias()
Section titled “isAlias()”Include only tokens that were alias references (i.e. they referenced another token via {token.name} and were resolved to that token’s value).
isAlias(): FilterAlias tokens are semantic or component tokens that point to base tokens. Use this filter to output only the “wire-up” layer, e.g. for debugging or documentation.
json({ name: 'aliases', file: 'aliases.json', filters: [isAlias()],})isBase()
Section titled “isBase()”Include only base tokens — the complement of isAlias(). Base tokens hold the raw values; alias tokens reference them.
isBase(): FilterUse when you want to exclude semantic/component tokens and output only primitive values.
css({ name: 'primitives', file: 'primitives.css', filters: [isBase()],})Combining Filters
Section titled “Combining Filters”All filters are AND-combined. A token must pass every filter to be included.
import { byType, byPath, isBase } from 'dispersa/filters'
filters: [ byType('color'), byPath('color.brand'), isBase(),]// Only base color tokens under color.brand.*