Skip to content

Instantly share code, notes, and snippets.

@doc22940
Forked from alexjlockwood/cleanup-figma-names.ts
Created April 9, 2020 12:10
Show Gist options
  • Save doc22940/2aa60778a06045c5be2f149b3a671bdc to your computer and use it in GitHub Desktop.
Save doc22940/2aa60778a06045c5be2f149b3a671bdc to your computer and use it in GitHub Desktop.
Cleans up Figma component and style names
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