Created
July 19, 2022 10:27
-
-
Save breenie/1cdfff1a3a2f4419cc89c14c0cc28142 to your computer and use it in GitHub Desktop.
Replace unicode characters with their code point
This file contains hidden or 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
const sane = JSON.stringify("Emdashses should be banned. –") | |
.replace( | |
/[^\x20-\x7F]/g, | |
x => "\\u" + ("000" + x.codePointAt(0).toString(16)).slice(-4) | |
); | |
console.log(sane); | |
// Emdashses should be banned. \u2013 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment