UNPKG

tiny-eucjp-encoder

Version:

Tiny EUC-JP(CP51932) encoder - Only 679 bytes

1 lines 679 B
((c,d)=>{"object"==typeof module?module.exports=d():"function"==typeof define&&define.amd?define([],d):c.eucjp=d();"object"==typeof exports&&(exports.default=exports.eucjp=d())})("undefined"!=typeof self?self:this,()=>{let c;const d=new TextDecoder("euc-jp");return function(h){if(void 0===c){c=new Uint16Array(65536);var e=new Uint8Array(2);for(var a=0;127>=a;a++)c[a]=a;for(const [g,f]of[[142,142],[161,252]])for(a=g;a<=f;a++){e[0]=a;for(var b=161;254>=b;b++){e[1]=b;try{c[d.decode(e).charCodeAt(0)]=a<<8|b}catch(k){}}}}e=h.length;a=new Uint8Array(2*e);b=0;for(let g=0;g<e;g++){const f=c[h.charCodeAt(g)]||63;255<f?(a[b++]=f>>8,a[b++]=f&255):a[b++]=f}return a.subarray(0,b)}});