Skip to content

Instantly share code, notes, and snippets.

@preco21
Last active July 4, 2016 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save preco21/a755edb8b43a140ce5e2 to your computer and use it in GitHub Desktop.
Save preco21/a755edb8b43a140ce5e2 to your computer and use it in GitHub Desktop.
Encode a non-bmp string into HTML entities with ES2015 powered
// encode
'foo © bar ≠ baz 𝌆 qux'.replace(/[\u{00A0}-\u{10FFFF}<>\&]/gmiu, (char) => `&#x${char.codePointAt(0).toString(16)};`);