Last active
March 4, 2021 19:57
-
-
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
This file contains 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 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