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
unspin = (text) -> | |
# spintax regex: "{" + anything not "{" or "}" + "}" | |
findSpintax = -> text.match /{[^{}]+?}/g | |
# while we find spintax keep unspinning it | |
while findSpintax text | |
# find spintax chunks and work on the first one | |
spintax = (findSpintax text)[0] | |
# put the spintax options in an array | |
options = spintax.split '|' | |
# choose a random index based on the array length |