Skip to content

Schibum/utf8.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

utf8.js

UTF8 byte sequence encoding decoding of strings without a encodeURIComponent hack.

Usage

Example:

// From string to bytes:
var bytes = utf8.stringToUTF8Bytes('hello utf8 € $');
// bytes = [104,101,108,108,111,32,117,116,102,56,32,226,130,172,32,36];
// From bytes to string:
var str = utf8.UTF8BytesToString(bytes)
// str = 'hello utf8 € $'

API

/**
 * Convert string to UTF8 byte sequence.
 * @param {string} str javascript string (unicode).
 * @return {Array.<number>} byte sequence.
 */
function stringToUTF8Bytes (str) {}

/**
 * Convert UTF8 byte sequence to string.
 * @param {Array.<number>} bytes UTF8 byte sequence.
 * @return {?string} result string or null on error (invalid input).
 */
function UTF8BytesToString(bytes) {}

It supports require.js (see example/example.html), but also works without it. If require.js is not available, the API is exported to window.utf8.

About

Convert strings from and to UTF8 byte sequences.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published