tiny-sjis-encoder
Version:
Tiny Shift-JIS(MS932) encoder - Only 806 bytes
1 lines • 806 B
JavaScript
((d,e)=>{"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):d.sjis=e();"object"==typeof exports&&(exports.default=exports.sjis=e())})("undefined"!=typeof self?self:this,()=>{let d;const e=new TextDecoder("ms932");return function(h){if(void 0===d){d=new Uint16Array(65536);var b=new Uint8Array(1),g=new Uint8Array(2);for(const [f,c]of[[0,127],[161,223]])for(var a=f;a<=c;a++)try{b[0]=a,d[e.decode(b).charCodeAt(0)]=a}catch(k){}for(const [f,c]of[[129,159],[224,252]])for(b=f;b<=c;b++){g[0]=b;for(const [k,l]of[[64,126],[128,252]])for(a=k;a<=l;a++){g[1]=a;try{d[e.decode(g).charCodeAt(0)]=b<<8|a}catch(m){}}}}g=h.length;b=new Uint8Array(2*g);a=0;for(let f=0;f<g;f++){const c=d[h.charCodeAt(f)]||63;255<c?(b[a++]=c>>8,b[a++]=c&255):b[a++]=c}return b.subarray(0,a)}});