Skip to content

Instantly share code, notes, and snippets.

@PavelLaptev
Created April 25, 2020 10:20
Show Gist options
  • Save PavelLaptev/6680abdcae0e6f1a5698f1817a1f09b2 to your computer and use it in GitHub Desktop.
Save PavelLaptev/6680abdcae0e6f1a5698f1817a1f09b2 to your computer and use it in GitHub Desktop.
export default function populateByTemplateString(selectedLayers, JSONobj, btnName) {
let newItem = 0;
const loopSelected = arr => {
arr.map(item => {
if (item.type === 'TEXT' && item.characters.includes(`{${btnName}}`)) {
figma.loadFontAsync(item.fontName).then(() => {
item.characters = item.characters.replace(`{${btnName}}`, JSONobj[newItem][btnName].toString());
newItem = ++newItem;
});
}
if (item.children) {
loopSelected(item.children);
}
});
};
loopSelected(selectedLayers);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment