You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
wtf-8 is a well-tested WTF-8 encoder/decoder written in JavaScript. WTF-8 is a superset of UTF-8: it can encode/decode any given Unicode code point, including those of (unpaired) surrogates. Here’s an online demo.
Feel free to fork if you see possible improvements!
Encodes any given JavaScript string (string) as WTF-8, and returns the WTF-8-encoded version of the string.
// U+00A9 COPYRIGHT SIGN; see https://codepoints.net/U+00A9wtf8.encode('\xA9');// → '\xC2\xA9'// U+10001 LINEAR B SYLLABLE B038 E; see https://codepoints.net/U+10001wtf8.encode('\uD800\uDC01');// → '\xF0\x90\x80\x81'
wtf8.decode(byteString)
Decodes any given WTF-8-encoded string (byteString) as WTF-8, and returns the WTF-8-decoded version of the string. It throws an error when malformed WTF-8 is detected.
wtf8.decode('\xC2\xA9');// → '\xA9'wtf8.decode('\xF0\x90\x80\x81');// → '\uD800\uDC01'// → U+10001 LINEAR B SYLLABLE B038 E
wtf8.version
A string representing the semantic version number.
Support
wtf-8 has been tested in (at least) the latest versions of Chrome, Opera, Firefox, Safari, IE, Node.js, Narwhal, RingoJS, PhantomJS, and Rhino.