Skip to content

Instantly share code, notes, and snippets.

@dbanksdesign
Created April 2, 2020 19:01
Show Gist options
  • Save dbanksdesign/da80cb401c59bd58b29147ee654a8d98 to your computer and use it in GitHub Desktop.
Save dbanksdesign/da80cb401c59bd58b29147ee654a8d98 to your computer and use it in GitHub Desktop.
Style Dictionary replacing transform in transformGroup
const StyleDictionary = require('style-dictionary');
// Way 1:
// Will run both name transforms, but yours will run last
// StyleDictionary.registerTransformGroup({
// name: 'less',
// transforms: StyleDictionary.transformGroup.less.concat('name/ti/camel')
// });
// Way 2:
// This will find and replace the first name transform
// found in the transform group
const nameIndex = StyleDictionary.transformGroup.less
.findIndex(transform => {
return transform.startsWith('name')
});
StyleDictionary.registerTransformGroup({
name: 'less',
transforms: [
...StyleDictionary.transformGroup.less.slice(0, nameIndex),
'name/ti/camel',
...StyleDictionary.transformGroup.less.slice( nameIndex + 1)
]
});
// You can also directly modify the transform group
// if you export a config object. All transforms, transformGroups, and formats are properties that can be
// overriden
module.exports = {
transformGroup: {
less: StyleDictionary.transformGroup.less.concat('name/ti/camel')
},
source: [],
platforms: {
//...
}
}
@joonaojapalo
Copy link

Also, why not?

StyleDictionary.transformGroup.less.map(x => x.replace('name/to/kebab', 'name/ti/camel'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment