Skip to content

Instantly share code, notes, and snippets.

@svschannak
Created October 25, 2018 15:47
Show Gist options
  • Save svschannak/68f2465715660e137893de0a8c880bf2 to your computer and use it in GitHub Desktop.
Save svschannak/68f2465715660e137893de0a8c880bf2 to your computer and use it in GitHub Desktop.
XD text randomizer
function randomizeText(selection, documentRoot) {
documentRoot.children.forEach(node => {
// [1]
if (node instanceof Artboard) {
// [2]
let artboard = node;
let rectangles = artboard.children.filter(artboardChild => {
// [3]
return artboardChild instanceof Text;
});
rectangles.forEach(rectangle => {
// [4]
// const strLength = rectangle.text.length;
// const random = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, strLength);
// console.log(random);
const newText = rectangle.text
.split("")
.map(letter => {
if (!isLetter(letter)) {
return letter;
}
let newLetter = Math.random()
.toString(36)
.replace(/[^a-z]+/g, "")
.substr(0, 1);
if (letter === letter.toUpperCase()) {
newLetter = newLetter.toUpperCase();
}
return newLetter;
})
.join("");
console.log(newText);
rectangle.text = newText;
// rectangle.text = random;
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment