@gjsify/string_decoder 0.4.20 → 0.4.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/index.js +1 -1
- package/package.json +5 -5
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{base64Encode as e,checkEncoding as t,normalizeEncoding as n}from"@gjsify/
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{base64Encode as e,checkEncoding as t,normalizeEncoding as n}from"@gjsify/buffer";function normalizeAndValidateEncoding(e){return e&&t(e),n(e)}function utf8DecodeMaximalSubpart(e,t,n){let r=``,i=t;for(;i<n;){let t=e[i];if(t<=127){r+=String.fromCharCode(t),i++;continue}if(t>=194&&t<=223){i+1<n&&e[i+1]>=128&&e[i+1]<=191?(r+=String.fromCharCode((t&31)<<6|e[i+1]&63),i+=2):(r+=`�`,i++);continue}if(t>=224&&t<=239){let a,o;if(t===224?(a=160,o=191):t===237?(a=128,o=159):(a=128,o=191),i+1>=n){r+=`�`,i++;continue}let s=e[i+1];if(s<a||s>o){r+=`�`,i++;continue}if(i+2>=n){r+=`�`,i+=2;continue}let c=e[i+2];if(c<128||c>191){r+=`�`,i+=2;continue}let l=(t&15)<<12|(s&63)<<6|c&63;r+=String.fromCharCode(l),i+=3;continue}if(t>=240&&t<=244){let a,o;if(t===240?(a=144,o=191):t===244?(a=128,o=143):(a=128,o=191),i+1>=n){r+=`�`,i++;continue}let s=e[i+1];if(s<a||s>o){r+=`�`,i++;continue}if(i+2>=n){r+=`�`,i+=2;continue}let c=e[i+2];if(c<128||c>191){r+=`�`,i+=2;continue}if(i+3>=n){r+=`�`,i+=3;continue}let l=e[i+3];if(l<128||l>191){r+=`�`,i+=3;continue}let u=(t&7)<<18|(s&63)<<12|(c&63)<<6|l&63;r+=String.fromCharCode(55296+(u-65536>>10),56320+(u-65536&1023)),i+=4;continue}r+=`�`,i++}return r}function utf8CharLength(e){return e&128?e>=194&&e<=223?2:e>=224&&e<=239?3:e>=240&&e<=244?4:0:1}function isValidContinuation(e,t,n,r){if(n===1){if(t===3)return e===224?r>=160&&r<=191:e===237?r>=128&&r<=159:r>=128&&r<=191;if(t===4)return e===240?r>=144&&r<=191:e===244?r>=128&&r<=143:r>=128&&r<=191}return r>=128&&r<=191}const r=function StringDecoder(e){this.encoding=normalizeAndValidateEncoding(e),this._lastNeed=0,this._lastTotal=0,this._lastLeadByte=0,this.encoding===`utf8`||this.encoding===`utf16le`?this._lastChar=new Uint8Array(4):this.encoding===`base64`?this._lastChar=new Uint8Array(3):this._lastChar=new Uint8Array};r.prototype.write=function write(e){if(e.length===0)return``;switch(this.encoding){case`utf8`:return writeUtf8(this,e);case`utf16le`:return writeUtf16le(this,e);case`base64`:return writeBase64(this,e);case`ascii`:return decodeAscii(e);case`latin1`:return decodeLatin1(e);case`hex`:return decodeHex(e);default:return decodeAscii(e)}},r.prototype.end=function end(t){let n=``;if(t&&t.length>0&&(n=this.write(t)),this.encoding===`utf8`&&this._lastNeed>0)n+=`�`,this._lastNeed=0,this._lastTotal=0;else if(this.encoding===`utf16le`&&this._lastNeed>0){let e=this._lastTotal-this._lastNeed;for(let t=0;t+1<e;t+=2)n+=String.fromCharCode(this._lastChar[t]|this._lastChar[t+1]<<8);this._lastNeed=0,this._lastTotal=0}else if(this.encoding===`base64`&&this._lastNeed>0){let t=this._lastChar.subarray(0,this._lastTotal-this._lastNeed);n+=e(t),this._lastNeed=0,this._lastTotal=0}return n};function writeUtf8(e,t){let n=0,r=``;if(e._lastNeed>0){for(;n<t.length&&e._lastNeed>0;){let i=t[n],a=e._lastTotal-e._lastNeed;if(isValidContinuation(e._lastLeadByte,e._lastTotal,a,i))e._lastChar[a]=i,e._lastNeed--,n++;else{r+=`�`,e._lastNeed=0,e._lastTotal=0,e._lastLeadByte=0;break}}if(e._lastNeed===0&&e._lastTotal>0&&(r+=utf8DecodeMaximalSubpart(e._lastChar,0,e._lastTotal),e._lastTotal=0,e._lastLeadByte=0),e._lastNeed>0)return r}let i=t.length;for(let r=0;r<Math.min(4,t.length-n);r++){let a=t.length-1-r;if(a<n)break;let o=t[a];if((o&192)!=128){let n=utf8CharLength(o);if(n>0&&o>=128){let r=t.length-a;if(r<n){let s=!0;for(let e=1;e<r;e++)if(!isValidContinuation(o,n,e,t[a+e])){s=!1;break}if(s){i=a;for(let n=0;n<r;n++)e._lastChar[n]=t[a+n];e._lastNeed=n-r,e._lastTotal=n,e._lastLeadByte=o}}}break}}return i>n&&(r+=utf8DecodeMaximalSubpart(t,n,i)),r}function writeUtf16le(e,t){let n=``,r=0;if(e._lastNeed>0){let i=e._lastTotal-e._lastNeed,a=Math.min(e._lastNeed,t.length);for(let n=0;n<a;n++)e._lastChar[i+n]=t[n];if(e._lastNeed-=a,r=a,e._lastNeed>0)return``;let o=e._lastTotal,s=0;for(;s+1<o;){let i=e._lastChar[s]|e._lastChar[s+1]<<8;if(s+=2,i>=55296&&i<=56319){if(s+1<o){let t=e._lastChar[s]|e._lastChar[s+1]<<8;if(t>=56320&&t<=57343){n+=String.fromCharCode(i,t),s+=2;continue}}if(r+1<t.length){let e=t[r]|t[r+1]<<8;if(e>=56320&&e<=57343){n+=String.fromCharCode(i,e),r+=2;continue}}else if(r>=t.length)return e._lastChar[0]=e._lastChar[s-2],e._lastChar[1]=e._lastChar[s-1],e._lastNeed=2,e._lastTotal=4,n}n+=String.fromCharCode(i)}e._lastTotal=0}for(;r+1<t.length;){let i=t[r]|t[r+1]<<8;if(r+=2,i>=55296&&i<=56319)if(r+1<t.length){let e=t[r]|t[r+1]<<8;if(e>=56320&&e<=57343){n+=String.fromCharCode(i,e),r+=2;continue}}else if(r<t.length)return n+=String.fromCharCode(i),e._lastChar[0]=t[r],e._lastNeed=1,e._lastTotal=2,n;else return e._lastChar[0]=t[r-2],e._lastChar[1]=t[r-1],e._lastNeed=2,e._lastTotal=4,n;n+=String.fromCharCode(i)}return r<t.length&&(e._lastChar[0]=t[r],e._lastNeed=1,e._lastTotal=2),n}function writeBase64(t,n){let r=0;if(t._lastNeed>0){let e=Math.min(t._lastNeed,n.length);for(let r=0;r<e;r++)t._lastChar[t._lastTotal-t._lastNeed+r]=n[r],t._lastNeed--;if(r=e,t._lastNeed>0)return``}let i=n.length-r,a=i-i%3,o=``;t._lastTotal>0&&t._lastNeed===0&&(o+=e(t._lastChar.subarray(0,t._lastTotal)),t._lastTotal=0),a>0&&(o+=e(n.subarray(r,r+a)));let s=i-a;if(s>0){for(let e=0;e<s;e++)t._lastChar[e]=n[r+a+e];t._lastNeed=3-s,t._lastTotal=3}return o}function decodeAscii(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]&127);return t}function decodeLatin1(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return t}function decodeHex(e){let t=``;for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,`0`);return t}var i={StringDecoder:r};export{r as StringDecoder,i as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/string_decoder",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.22",
|
|
4
4
|
"description": "Node.js string_decoder module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"string_decoder"
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@gjsify/cli": "^0.4.
|
|
37
|
-
"@gjsify/unit": "^0.4.
|
|
38
|
-
"@types/node": "^25.
|
|
36
|
+
"@gjsify/cli": "^0.4.22",
|
|
37
|
+
"@gjsify/unit": "^0.4.22",
|
|
38
|
+
"@types/node": "^25.9.1",
|
|
39
39
|
"typescript": "^6.0.3"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@gjsify/
|
|
42
|
+
"@gjsify/buffer": "^0.4.22"
|
|
43
43
|
}
|
|
44
44
|
}
|