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