Filters
Filters is a hook that provides a way to filter your tokens prior to formatting them to the final output.
Common use cases for filtering are:
- Not outputting your primitive/option tokens such as a color palette
- Splitting component tokens into separate files for each component
Filter structure
A filter is an object with two props:
name
: the name of the filterfilter
: a callback function that receives thetoken
as argument and returns a boolean,true
to include the token,false
to exclude/filter it out. Can also be an async function. Also has a second argument with the Style Dictionary options, which also contains thetokens
object,usesDTCG
option, etc.
Using filters
First you will need to tell Style Dictionary about your filter. You can do this in two ways:
- Using the
.registerFilter
method - Inline in the configuration
hooks.filters
property