UNPKG

qb-utf8-from-str-tiny

Version:

tiny browser script for converting string to array of UTF-8 characters. not efficient for large files.

12 lines (11 loc) 264 B
module.exports = function (s) { for (var i = 0, enc = encodeURIComponent(s), a = []; i < enc.length;) { if (enc[i] === '%') { a.push(parseInt(enc.substr(i + 1, 2), 16)) i += 3 } else { a.push(enc.charCodeAt(i++)) } } return a }