utf8.js 368 B

123456789101112
  1. //try { module.exports = {dec:utf8_dec, enc:utf8_enc}; } catch (e) { console.log(e); }
  2. // UTF-8 Support
  3. function utf8_dec(ab){ return (new TextDecoder()).decode(ab); }
  4. function utf8_enc(ab){ return (new TextEncoder("utf-8")).encode(ab); }
  5. function utf8_arr(ab){
  6. if(!(ab instanceof ArrayBuffer)) ab = new Uint8Array(utf8_enc(ab)).buffer;
  7. return utf8_dec(ab);
  8. }