forked from samthor/fast-text-encoding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.min.js
3 lines (3 loc) · 2.89 KB
/
text.min.js
1
2
3
(function(scope) {'use strict';
function w(r,f,o){var e;if(r instanceof Buffer)e=r;else try{e=Buffer.from(r.buffer,r.byteOffset,r.byteLength)}catch(i){if(o)throw i;return""}return e.toString(f)}var B=function(r){return Buffer.from(r)};function h(r,f,o){for(var e=0,i=Math.min(256*256,r.length+1),t=new Uint16Array(i),n=[],a=0;;){var p=e<r.length;if(!p||a>=i-1){var y=t.subarray(0,a),R=y;if(n.push(String.fromCharCode.apply(null,R)),!p)return n.join("");r=r.subarray(e),e=0,a=0}var c=r[e++];if((c&128)===0)t[a++]=c;else if((c&224)===192){var s=r[e++]&63;t[a++]=(c&31)<<6|s}else if((c&240)===224){var s=r[e++]&63,l=r[e++]&63;t[a++]=(c&31)<<12|s<<6|l}else if((c&248)===240){var s=r[e++]&63,l=r[e++]&63,A=r[e++]&63,x=(c&7)<<18|s<<12|l<<6|A;x>65535&&(x-=65536,t[a++]=x>>>10&1023|55296,x=56320|x&1023),t[a++]=x}else if(o)throw new Error("invalid input")}}function F(r){for(var f=0,o=r.length,e=0,i=Math.max(32,o+(o>>>1)+7),t=new Uint8Array(i>>>3<<3);f<o;){var n=r.charCodeAt(f++);if(n>=55296&&n<=56319){if(f<o){var a=r.charCodeAt(f);(a&64512)===56320&&(++f,n=((n&1023)<<10)+(a&1023)+65536)}if(n>=55296&&n<=56319)continue}if(e+4>t.length){i+=8,i*=1+f/r.length*2,i=i>>>3<<3;var p=new Uint8Array(i);p.set(t),t=p}if((n&4294967168)===0){t[e++]=n;continue}else if((n&4294965248)===0)t[e++]=n>>>6&31|192;else if((n&4294901760)===0)t[e++]=n>>>12&15|224,t[e++]=n>>>6&63|128;else if((n&4292870144)===0)t[e++]=n>>>18&7|240,t[e++]=n>>>12&63|128,t[e++]=n>>>6&63|128;else continue;t[e++]=n&63|128}return t.slice?t.slice(0,e):t.subarray(0,e)}var u="Failed to ",m=function(r,f,o){if(r)throw new Error("".concat(u).concat(f,": the '").concat(o,"' option is unsupported."))};var d=typeof Buffer=="function"&&Buffer.from;var E=d?B:F;function v(){this.encoding="utf-8"}v.prototype.encode=function(r,f){return m(f&&f.stream,"encode","stream"),E(r)};function U(r){var f;try{var o=new Blob([r],{type:"text/plain;charset=UTF-8"});f=URL.createObjectURL(o);var e=new XMLHttpRequest;return e.open("GET",f,!1),e.send(),e.responseText}finally{f&&URL.revokeObjectURL(f)}}var O=!d&&typeof Blob=="function"&&typeof URL=="function"&&typeof URL.createObjectURL=="function",S=["utf-8","utf8","unicode-1-1-utf-8"],T=h;d?T=w:O&&(T=function(r,f,o){try{return U(r)}catch(e){return h(r,f,o)}});var k="construct 'TextDecoder'",$="".concat(u," ").concat(k,": the ");function g(r,f){r=r||"utf-8";var o;if(d?o=Buffer.isEncoding(r):o=S.indexOf(r.toLowerCase())!==-1,!o)throw new RangeError("".concat($," encoding label provided ('").concat(r,"') is invalid."));this.encoding=r,this.fatal=!!(f&&f.fatal),this.ignoreBOM=!1}g.prototype.decode=function(r,f){m(f&&f.stream,"decode","stream");var o;return r instanceof Uint8Array?o=r:r.buffer instanceof ArrayBuffer?o=new Uint8Array(r.buffer):o=new Uint8Array(r),T(o,this.encoding,this.fatal)};scope.TextEncoder=scope.TextEncoder||v;scope.TextDecoder=scope.TextDecoder||g;
}(typeof window !== 'undefined' ? window : (typeof global !== 'undefined' ? global : this)));