Last active
August 8, 2020 02:55
-
-
Save qgustavor/9c373ca8719eaacbbe912793f08fdb2d to your computer and use it in GitHub Desktop.
Swap quotes to handle quotation of titles already containing quotes.
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 swapQuotes (input) { | |
const quotesStr = `'"“‘”’` | |
return input.replace(/['"“”‘’]/g, e => quotesStr.charAt(quotesStr.indexOf(e) ^ 1)) | |
} | |
// Example usage: | |
// const episodeName = 'Marge Simpson in: "Screaming Yellow Honkers"' | |
// <div>This user watched "{{ swapQuotes(episodeName) }}" in...</div> | |
// Should return <div>This user watched "Marge Simpson in: 'Screaming Yellow Honkers'" in...</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment