fast-text-encoding
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "fast-text-encoding", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Fast polyfill for TextEncoder and TextDecoder, only supports utf-8", | ||
@@ -9,11 +9,9 @@ "main": "text.min.js", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"google-closure-compiler": "^20200406.0.0", | ||
"mocha": "^7.1.0" | ||
}, | ||
"scripts": { | ||
"compile": "./compile.sh", | ||
"test": "mocha" | ||
"test": "node --test ./test.mjs" | ||
}, | ||
"devDependencies": { | ||
"google-closure-compiler": "^20220601.0.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
[![Build](https://api.travis-ci.org/samthor/fast-text-encoding.svg?branch=master)](https://travis-ci.org/samthor/fast-text-encoding) | ||
[![Test](https://github.com/samthor/fast-text-encoding/actions/workflows/node.js.yml/badge.svg)](https://github.com/samthor/fast-text-encoding/actions/workflows/node.js.yml) | ||
@@ -3,0 +3,0 @@ This is a fast polyfill for [`TextEncoder`][1] and [`TextDecoder`][2], which let you encode and decode JavaScript strings into UTF-8 bytes. |
10
text.js
@@ -146,4 +146,3 @@ /* | ||
function decodeSyncXHR(bytes) { | ||
const b = new Blob([bytes], {type: 'text/plain;charset=UTF-8'}); | ||
const u = URL.createObjectURL(b); | ||
let u; | ||
@@ -153,2 +152,5 @@ // This hack will fail in non-Edgium Edge because sync XHRs are disabled (and | ||
try { | ||
const b = new Blob([bytes], {type: 'text/plain;charset=UTF-8'}); | ||
u = URL.createObjectURL(b); | ||
const x = new XMLHttpRequest(); | ||
@@ -161,3 +163,5 @@ x.open('GET', u, false); | ||
} finally { | ||
URL.revokeObjectURL(u); | ||
if (u) { | ||
URL.revokeObjectURL(u); | ||
} | ||
} | ||
@@ -164,0 +168,0 @@ } |
@@ -1,3 +0,3 @@ | ||
(function(l){function m(){}function k(a,c){a=void 0===a?"utf-8":a;c=void 0===c?{fatal:!1}:c;if(-1===r.indexOf(a.toLowerCase()))throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('"+a+"') is invalid.");if(c.fatal)throw Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.");}function t(a){return Buffer.from(a.buffer,a.byteOffset,a.byteLength).toString("utf-8")}function u(a){var c=URL.createObjectURL(new Blob([a],{type:"text/plain;charset=UTF-8"})); | ||
try{var f=new XMLHttpRequest;f.open("GET",c,!1);f.send();return f.responseText}catch(e){return q(a)}finally{URL.revokeObjectURL(c)}}function q(a){for(var c=0,f=Math.min(65536,a.length+1),e=new Uint16Array(f),h=[],d=0;;){var b=c<a.length;if(!b||d>=f-1){h.push(String.fromCharCode.apply(null,e.subarray(0,d)));if(!b)return h.join("");a=a.subarray(c);d=c=0}b=a[c++];if(0===(b&128))e[d++]=b;else if(192===(b&224)){var g=a[c++]&63;e[d++]=(b&31)<<6|g}else if(224===(b&240)){g=a[c++]&63;var n=a[c++]&63;e[d++]= | ||
(function(l){function m(){}function k(a,c){a=void 0===a?"utf-8":a;c=void 0===c?{fatal:!1}:c;if(-1===r.indexOf(a.toLowerCase()))throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('"+a+"') is invalid.");if(c.fatal)throw Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.");}function t(a){return Buffer.from(a.buffer,a.byteOffset,a.byteLength).toString("utf-8")}function u(a){try{var c=URL.createObjectURL(new Blob([a],{type:"text/plain;charset=UTF-8"})); | ||
var f=new XMLHttpRequest;f.open("GET",c,!1);f.send();return f.responseText}catch(e){return q(a)}finally{c&&URL.revokeObjectURL(c)}}function q(a){for(var c=0,f=Math.min(65536,a.length+1),e=new Uint16Array(f),h=[],d=0;;){var b=c<a.length;if(!b||d>=f-1){h.push(String.fromCharCode.apply(null,e.subarray(0,d)));if(!b)return h.join("");a=a.subarray(c);d=c=0}b=a[c++];if(0===(b&128))e[d++]=b;else if(192===(b&224)){var g=a[c++]&63;e[d++]=(b&31)<<6|g}else if(224===(b&240)){g=a[c++]&63;var n=a[c++]&63;e[d++]= | ||
(b&31)<<12|g<<6|n}else if(240===(b&248)){g=a[c++]&63;n=a[c++]&63;var v=a[c++]&63;b=(b&7)<<18|g<<12|n<<6|v;65535<b&&(b-=65536,e[d++]=b>>>10&1023|55296,b=56320|b&1023);e[d++]=b}}}if(l.TextEncoder&&l.TextDecoder)return!1;var r=["utf-8","utf8","unicode-1-1-utf-8"];Object.defineProperty(m.prototype,"encoding",{value:"utf-8"});m.prototype.encode=function(a,c){c=void 0===c?{stream:!1}:c;if(c.stream)throw Error("Failed to encode: the 'stream' option is unsupported.");c=0;for(var f=a.length,e=0,h=Math.max(32, | ||
@@ -4,0 +4,0 @@ f+(f>>>1)+7),d=new Uint8Array(h>>>3<<3);c<f;){var b=a.charCodeAt(c++);if(55296<=b&&56319>=b){if(c<f){var g=a.charCodeAt(c);56320===(g&64512)&&(++c,b=((b&1023)<<10)+(g&1023)+65536)}if(55296<=b&&56319>=b)continue}e+4>d.length&&(h+=8,h*=1+c/a.length*2,h=h>>>3<<3,g=new Uint8Array(h),g.set(d),d=g);if(0===(b&4294967168))d[e++]=b;else{if(0===(b&4294965248))d[e++]=b>>>6&31|192;else if(0===(b&4294901760))d[e++]=b>>>12&15|224,d[e++]=b>>>6&63|128;else if(0===(b&4292870144))d[e++]=b>>>18&7|240,d[e++]=b>>>12& |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33768
1
274
7