Skip to main content Skip to docs navigation

filters.js

Custom token filters for Style Dictionary

filters.js

This script defines and registers custom filters for Style Dictionary. Filters control which tokens are included in each output file, based on type, path, or other properties.

Key Responsibilities

  • Register custom filters for color, number, string, and theme tokens
  • Exclude or include tokens based on type and path
  • Enable fine-grained control over which tokens are output for each platform

Example Filters

  • cx/allTokens: Includes all tokens except certain excluded types
  • cx/colorTokens: Includes only color tokens, excluding palette/context/utility
  • cx/themeTokens: Includes only theme color tokens, excluding base/utility
  • cx/numberTokens: Includes only number and certain size tokens
  • cx/stringTokens: Includes only string tokens

Example Usage

import registerFilters from './filters.js'
registerFilters(StyleDictionary)

See Also