Skip to content

Instantly share code, notes, and snippets.

@breenie
Created July 19, 2022 10:27
Show Gist options
  • Save breenie/1cdfff1a3a2f4419cc89c14c0cc28142 to your computer and use it in GitHub Desktop.
Save breenie/1cdfff1a3a2f4419cc89c14c0cc28142 to your computer and use it in GitHub Desktop.
Replace unicode characters with their code point
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