Last active
March 22, 2019 14:47
-
-
Save chriscorwin/de14c1f7ec647d970b832f28e95d60f8 to your computer and use it in GitHub Desktop.
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 escapeRegExp(str) { | |
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); | |
} | |
function replaceAll(str, find, replace) { | |
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace); | |
} | |
let filenameRaw = '0052___ID=message-is-being-dragged___DATA=use-slide-transition__slide-transition_auto-advance__slide-transition-timing--fast___NOTES=Do-not-forget-to-move-your-mouse__The-next-five-steps-auto-advance~~so~~no-need-to-click-for-a-while.svg' | |
// GET THESE HARD-TO-ESCAPE THINGS OUT OF THE WAY FIRST. | |
filenameRaw = replaceAll(filenameRaw, '~_~', '::::UNDERSCORE::::'); | |
filenameRaw = replaceAll(filenameRaw, '~-~', '::::DASH::::'); | |
filenameRaw = replaceAll(filenameRaw, '~.~', '::::PERIOD::::'); | |
filenameRaw = replaceAll(filenameRaw, '~per-cent~', '::::PERCENT::::'); | |
// CONJUNCTIONS | |
filenameRaw = replaceAll(filenameRaw, '_and_', ' and '); | |
filenameRaw = replaceAll(filenameRaw, '_or_', ' or '); | |
// WILD AND STRANGE | |
filenameRaw = replaceAll(filenameRaw, '__--__', '. '); | |
// UNDERSCORES | |
filenameRaw = replaceAll(filenameRaw, '___', ' / '); | |
filenameRaw = replaceAll(filenameRaw, '__', ', '); | |
filenameRaw = replaceAll(filenameRaw, '_', ' '); | |
// DASHES | |
filenameRaw = replaceAll(filenameRaw, '---', '. '); | |
filenameRaw = replaceAll(filenameRaw, '--', ': '); | |
filenameRaw = replaceAll(filenameRaw, '-', ' '); | |
filenameRaw = replaceAll(filenameRaw, '=', ': '); | |
filenameRaw = replaceAll(filenameRaw, '~~', ', '); | |
filenameRaw = replaceAll(filenameRaw, '~', '’'); | |
filenameRaw = replaceAll(filenameRaw, '%3f', '?'); | |
filenameRaw = replaceAll(filenameRaw, '::::UNDERSCORE::::', '_'); | |
filenameRaw = replaceAll(filenameRaw, '::::DASH::::', '-'); | |
filenameRaw = replaceAll(filenameRaw, '::::PERIOD::::', '. '); | |
filenameRaw = replaceAll(filenameRaw, '::::PERCENT::::', '%'); | |
console.group(`filenameRaw:`); | |
console.log(filenameRaw); | |
console.groupEnd(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs like:
0052 / ID: message is being dragged / DATA: use slide transition, slide transition auto advance, slide transition timing: fast / NOTES: Do not forget to move your mouse, The next five steps auto advance, so, no need to click for a while.svg