Created
October 25, 2018 15:47
-
-
Save svschannak/68f2465715660e137893de0a8c880bf2 to your computer and use it in GitHub Desktop.
XD text randomizer
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
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