qb-utf8-to-str-tiny
v1.2.2
Published
tiny browser script for converting array of UTF-8 characters to string. not efficient for large files.
Downloads
300
Maintainers
Readme
qb-utf8-to-str-tiny
Tiny script for converting utf-8 to string based upon decodeURIComponent().
Runs in nodejs and in browser. Not efficient for large strings.
module.exports = function utf8_to_str (src, off, lim) {
lim = lim == null ? src.length : lim
for (var i = off || 0, s = ''; i < lim; i++) {
var h = src[i].toString(16)
if (h.length < 2) h = '0' + h
s += '%' + h
}
return decodeURIComponent(s)
}
That's it. That's the code.
Complies with the 100% test coverage and minimum dependency requirements of qb-standard .
Install
npm install qb-utf8-to-str-tiny
Example
npm install qb-utf8-to-str-tiny
node
> var utf2str = require('qb-utf8-to-str-tiny')
> utf2str([ 103,195,174,100,100,195,177,117,112,240,144,130,131,33 ])
'gîddñup𐂃!'