Skip to content

Instantly share code, notes, and snippets.

@kemiljk
Last active March 4, 2021 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kemiljk/d7820f1c625dcf8cbdefcce0f1eb0f5c to your computer and use it in GitHub Desktop.
Save kemiljk/d7820f1c625dcf8cbdefcce0f1eb0f5c to your computer and use it in GitHub Desktop.
A way to lint common phrases we use in our design files that can be miswritten
const find = ["Move in", "move in", "Homehero", "wifi", "Wifi", "WiFi"];
const replace = ["Move-in", "move-in", "HomeHero", "Wi-Fi"];
const layers = figma.currentPage.findAll((node) => node.type === "TEXT");
figma.currentPage.selection = layers;
const { selection } = figma.currentPage;
async function lintTextNodes(): Promise<String> {
figma.root.children.flatMap((pageNode) =>
pageNode.selection.forEach(async (node) => {
if (layers.length > 0 && node.type === "TEXT") {
await figma.loadFontAsync(node.fontName as FontName);
node.characters = node.characters.replaceAll(find[0], replace[0]);
node.characters = node.characters.replaceAll(find[1], replace[1]);
node.characters = node.characters.replaceAll(find[2], replace[2]);
node.characters = node.characters.replaceAll(find[3], replace[3]);
node.characters = node.characters.replaceAll(find[4], replace[3]);
node.characters = node.characters.replaceAll(find[5], replace[3]);
}
return Promise.resolve("Done!");
})
);
if (layers.length === 0) {
return Promise.reject("No layers selected");
}
}
lintTextNodes();
figma.notify("All linted");
figma.closePlugin();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment