Styledictionary/4/Instantiating Style Dictionary
What Changed
This codemod updates Style Dictionary to be a class in version 4, rather than a regular JS object. This allows for instance creation using the new class instantiator keyword. Due to ES Modules' asynchronous nature, you must await initialization before accessing properties like tokens on the instance. The .extend()
method remains available for creating instances based on another instance.
Before
const StyleDictionary = require('style-dictionary');const sd = StyleDictionary.extend('config.json');console.log(sd.tokens);
After
import StyleDictionary from 'style-dictionary';const sd = new StyleDictionary('config.json');await sd.hasInitialized;console.log(sd.tokens);
Build custom codemods
Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community