Last active
July 12, 2025 19:06
-
-
Save alexjlockwood/af32dc2da4366717bed8947db3d19a5b to your computer and use it in GitHub Desktop.
Cleans up Figma component and style names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const components = figma.root.children.flatMap(pageNode => { | |
| return pageNode.findAll(node => node.type === 'COMPONENT'); | |
| }); | |
| const styles = [ | |
| ...figma.getLocalEffectStyles(), | |
| ...figma.getLocalGridStyles(), | |
| ...figma.getLocalPaintStyles(), | |
| ...figma.getLocalTextStyles(), | |
| ]; | |
| const updatedObjs = [...components, ...styles].filter(obj => { | |
| let updated = false; | |
| if (obj.name !== obj.name.trim()) { | |
| obj.name = obj.name.trim(); | |
| updated = true; | |
| } | |
| if (obj.name !== obj.name.replace(/\s{2,}/g, ' ')) { | |
| obj.name = obj.name.replace(/\s{2,}/g, ' '); | |
| updated = true; | |
| } | |
| if (obj.name.startsWith('.')) { | |
| obj.name = obj.name.replace('.', '_'); | |
| updated = true; | |
| } | |
| return updated; | |
| }); | |
| figma.notify(`Cleaned up ${updatedObjs.length} name(s)`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment