Skip to content

Instantly share code, notes, and snippets.

@alexjlockwood
Last active November 24, 2021 21:02
Show Gist options
  • Save alexjlockwood/af32dc2da4366717bed8947db3d19a5b to your computer and use it in GitHub Desktop.
Save alexjlockwood/af32dc2da4366717bed8947db3d19a5b 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