utf8safe-uhex

Hex-escape (\uHHHH) those UCS-2 characters that cannot be encoded as UTF-8, and the replacement character, to help you distinguish verbatim occurrences from freshly discarded data.

Usage no npm install needed!

<script type="module">
  import utf8safeUhex from 'https://cdn.skypack.dev/utf8safe-uhex';
</script>

README



utf8safe-uhex

Hex-escape (\uHHHH) those UCS-2 characters that cannot be encoded as UTF-8, and the replacement character, to help you distinguish verbatim occurrences from freshly discarded data.

Usage

trom test.js:

  var utf8safe_uhex = require('utf8safe-uhex'),
    orig = "\uD83D\uDC15\u2771" + "\uDC15" + "\uD83D" + "\u2770\uD83D\uDC04",
    expect = noSpace("🐕  ❱  \\u  DC15  \\u  D83D  ❰  🐄"),
    actual = utf8safe_uhex(orig);
  expectStrictEqual(actual, expect);

License

ISC