Skip to content

Instantly share code, notes, and snippets.



Last active Aug 8, 2020
What would you like to do?
Swap quotes to handle quotation of titles already containing quotes.
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
You can’t perform that action at this time.