strc 2.0.0-test → 2.0.1

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.
Files changed (7) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +123 -124
  3. package/index.d.ts +121 -121
  4. package/index.js +1627 -1620
  5. package/index.min.js +40 -38
  6. package/package.json +2 -2
  7. package/test/index.js +122 -97
package/index.min.js CHANGED
@@ -1,38 +1,40 @@
1
- /*
2
-
3
- MIT License
4
-
5
- Copyright (c) 2025-2026 JustDeveloper <https://justdeveloper.is-a.dev/>
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in all
15
- copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- SOFTWARE.
24
-
25
- */
26
-
27
- /*
28
- _______________
29
- __ / / __/ __/ ___/
30
- / // /\ \_\ \/ /__
31
- \___/___/___/\___/
32
-
33
- JavaScript String Compressor
34
- https://jssc.js.org/
35
-
36
- */
37
-
38
- ((e,r)=>{"function"==typeof define&&define.amd?define(["justc"],r):"object"==typeof module&&module.exports?module.exports=r(require("justc")):(e.JSSC=r(e.JUSTC),Object.freeze(e.JSSC))})("undefined"!=typeof self?self:this,function(M){if(65536===String.fromCharCode(65536).charCodeAt(0)||256!==String.fromCharCode(256).charCodeAt(0))throw new Error("Supported UTF-16 only!");function _(e){let r=[],t=0,n=0,o=1/0;return String(e).split("").forEach(e=>{e=e.charCodeAt();r.push(e),t=Math.max(t,e.toString().length),n=Math.max(n,e),o=Math.min(o,e.toString().length)}),{max:t,output:r,maxCharCode:n,min:o}}function b(e){return String.fromCharCode(e+32)}function E(e){return e%65535===e}function U(r,t){var n=[];for(let e=0;e<r.length;e+=t)n.push(r.slice(e,e+t));return n}function I(r,t){var n=[];for(let e=0;e<r.length;e+=t)n.push(r.slice(e,e+t));return n}function x(e,r){return e.toString(2).padStart(r,"0")}function q(e){return parseInt(e,2)}function o(){let r={};function t(e){r[e]=String.fromCharCode(e)}for(let e=0;e<65;e++)t(e);for(let e=91;e<97;e++)t(e);for(let e=123;e<128;e++)t(e);return r}function n(){var r={};for(let e=0;e<128;e++)r[e]=String.fromCharCode(e);return r}let H={};function k(e,r=!1,t=!1,n=!1,o=-1,a=0,i=!1,f=-1){var s,c,l;return r?(s=(r=x(e,16)).slice(8,11).split(""),c=q(r.slice(11)),l=q(r.slice(5,8)),{code:c,repeatBefore:"1"===s[0],repeatAfter:"1"===s[1],beginId:"1"===s[2]?l:-1,code2:q(r.slice(0,4)),sequences:"1"===r.slice(4,5),code3:"0"===s[2]?l:-1,bin:r}):q(x(a,4)+(i?"1":"0")+x(0<=o?o:f<0?0:f,3)+(t?"1":"0")+(n?"1":"0")+(0<=o?"1":"0")+x(e,5))}H._char=e=>String.fromCharCode(e),H._IDs={BASE:0,RU:1,ENRU:2,ENKK:3,HI:4,ENHI:5,BN:6,ENBN:7,HIBN:8,JA:9,Telu:10,MR:11,B:12,E:13,AR:14},H.BASE=function(){var e,r=o(),t=[215,247,8722,11800,174,169,171,10003,182,9834,183,10005,177,181,8960,8211,8212,8228,8229,8230,8240,8241,8249,8250,8252,8253,8263,8264,8267,8270,8274,8451,8457,8470,8471,8482,402,1423,1547,65020,2547,2553,2555,2801,3065,3647,6107,8499,2546,8304,185,178,179,8585,8319,8305,8709,8730,8734];for(let e=161;e<168;e++)t.push(e);for(let e=187;e<192;e++)t.push(e);for(let e=8308;e<8317;e++)t.push(e);for(let e=8528;e<8576;e++)t.push(e);for(let e=8352;e<8385;e++)t.push(e);for(let e=8320;e<8333;e++)t.push(e);for(let e=8712;e<8718;e++)t.push(e);let n=65;for(e of t)r[n++]=H._char(e),91===n?n=97:123===n&&(n=128);return r},H._BASE=[167,8722,8451,169,8211,215,247,8457,174,8470,8482,8471,8249,8250,171,187,8242,8245,8216,8217,8218,8219,8243,8246,8220,8221,8222,8223,8226,182,8267,8270,8240,8241,9834,183,8228,8229,8230,161,191,8252,8264],H._MATH=[8544,8547,8550,8553,8556,8572,8545,8548,8551,8554,8557,8573,8546,8549,8552,8555,8558,8574,8560,8563,8566,8569,8559,8575,8561,8564,8567,8570,8562,8565,8568,8571,8712,8715,8713,8716,8730,8721,8734,8804,8805],H._CURR=[165,3647,8363,8361,1423,8364,8377,8362,8378,8353,8358,163,8381,8354,8369,2547,8370,8366,8376,8382,8357,6107,8360,8372,8373,8365,1547,2801,162,65020,8355,8383,8380,3065,164,8384,8379,402,8359,2546,8371,8367,8356,8375,2553,8368,8352,8499,8374,2555],H._RU=function(e){var r=e();let t=0;for(let e=1040;e<1104;e++){var n=e-912;r[n]=H._char(e),t=Math.max(t,n)}return r[t+1]=H._char(1025),r[t+2]=H._char(1105),r},H.RU=function(){var e,r=H._RU(o);let t=65;for(e of H._BASE.concat(H._MATH,[105,239,1028,1030,1031,1108,1110,1111,1118,1038,1241,1181,1171,1199,1201,1179,1257,1211,1240,1186,1170,1198,1200,1178,1256,1210,8381,8364,165,8376,8372]))r[t++]=H._char(e),91===t?t=97:123===t&&(t=193);return r[110]="i",r[111]="I",r},H.ENRU=function(){var e,r=H._RU(n);let t=194;for(e of H._BASE.concat([105,239,1028,1030,1031,1108,1110,1111,1118,1038,8381,8364,165,8376,8372,163,8380],[215,247]))r[t++]=H._char(e);return r},H.ENKK=function(){var e,r=H._RU(n);let t=194;for(e of H._BASE.concat([1241,1181,1171,1199,1201,1179,1257,1211,1240,1186,1170,1198,1200,1178,1256,1210,8381,163,8376]))r[t++]=H._char(e);return r},H._HI=function(e){var r=e();for(let e=2304;e<2432;e++)r[e-2176]=H._char(e);return r},H._Ind=[8377,8360,78,2547,2404,215,247],H.HI=function(){var e,r=H._HI(o);let t=65;for(e of H._BASE.concat(H._Ind))r[t++]=H._char(e),91===t&&(t=97);return r},H.ENHI=function(){return H._HI(n)},H._BN=function(e){var r=e();for(let e=2432;e<2559;e++)r[e-2304]=H._char(e);return r[255]=H._char(2404),r},H.BN=function(){var e,r=H._BN(o);let t=65;for(e of H._BASE.concat(H._Ind))r[t++]=H._char(e),91===t&&(t=97);return r},H.ENBN=function(){return H._BN(n)},H.HIBN=function(){var r={};for(let e=2304;e<2559;e++)r[e-2176-128]=H._char(e);return r[255]=" ",r},H._JA=[[65371,65373,65288,65289,65339,65341,12304,12305,12289,65292,12290,12349,12300,12301,12302,12303,12288,12316,65306,65281,65311,12445,12541,183],[8230,8229,165]],H.JA=function(){var e,r=n();let t=128;for(e of H._JA[0].concat(Array.from({length:46},(e,r)=>r+12352),Array.from({length:46},(e,r)=>r+12448),H._JA[1],[19968,20108,19977,22235,20116,20845,19971,20843,20061]))r[t++]=H._char(e);return r[17]=H._char(21313),r[18]=H._char(30334),r[19]=H._char(21315),r[20]=H._char(19975),r},H.Telu=function(){var e,r=n();for(let e=3073;e<3184;e++)r[e-2945]=H._char(e);let t=239;for(e of H._Ind.concat([8364,163,162,165,167,169,174,8482,8240,8241]))r[t++]=H._char(e);return r},H.MR=function(){var r=n();for(let e=2304;e<2432;e++)r[e-2176]=H._char(e);return r},H.B=function(){var r=n();for(let e=256;e<383;e++)r[e-128]=H._char(e);return r[255]=H._char(383),r},H.E=function(){var r=n();for(let e=128;e<255;e++)r[e]=H._char(e);return r[255]=H._char(383),r},H.AR=function(){var r={};for(let e=1536;e<1791;e++)r[e-1536]=H._char(e);return r},H.use=class{constructor(){var e,r,t={};for([e,r]of Object.entries(H))"function"!=typeof r||e.startsWith("_")||"use"==e||(t["JSSC"+e]=r);return Object.freeze(t),t}},H._begin=["https://","http://","file://","mailto:","ftp://","data:","tel:","sms:"],Object.freeze(H.use);let P="\udbff";function j(e){if(e.length<20)return{compressed:e,sequences:!1};if(e.includes(P))return{compressed:e,sequences:!1};var r=((o,e,a)=>{var i=[],f=o.length;for(let n=0;n<f-e*a+1;n++)for(let t=2;t<=Math.min(30,Math.floor((f-n)/a));t++){var s=o.substr(n,t);if(!s.includes(P)){let r=1;for(let e=n+t;e<=f-t&&o.substr(e,t)===s;e+=t)r++;if(r>=a){var c,l=n+t*r;let e=!1;for(c of i)if(n<c.end&&l>c.start){e=!0;break}if(!e){i.push({start:n,end:l,length:t,pattern:s,count:r,saved:t*r-(t+3)}),n=l-1;break}}}}return i.sort((e,r)=>r.saved-e.saved)})(e,2,3);if(0===r.length)return{compressed:e,sequences:!1};var t,n,o=[],a=new Array(e.length).fill(!1);for(t of r){let r=!0;for(let e=t.start;e<t.end;e++)if(a[e]){r=!1;break}if(r&&0<t.saved){o.push(t);for(let e=t.start;e<t.end;e++)a[e]=!0}}if(0===o.length)return{compressed:e,sequences:!1};let i="",f=0;for(n of o){f<n.start&&(i+=e.slice(f,n.start));var s=String.fromCharCode(Math.min(n.length,30)+32),c=String.fromCharCode(Math.min(n.count,65535)+32);i+=P+s+c+n.pattern,f=n.end}return f<e.length&&(i+=e.slice(f)),i.length<.9*e.length?{compressed:i,sequences:!0}:{compressed:e,sequences:!1}}let L={ESCAPE_BYTE:255,TOP_COUNT:254,SPLITTER:" ​",compress(e,r=this.SPLITTER){var t,n={};for(t of e)n[t]=(n[t]||0)+1;var o,a,i=Object.entries(n).sort((e,r)=>r[1]-e[1]).slice(0,this.TOP_COUNT).map(e=>e[0]),f=new Map(i.map((e,r)=>[e,r])),i=String.fromCharCode(i.length)+i.join(""),s=[];for(o of e)f.has(o)?s.push(f.get(o)):(s.push(this.ESCAPE_BYTE),a=o.charCodeAt(0),s.push(a>>8&255),s.push(255&a));let c="";for(let e=0;e<s.length;e+=2){var l=s[e],u=e+1<s.length?s[e+1]:0;c+=String.fromCharCode(l<<8|u)}return i+r+c},decompress(e,r=this.SPLITTER){e=e.split(r);if(e.length<2)throw new Error("Invalid freqMap data: splitter not found");var t=e[0],n=e.slice(1).join(r),o=t.charCodeAt(0),a=t.substring(1,o+1),i=[];for(let e=0;e<n.length;e++){var f=n.charCodeAt(e);i.push(f>>8&255),i.push(255&f)}let s="";for(let e=0;e<i.length;e++){var c,l=i[e];l===this.ESCAPE_BYTE?(c=i[e+1]<<8|i[e+2],s+=String.fromCharCode(c),e+=2):l<o&&(s+=a[l])}return s},test(e,r=this.SPLITTER){try{var t,n;return e.includes(r)?0:(t=this.compress(e,r),n=this.decompress(t,r),t.length<e.length?n==e?[1,t.length,r,t]:n.slice(0,-1)==e?[2,t.length,r,t]:0:0)}catch(e){return 0}}},D=[" ​","\0","","","�","•","|§|","\ufeff"];async function compress(e,r){if("string"!=typeof e&&"object"!=typeof e&&"number"!=typeof e)throw new Error("Invalid input.");let o={segmentation:!0,recursivecompression:!0,justc:!!M};if(r){if("object"!=typeof r)throw new Error("Invalid options input.");for(var[t,n]of Object.entries(r)){if("boolean"!=typeof n)throw new Error("Invalid options input.");t.toLowerCase()in o?o[t.toLowerCase()]=n:console.warn(`Unknown option: "${t}".`)}}let a=e,g=e,c=!1;if("number"==typeof g&&(c=!0,(g=g.toString()).includes(".")))throw new Error("Invalid input.");let v=!1;function i(e){return e.replace(/(.)\1+/g,(e,r)=>r+e.length)}let C=-1;if("string"==typeof g)for(var f of H._begin)if(g.startsWith(f)){C=H._begin.indexOf(f),g=g.slice(f.length);break}let m=-1;async function s(r){try{var e=await M.stringify(r);return e&&"function"==typeof e.then?await e:e}catch(e){return await M.initialize(),M.stringify(r)}}if(-1==C)if("object"==typeof g&&Array.isArray(g))g=JSON.stringify(g).slice(1,-1),m=4;else if("object"==typeof g)try{m=o.justc?(p=await s(g),g=p,2):(g=JSON.stringify(g),6)}catch(e){r=new Error("Invalid input.");throw new AggregateError([r,e],r.message)}else try{var l=JSON.parse(g);m=Array.isArray(l)?(g=g.slice(1,-1),3):(h=!!o.justc&&await s(l))&&h.length<g.length&&g==JSON.stringify(l)?(g=h,1):(g=g.slice(1,-1),5)}catch(e){}function S(e,r=!1){let t=!1,n=!1;if(/\d/.test(e)||(t=!0,e=i(e)),!r){r=j(e);if(r.sequences)return n=!0,[r.compressed,t,n]}return[e,t,n]}/\d/.test(g)||(g=i(g),v=!0);let y=async e=>{try{return await decompress(e,!0)===String(a)}catch{return!1}};e=[];/^\d+$/.test(g)&&(e.push(async()=>{var e=await((e=parseInt(g))<15?b(k(c?6:0,!1,!1,!1,-1,e+1,!1,m)):null);return e&&await y(e)?e:null}),e.push(async()=>{var e,r,t,n,o={A:10,B:11,C:12,D:13,E:14},a=[];for(e of g.replaceAll("10","A").replaceAll("11","B").replaceAll("12","C").replaceAll("13","D").replaceAll("14","E").split(""))/\d/.test(e)?a.push(x(parseInt(e),4)):a.push(x(o[e],4));let[i,f,s]=["",!1,!1];for(r of I(a,4))i+=String.fromCharCode(q((t=r.join(""),n=void 0,t.length<16?(n=4-U(t,4).length,x(15,4).repeat(n)+t):t)));return[i,f,s]=S(i),i=b(k(3,!1,c,f,-1,0,s,m))+i,await y(i)?i:null})),e.push(async()=>{var e=_(g);if(2!==e.max||2!==e.min)return null;let r=e.output,[t,n,o]=["",!1,!1];function a(e){t+=String.fromCharCode(e)}function i(e){r=r.slice(e)}for(;0<r.length;)if(1===r.length)a(r[0]),i(1);else if(r.length<3){for(var f of r)a(f);i(r.length)}else{var s=parseInt(String(r[0])+String(r[1])+String(r[2])),c=parseInt(String(r[0])+String(r[1]));E(s)?(a(s),i(3)):E(c)?(a(c),i(2)):(a(r[0]),i(1))}[t,n,o]=S(out);e=b(k(1,!1,v,n,C,0,o,m))+t;return await y(e)?e:null}),e.push(async()=>{var r;if(256<=_(g).maxCharCode)return null;let[t,e,n]=["",!1,!1];for(r of U(g,2)){let e="";for(var o of r)e+=x(o.charCodeAt(0),8);t+=String.fromCharCode(q(e))}[t,e,n]=S(t);var a=b(k(2,!1,v,e,C,0,n,m))+t;return await y(a)?a:null}),e.push(async()=>{var r,t,e=new H.use,n=g.split("");let o,a=NaN;for([r,t]of Object.entries(e)){var i,f=t(),s=(f.length=256,Array.from(f));let e=!0;for(i of n)if(!s.includes(i)){e=!1;break}if(e){o=t(),a=H._IDs[r.slice(4)];break}}if(o){var c={};for(let[e,r]of Object.entries(o))c[r]=e;var l,u,h,p=[],d=[];for(l of n)p.push(x(parseInt(c[l]),8));for(u of I(p,2))d.push(u.join("").padStart(16,"0"));let[e,r,t]=["",!1,!1];for(h of d)e+=String.fromCharCode(q(h));if([e,r,t]=S(e),e=b(k(5,!1,v,r,C,a,t,m))+e,await y(e))return e}return null}),e.push(async()=>{var e=[...new Set(g.split("").map(e=>e.charCodeAt(0)))];if(16<=e.length)return null;let r=e.map(e=>String.fromCharCode(e)).join(""),t=[];var n,[o,a]=[!1,!1];for(n of g)t.push(e.indexOf(n.charCodeAt(0))),4===t.length&&(r+=String.fromCharCode(q(t.map(e=>x(e,4)).join(""))),t=[]);t.length&&(r+=String.fromCharCode(q(t.map(e=>x(e,4)).join("").padStart(16,"1")))),[r,o,a]=S(r);o=b(k(4,!1,v,o,C,e.length,a,m))+r;return await y(o)?o:null}),e.push(async()=>{for(var e of D){e=L.test(g,e);if(Array.isArray(e)){var[,,r,t]=e,e=b(k(7,!1,!1,!1,-1,q((e[0]-1).toString()+x(D.indexOf(r),3))))+t;if(await y(e))return e}}return null}),e.push(async()=>{if("string"!=typeof g)return null;let e;try{e=new URL(H._begin[C]+g)}catch{return null}var r=e.href,t=/%[0-9A-Fa-f]{2}/.test(r),n=e.hostname.includes("xn--"),o=!!e.search,a=!!e.hash;let i=r.slice(H._begin[C].length);n&&"undefined"!=typeof punycode&&(e.hostname=punycode.toUnicode(e.hostname),i=e.href.slice(H._begin[C].length));var f=[];for(let e=0;e<i.length;e++){if("%"===i[e]&&e+2<i.length){var s=i.slice(e+1,e+3);if(/^[0-9A-Fa-f]{2}$/.test(s)){f.push(parseInt(s,16)),e+=2;continue}}f.push(i.charCodeAt(e))}r=1&f.length;r&&f.push(0);let c="";for(let e=0;e<f.length;e+=2)c+=String.fromCharCode(f[e]<<8|(f[e+1]??0));t=(t?1:0)|(n?2:0)|(o?4:0)|(a?8:0),n=!1,[c,n]=S(c,!0),o=b(k(8,!1,v,n,C,t,r,m))+c;return await y(o)?o:null}),o.segmentation&&e.push(async()=>{var e,r=(r=>{if("string"!=typeof r||0===r.length)return[];var t=[];let n=r[0];for(let e=1;e<r.length;e++){var o=r.charCodeAt(e-1),a=r.charCodeAt(e);128<Math.abs(a-o)?(t.push(n),n=r[e]):n+=r[e]}return n&&t.push(n),t})(g);if(r.length<2)return null;let t=r.length-2<15?"":String.fromCharCode(r.length-2);for(e of r){var n={...o,segmentation:!1},n=await compress(e,n);t=t+String.fromCharCode(e.length)+n}r=b(k(9,!1,v,o.justc,C,Math.min(r.length-2,15),o.recursivecompression,m))+t;return await y(r)?r:null});let u=g.match(/^(.{1,7}?)(?:\1)+$/);u&&e.push(async()=>{var e,r,t,n=u[1],o=g.length/n.length;return!(Math.floor(o)!=o||o<1||65550<o)&&([e,r,t]=["",!1,!1],[e,r,t]=S(n),n=b(k(10,!1,v,r,C,Math.min(o-1,15),t,m))+(14<o-1?String.fromCharCode(o-15):"")+e,await y(n))?n:null});var h,p=(await Promise.all(e.map(e=>(async e=>{try{return await e()}catch{return null}})(e)))).filter(e=>"string"==typeof e&&e.length<=String(g).length);let d;if(d=p.length?p.reduce((e,r)=>r.length<e.length?r:e):([r,l]=[!1,!1],[g,r,l]=S(h=g),await y(g)?b(k(0,!1,v,r,C,0,l,m))+g:b(k(0,!1,v,!1,C,0,!1,m))+h),o.recursivecompression)try{for(var A of p){var w=await(async(e,r)=>{if(!r.recursivecompression)return e;let t=e,n=0;for(;n<15;){n++;var o=await compress(t,{...r,recursivecompression:!1});if(o.length>=t.length)break;if(await decompress(o,!0)!==t)break;t=o}return 0===n?null:b(k(31,!1,!1,!1,-1,n,!1,-1))+t})(A,o);w&&w.length<=d.length&&await y(w)&&(d=w)}}catch(e){}return d}async function decompress(e,t=!1){if("string"!=typeof e)throw new Error("Invalid input.");let n=k(e.charCodeAt(0)-32,!0),o=n.code;function a(e){return e.replace(/(\D)(\d+)/g,(e,r,t)=>r.repeat(t))}let i=e.slice(1);async function f(e){var r;return 0<=n.beginId?H._begin[n.beginId]+e:1==n.code3||2==n.code3?(r=await(async r=>{try{var e=M.parse(r);return e&&"function"==typeof e.then?await e:e}catch(e){if("undefined"!=typeof window)try{await M.initialize();var t=M.parse(r);return t&&"function"==typeof t.then?await t:t}catch{}return null}})(e))&&"function"==typeof r.then?JSON.stringify(await r):JSON.stringify(r):e}async function s(e){let r=e;return r=n.repeatBefore&&3!=o?a(await f(e)):await f(e),n.repeatBefore&&3==o||30==o?r=parseInt(r):(3==n.code3||4==n.code3?r="["+r+"]":5==n.code3&&(r="{"+r+"}"),2!=n.code3&&4!=n.code3&&6!=n.code3||(r=JSON.parse(r))),t&&("object"==typeof r?r=JSON.stringify(r):"number"==typeof r&&(r=r.toString())),r}n.sequences&&8!=o&&9!=o&&(i=(e=>{let r="",t=0;for(;t<e.length;)if(56319===e.charCodeAt(t))if(++t+2>=e.length)r+=P;else{var n=e.charCodeAt(t)-32,o=e.charCodeAt(t+1)-32;if((t+=2)+n>e.length){r+=P+String.fromCharCode(32+n)+String.fromCharCode(32+o)+e.slice(t);break}var a=e.substr(t,n);t+=n;for(let e=0;e<o;e++)r+=a}else r+=e.charAt(t),t++;return r})(i)),n.repeatAfter&&9!=o&&(i=a(i));let r="";switch(o){case 0:case 6:return 0<n.code2?s(String(n.code2-1)):s(i);case 1:function c(e){r+=String.fromCharCode(e)}for(var l of i.split("")){var u,h=String(l.charCodeAt(0));if(2<h.length)for(u of U(h,2))c(parseInt(u));else c(l.charCodeAt(0))}return s(r);case 2:function p(e){return String.fromCharCode(q(e))}for(var d of i.split("")){var g,v=x(d.charCodeAt(0),16);8<x(d.charCodeAt(0),0).length?([v,g]=U(v,8),r+=p(v)+p(g)):(v=x(d.charCodeAt(0),8),r+=p(v))}return s(r);case 3:for(var C of i.split("")){var m;for(m of U(x(C.charCodeAt(0),16),4)){var S=q(m);15!=S&&(r+=S.toString(10))}}return s(r);case 4:var y,A,w,_,b=[];for(y of i.slice(0,n.code2).split(""))b.push(y);for(A of i.slice(n.code2).split(""))for(w of U(x(A.charCodeAt(0),16),4))"1111"!=w&&(_=q(w),r+=b[_]);return s(r);case 5:var E=((t,n)=>{var e,r,o,a={};for([e,r]of Object.entries(H._IDs))a[r]=e;if(t=a[t]){let r=(new H.use)["JSSC"+t](),e="";for(o of n.split("")){var i,f,s=o.charCodeAt();function c(e){return String(r[String(q(e))])}8<x(s,0).length?([f,i]=U(x(s,16),8),e+=c(f)+c(i)):(f=x(s,8),e+=c(f))}return e}})(n.code2,i);if(E)return s(E);throw new Error("Invalid compressed string");case 7:E=D[q(x(n.code2).slice(1))];return r=L.decompress(i,E),s(r=1==parseInt(x(n.code2).slice(0,1))?r.slice(0,-1):r);case 8:{var I,j,N=[];for(I of i){var B=I.charCodeAt(0);N.push(B>>8&255,255&B)}n.sequences&&N.pop();let e="";for(j of N)e+=String.fromCharCode(j);return 1&n.code2&&(e=e.replace(/[\x00-\x20\x7F-\xFF]/g,e=>"%"+e.charCodeAt(0).toString(16).padStart(2,"0").toUpperCase())),2&n.code2&&"undefined"!=typeof punycode&&((E=new URL(e)).hostname=punycode.toASCII(E.hostname),e=E.href),s(e)}case 9:{let r=0;var O=n.code2<15?n.code2+2:i.charCodeAt(r++)+2;let t="";for(let e=0;e<O;e++){var T=i.charCodeAt(r++),T=(await decompress(i.slice(r),!0)).slice(0,T);t+=T,r+=(await compress(T,{segmentation:!1,justc:n.repeatAfter,recursivecompression:n.sequences})).length}return s(t)}case 10:var E=15==n.code2,R=E?i.charCodeAt(0)+15:n.code2;return s((i=E?i.slice(1):i).repeat(R));case 31:{let r=i;var J=n.code2;for(let e=0;e<J;e++){if(31===k(r.charCodeAt(0)-32,!0).code)throw new Error("Attempt to nested recursive compression");r=await decompress(r,!0)}return r}default:throw new Error("Invalid compressed string")}}return{compress:compress,decompress:decompress,get[Symbol.toStringTag](){return"JSSC"}}});
1
+ /*
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2025-2026 JustDeveloper <https://justdeveloper.is-a.dev/>
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+
25
+ */
26
+
27
+ /*
28
+ __ _______________ __
29
+ \ \ __ / / __/ __/ ___/ / /
30
+ > > / // /\ \_\ \/ /__ < <
31
+ /_/ \___/___/___/\___/ \_\
32
+
33
+ JavaScript String Compressor
34
+ https://jssc.js.org/
35
+
36
+ npm i strc
37
+
38
+ */
39
+
40
+ ((e,r)=>{var t;"function"==typeof define&&define.amd?define(["justc"],r):"object"==typeof module&&module.exports?(t=r(require("justc")),module.exports={...t,default:t}):(e.JSSC=r(e.JUSTC),Object.freeze(e.JSSC))})("undefined"!=typeof self?self:this,function(U){let x="JSSC",J=x+": ";if(65536===String.fromCharCode(65536).charCodeAt(0)||256!==String.fromCharCode(256).charCodeAt(0))throw new Error(J+"Supported UTF-16 only!");function _(e){let r=[],t=0,n=0,o=1/0;return String(e).split("").forEach(e=>{e=e.charCodeAt();r.push(e),t=Math.max(t,e.toString().length),n=Math.max(n,e),o=Math.min(o,e.toString().length)}),{max:t,output:r,maxCharCode:n,min:o}}function b(e){return String.fromCharCode(e+32)}function E(e){return e%65535===e}function q(r,t){var n=[];for(let e=0;e<r.length;e+=t)n.push(r.slice(e,e+t));return n}function I(r,t){var n=[];for(let e=0;e<r.length;e+=t)n.push(r.slice(e,e+t));return n}function H(e,r){return e.toString(2).padStart(r,"0")}function k(e){return parseInt(e,2)}function o(){let r={};function t(e){r[e]=String.fromCharCode(e)}for(let e=0;e<65;e++)t(e);for(let e=91;e<97;e++)t(e);for(let e=123;e<128;e++)t(e);return r}function n(){var r={};for(let e=0;e<128;e++)r[e]=String.fromCharCode(e);return r}let P={};function L(e,r=!1,t=!1,n=!1,o=-1,a=0,i=!1,f=-1){var s,c,l;return r?(s=(r=H(e,16)).slice(8,11).split(""),c=k(r.slice(11)),l=k(r.slice(5,8)),{code:c,repeatBefore:"1"===s[0],repeatAfter:"1"===s[1],beginId:"1"===s[2]?l:-1,code2:k(r.slice(0,4)),sequences:"1"===r.slice(4,5),code3:"0"===s[2]?l:-1,bin:r}):k(H(a,4)+(i?"1":"0")+H(0<=o?o:f<0?0:f,3)+(t?"1":"0")+(n?"1":"0")+(0<=o?"1":"0")+H(e,5))}P._char=e=>String.fromCharCode(e),P._IDs={BASE:0,RU:1,ENRU:2,ENKK:3,HI:4,ENHI:5,BN:6,ENBN:7,HIBN:8,JA:9,Telu:10,MR:11,B:12,E:13,AR:14},P.BASE=function(){var e,r=o(),t=[215,247,8722,11800,174,169,171,10003,182,9834,183,10005,177,181,8960,8211,8212,8228,8229,8230,8240,8241,8249,8250,8252,8253,8263,8264,8267,8270,8274,8451,8457,8470,8471,8482,402,1423,1547,65020,2547,2553,2555,2801,3065,3647,6107,8499,2546,8304,185,178,179,8585,8319,8305,8709,8730,8734];for(let e=161;e<168;e++)t.push(e);for(let e=187;e<192;e++)t.push(e);for(let e=8308;e<8317;e++)t.push(e);for(let e=8528;e<8576;e++)t.push(e);for(let e=8352;e<8385;e++)t.push(e);for(let e=8320;e<8333;e++)t.push(e);for(let e=8712;e<8718;e++)t.push(e);let n=65;for(e of t)r[n++]=P._char(e),91===n?n=97:123===n&&(n=128);return r},P._BASE=[167,8722,8451,169,8211,215,247,8457,174,8470,8482,8471,8249,8250,171,187,8242,8245,8216,8217,8218,8219,8243,8246,8220,8221,8222,8223,8226,182,8267,8270,8240,8241,9834,183,8228,8229,8230,161,191,8252,8264],P._MATH=[8544,8547,8550,8553,8556,8572,8545,8548,8551,8554,8557,8573,8546,8549,8552,8555,8558,8574,8560,8563,8566,8569,8559,8575,8561,8564,8567,8570,8562,8565,8568,8571,8712,8715,8713,8716,8730,8721,8734,8804,8805],P._CURR=[165,3647,8363,8361,1423,8364,8377,8362,8378,8353,8358,163,8381,8354,8369,2547,8370,8366,8376,8382,8357,6107,8360,8372,8373,8365,1547,2801,162,65020,8355,8383,8380,3065,164,8384,8379,402,8359,2546,8371,8367,8356,8375,2553,8368,8352,8499,8374,2555],P._RU=function(e){var r=e();let t=0;for(let e=1040;e<1104;e++){var n=e-912;r[n]=P._char(e),t=Math.max(t,n)}return r[t+1]=P._char(1025),r[t+2]=P._char(1105),r},P.RU=function(){var e,r=P._RU(o);let t=65;for(e of P._BASE.concat(P._MATH,[105,239,1028,1030,1031,1108,1110,1111,1118,1038,1241,1181,1171,1199,1201,1179,1257,1211,1240,1186,1170,1198,1200,1178,1256,1210,8381,8364,165,8376,8372]))r[t++]=P._char(e),91===t?t=97:123===t&&(t=193);return r[110]="i",r[111]="I",r},P.ENRU=function(){var e,r=P._RU(n);let t=194;for(e of P._BASE.concat([105,239,1028,1030,1031,1108,1110,1111,1118,1038,8381,8364,165,8376,8372,163,8380],[215,247]))r[t++]=P._char(e);return r},P.ENKK=function(){var e,r=P._RU(n);let t=194;for(e of P._BASE.concat([1241,1181,1171,1199,1201,1179,1257,1211,1240,1186,1170,1198,1200,1178,1256,1210,8381,163,8376]))r[t++]=P._char(e);return r},P._HI=function(e){var r=e();for(let e=2304;e<2432;e++)r[e-2176]=P._char(e);return r},P._Ind=[8377,8360,78,2547,2404,215,247],P.HI=function(){var e,r=P._HI(o);let t=65;for(e of P._BASE.concat(P._Ind))r[t++]=P._char(e),91===t&&(t=97);return r},P.ENHI=function(){return P._HI(n)},P._BN=function(e){var r=e();for(let e=2432;e<2559;e++)r[e-2304]=P._char(e);return r[255]=P._char(2404),r},P.BN=function(){var e,r=P._BN(o);let t=65;for(e of P._BASE.concat(P._Ind))r[t++]=P._char(e),91===t&&(t=97);return r},P.ENBN=function(){return P._BN(n)},P.HIBN=function(){var r={};for(let e=2304;e<2559;e++)r[e-2176-128]=P._char(e);return r[255]=" ",r},P._JA=[[65371,65373,65288,65289,65339,65341,12304,12305,12289,65292,12290,12349,12300,12301,12302,12303,12288,12316,65306,65281,65311,12445,12541,183],[8230,8229,165]],P.JA=function(){var e,r=n();let t=128;for(e of P._JA[0].concat(Array.from({length:46},(e,r)=>r+12352),Array.from({length:46},(e,r)=>r+12448),P._JA[1],[19968,20108,19977,22235,20116,20845,19971,20843,20061]))r[t++]=P._char(e);return r[17]=P._char(21313),r[18]=P._char(30334),r[19]=P._char(21315),r[20]=P._char(19975),r},P.Telu=function(){var e,r=n();for(let e=3073;e<3184;e++)r[e-2945]=P._char(e);let t=239;for(e of P._Ind.concat([8364,163,162,165,167,169,174,8482,8240,8241]))r[t++]=P._char(e);return r},P.MR=function(){var r=n();for(let e=2304;e<2432;e++)r[e-2176]=P._char(e);return r},P.B=function(){var r=n();for(let e=256;e<383;e++)r[e-128]=P._char(e);return r[255]=P._char(383),r},P.E=function(){var r=n();for(let e=128;e<255;e++)r[e]=P._char(e);return r[255]=P._char(383),r},P.AR=function(){var r={};for(let e=1536;e<1791;e++)r[e-1536]=P._char(e);return r},P.use=class{constructor(){var e,r,t={};for([e,r]of Object.entries(P))"function"!=typeof r||e.startsWith("_")||"use"==e||(t[x+e]=r);return Object.freeze(t),t}},P._begin=["https://","http://","file://","mailto:","ftp://","data:","tel:","sms:"],Object.freeze(P.use);let D="\udbff";function j(e){if(e.length<20)return{compressed:e,sequences:!1};if(e.includes(D))return{compressed:e,sequences:!1};var r=((o,e,a)=>{var i=[],f=o.length;for(let n=0;n<f-e*a+1;n++)for(let t=2;t<=Math.min(30,Math.floor((f-n)/a));t++){var s=o.substr(n,t);if(!s.includes(D)){let r=1;for(let e=n+t;e<=f-t&&o.substr(e,t)===s;e+=t)r++;if(r>=a){var c,l=n+t*r;let e=!1;for(c of i)if(n<c.end&&l>c.start){e=!0;break}if(!e){i.push({start:n,end:l,length:t,pattern:s,count:r,saved:t*r-(t+3)}),n=l-1;break}}}}return i.sort((e,r)=>r.saved-e.saved)})(e,2,3);if(0===r.length)return{compressed:e,sequences:!1};var t,n,o=[],a=new Array(e.length).fill(!1);for(t of r){let r=!0;for(let e=t.start;e<t.end;e++)if(a[e]){r=!1;break}if(r&&0<t.saved){o.push(t);for(let e=t.start;e<t.end;e++)a[e]=!0}}if(0===o.length)return{compressed:e,sequences:!1};let i="",f=0;for(n of o){f<n.start&&(i+=e.slice(f,n.start));var s=String.fromCharCode(Math.min(n.length,30)+32),c=String.fromCharCode(Math.min(n.count,65535)+32);i+=D+s+c+n.pattern,f=n.end}return f<e.length&&(i+=e.slice(f)),i.length<.9*e.length?{compressed:i,sequences:!0}:{compressed:e,sequences:!1}}let F={ESCAPE_BYTE:255,TOP_COUNT:254,SPLITTER:" ​",compress(e,r=this.SPLITTER){var t,n={};for(t of e)n[t]=(n[t]||0)+1;var o,a,i=Object.entries(n).sort((e,r)=>r[1]-e[1]).slice(0,this.TOP_COUNT).map(e=>e[0]),f=new Map(i.map((e,r)=>[e,r])),i=String.fromCharCode(i.length)+i.join(""),s=[];for(o of e)f.has(o)?s.push(f.get(o)):(s.push(this.ESCAPE_BYTE),a=o.charCodeAt(0),s.push(a>>8&255),s.push(255&a));let c="";for(let e=0;e<s.length;e+=2){var l=s[e],u=e+1<s.length?s[e+1]:0;c+=String.fromCharCode(l<<8|u)}return i+r+c},decompress(e,r=this.SPLITTER){e=e.split(r);if(e.length<2)throw new Error(J+"Invalid freqMap data: splitter not found");var t=e[0],n=e.slice(1).join(r),o=t.charCodeAt(0),a=t.substring(1,o+1),i=[];for(let e=0;e<n.length;e++){var f=n.charCodeAt(e);i.push(f>>8&255),i.push(255&f)}let s="";for(let e=0;e<i.length;e++){var c,l=i[e];l===this.ESCAPE_BYTE?(c=i[e+1]<<8|i[e+2],s+=String.fromCharCode(c),e+=2):l<o&&(s+=a[l])}return s},test(e,r=this.SPLITTER){try{var t,n;return e.includes(r)?0:(t=this.compress(e,r),n=this.decompress(t,r),t.length<e.length?n==e?[1,t.length,r,t]:n.slice(0,-1)==e?[2,t.length,r,t]:0:0)}catch(e){return 0}}},z=[" ​","\0","","","�","•","|§|","\ufeff"];async function compress(e,r){if("string"!=typeof e&&"object"!=typeof e&&"number"!=typeof e)throw new Error(J+"Invalid input.");let o={segmentation:!0,recursivecompression:!0,justc:!!U};if(r){if("object"!=typeof r)throw new Error(J+"Invalid options input.");for(var[t,n]of Object.entries(r))if(void 0!==n){if("boolean"!=typeof n)throw new Error(J+"Invalid options input.");t.toLowerCase()in o?o[t.toLowerCase()]=n:console.warn(J+`Unknown option: "${t}".`)}}let a=e,g=e,c=!1;if("number"==typeof g&&(c=!0,(g=g.toString()).includes(".")))throw new Error(J+"Invalid input.");let v=!1;function i(e){return e.replace(/(.)\1+/g,(e,r)=>r+e.length)}let C=-1;if("string"==typeof g)for(var f of P._begin)if(g.startsWith(f)){C=P._begin.indexOf(f),g=g.slice(f.length);break}let m=-1;async function s(r){try{var e=await U.stringify(r);return e&&"function"==typeof e.then?await e:e}catch(e){return await U.initialize(),U.stringify(r)}}if(-1==C)if("object"==typeof g&&Array.isArray(g))g=JSON.stringify(g).slice(1,-1),m=4;else if("object"==typeof g)try{m=o.justc?(p=await s(g),g=p,2):(g=JSON.stringify(g),6)}catch(e){r=new Error(J+"Invalid input.");throw new AggregateError([r,e],r.message)}else try{var l=JSON.parse(g);m=Array.isArray(l)?(g=g.slice(1,-1),3):(h=!!o.justc&&await s(l))&&h.length<g.length&&g==JSON.stringify(l)?(g=h,1):(g=g.slice(1,-1),5)}catch(e){}function S(e,r=!1){let t=!1,n=!1;if(/\d/.test(e)||(t=!0,e=i(e)),!r){r=j(e);if(r.sequences)return n=!0,[r.compressed,t,n]}return[e,t,n]}/\d/.test(g)||(g=i(g),v=!0);let y=async e=>{try{return await decompress(e,!0)===String(a)}catch{return!1}};e=[];/^\d+$/.test(g)&&(e.push(async()=>{var e=await((e=parseInt(g))<15?b(L(c?6:0,!1,!1,!1,-1,e+1,!1,m)):null);return e&&await y(e)?e:null}),e.push(async()=>{var e,r,t,n,o={A:10,B:11,C:12,D:13,E:14},a=[];for(e of g.replaceAll("10","A").replaceAll("11","B").replaceAll("12","C").replaceAll("13","D").replaceAll("14","E").split(""))/\d/.test(e)?a.push(H(parseInt(e),4)):a.push(H(o[e],4));let[i,f,s]=["",!1,!1];for(r of I(a,4))i+=String.fromCharCode(k((t=r.join(""),n=void 0,t.length<16?(n=4-q(t,4).length,H(15,4).repeat(n)+t):t)));return[i,f,s]=S(i),i=b(L(3,!1,c,f,-1,0,s,m))+i,await y(i)?i:null})),e.push(async()=>{var e=_(g);if(2!==e.max||2!==e.min)return null;let r=e.output,[t,n,o]=["",!1,!1];function a(e){t+=String.fromCharCode(e)}function i(e){r=r.slice(e)}for(;0<r.length;)if(1===r.length)a(r[0]),i(1);else if(r.length<3){for(var f of r)a(f);i(r.length)}else{var s=parseInt(String(r[0])+String(r[1])+String(r[2])),c=parseInt(String(r[0])+String(r[1]));E(s)?(a(s),i(3)):E(c)?(a(c),i(2)):(a(r[0]),i(1))}[t,n,o]=S(out);e=b(L(1,!1,v,n,C,0,o,m))+t;return await y(e)?e:null}),e.push(async()=>{var r;if(256<=_(g).maxCharCode)return null;let[t,e,n]=["",!1,!1];for(r of q(g,2)){let e="";for(var o of r)e+=H(o.charCodeAt(0),8);t+=String.fromCharCode(k(e))}[t,e,n]=S(t);var a=b(L(2,!1,v,e,C,0,n,m))+t;return await y(a)?a:null}),e.push(async()=>{var r,t,e=new P.use,n=g.split("");let o,a=NaN;for([r,t]of Object.entries(e)){var i,f=t(),s=(f.length=256,Array.from(f));let e=!0;for(i of n)if(!s.includes(i)){e=!1;break}if(e){o=t(),a=P._IDs[r.slice(4)];break}}if(o){var c={};for(let[e,r]of Object.entries(o))c[r]=e;var l,u,h,p=[],d=[];for(l of n)p.push(H(parseInt(c[l]),8));for(u of I(p,2))d.push(u.join("").padStart(16,"0"));let[e,r,t]=["",!1,!1];for(h of d)e+=String.fromCharCode(k(h));if([e,r,t]=S(e),e=b(L(5,!1,v,r,C,a,t,m))+e,await y(e))return e}return null}),e.push(async()=>{var e=[...new Set(g.split("").map(e=>e.charCodeAt(0)))];if(16<=e.length)return null;let r=e.map(e=>String.fromCharCode(e)).join(""),t=[];var n,[o,a]=[!1,!1];for(n of g)t.push(e.indexOf(n.charCodeAt(0))),4===t.length&&(r+=String.fromCharCode(k(t.map(e=>H(e,4)).join(""))),t=[]);t.length&&(r+=String.fromCharCode(k(t.map(e=>H(e,4)).join("").padStart(16,"1")))),[r,o,a]=S(r);o=b(L(4,!1,v,o,C,e.length,a,m))+r;return await y(o)?o:null}),e.push(async()=>{for(var e of z){e=F.test(g,e);if(Array.isArray(e)){var[,,r,t]=e,e=b(L(7,!1,!1,!1,-1,k((e[0]-1).toString()+H(z.indexOf(r),3))))+t;if(await y(e))return e}}return null}),e.push(async()=>{if("string"!=typeof g)return null;let e;try{e=new URL(P._begin[C]+g)}catch{return null}var r=e.href,t=/%[0-9A-Fa-f]{2}/.test(r),n=e.hostname.includes("xn--"),o=!!e.search,a=!!e.hash;let i=r.slice(P._begin[C].length);n&&"undefined"!=typeof punycode&&(e.hostname=punycode.toUnicode(e.hostname),i=e.href.slice(P._begin[C].length));var f=[];for(let e=0;e<i.length;e++){if("%"===i[e]&&e+2<i.length){var s=i.slice(e+1,e+3);if(/^[0-9A-Fa-f]{2}$/.test(s)){f.push(parseInt(s,16)),e+=2;continue}}f.push(i.charCodeAt(e))}r=1&f.length;r&&f.push(0);let c="";for(let e=0;e<f.length;e+=2)c+=String.fromCharCode(f[e]<<8|(f[e+1]??0));t=(t?1:0)|(n?2:0)|(o?4:0)|(a?8:0),n=!1,[c,n]=S(c,!0),o=b(L(8,!1,v,n,C,t,r,m))+c;return await y(o)?o:null}),o.segmentation&&e.push(async()=>{var e,r=(r=>{if("string"!=typeof r||0===r.length)return[];var t=[];let n=r[0];for(let e=1;e<r.length;e++){var o=r.charCodeAt(e-1),a=r.charCodeAt(e);128<Math.abs(a-o)?(t.push(n),n=r[e]):n+=r[e]}return n&&t.push(n),t})(g);if(r.length<2)return null;let t=r.length-2<15?"":String.fromCharCode(r.length-2);for(e of r){var n={...o,segmentation:!1},n=await compress(e,n);t=t+String.fromCharCode(e.length)+n}r=b(L(9,!1,v,o.justc,C,Math.min(r.length-2,15),o.recursivecompression,m))+t;return await y(r)?r:null});let u=g.match(/^(.{1,7}?)(?:\1)+$/);u&&e.push(async()=>{var e,r,t,n=u[1],o=g.length/n.length;return!(Math.floor(o)!=o||o<1||65550<o)&&([e,r,t]=["",!1,!1],[e,r,t]=S(n),n=b(L(10,!1,v,r,C,Math.min(o-1,15),t,m))+(14<o-1?String.fromCharCode(o-15):"")+e,await y(n))?n:null});var h,p=(await Promise.all(e.map(e=>(async e=>{try{return await e()}catch{return null}})(e)))).filter(e=>"string"==typeof e&&e.length<=String(g).length);let d;if(d=p.length?p.reduce((e,r)=>r.length<e.length?r:e):([r,l]=[!1,!1],[g,r,l]=S(h=g),await y(g)?b(L(0,!1,v,r,C,0,l,m))+g:b(L(0,!1,v,!1,C,0,!1,m))+h),o.recursivecompression)try{for(var A of p){var w=await(async(e,r)=>{if(!r.recursivecompression)return e;let t=e,n=0;for(;n<15;){n++;var o=await compress(t,{...r,recursivecompression:!1});if(o.length>=t.length)break;if(await decompress(o,!0)!==t)break;t=o}return 0===n?null:b(L(31,!1,!1,!1,-1,n,!1,-1))+t})(A,o);w&&w.length<=d.length&&await y(w)&&(d=w)}}catch(e){}return d}async function decompress(e,t=!1){if("string"!=typeof e)throw new Error(J+"Invalid input.");let n=L(e.charCodeAt(0)-32,!0),o=n.code;function a(e){return e.replace(/(\D)(\d+)/g,(e,r,t)=>r.repeat(t))}let i=e.slice(1);async function f(e){var r;return 0<=n.beginId?P._begin[n.beginId]+e:1==n.code3||2==n.code3?(r=await(async r=>{try{var e=U.parse(r);return e&&"function"==typeof e.then?await e:e}catch(e){if("undefined"!=typeof window)try{await U.initialize();var t=U.parse(r);return t&&"function"==typeof t.then?await t:t}catch{}return null}})(e))&&"function"==typeof r.then?JSON.stringify(await r):JSON.stringify(r):e}async function s(e){let r=e;return r=n.repeatBefore&&3!=o?a(await f(e)):await f(e),n.repeatBefore&&3==o||30==o?r=parseInt(r):(3==n.code3||4==n.code3?r="["+r+"]":5==n.code3&&(r="{"+r+"}"),2!=n.code3&&4!=n.code3&&6!=n.code3||(r=JSON.parse(r))),t&&("object"==typeof r?r=JSON.stringify(r):"number"==typeof r&&(r=r.toString())),r}n.sequences&&8!=o&&9!=o&&(i=(e=>{let r="",t=0;for(;t<e.length;)if(56319===e.charCodeAt(t))if(++t+2>=e.length)r+=D;else{var n=e.charCodeAt(t)-32,o=e.charCodeAt(t+1)-32;if((t+=2)+n>e.length){r+=D+String.fromCharCode(32+n)+String.fromCharCode(32+o)+e.slice(t);break}var a=e.substr(t,n);t+=n;for(let e=0;e<o;e++)r+=a}else r+=e.charAt(t),t++;return r})(i)),n.repeatAfter&&9!=o&&(i=a(i));let r="";switch(o){case 0:case 6:return 0<n.code2?s(String(n.code2-1)):s(i);case 1:function c(e){r+=String.fromCharCode(e)}for(var l of i.split("")){var u,h=String(l.charCodeAt(0));if(2<h.length)for(u of q(h,2))c(parseInt(u));else c(l.charCodeAt(0))}return s(r);case 2:function p(e){return String.fromCharCode(k(e))}for(var d of i.split("")){var g,v=H(d.charCodeAt(0),16);8<H(d.charCodeAt(0),0).length?([v,g]=q(v,8),r+=p(v)+p(g)):(v=H(d.charCodeAt(0),8),r+=p(v))}return s(r);case 3:for(var C of i.split("")){var m;for(m of q(H(C.charCodeAt(0),16),4)){var S=k(m);15!=S&&(r+=S.toString(10))}}return s(r);case 4:var y,A,w,_,b=[];for(y of i.slice(0,n.code2).split(""))b.push(y);for(A of i.slice(n.code2).split(""))for(w of q(H(A.charCodeAt(0),16),4))"1111"!=w&&(_=k(w),r+=b[_]);return s(r);case 5:var E=((t,n)=>{var e,r,o,a={};for([e,r]of Object.entries(P._IDs))a[r]=e;if(t=a[t]){let r=(new P.use)[x+t](),e="";for(o of n.split("")){var i,f,s=o.charCodeAt();function c(e){return String(r[String(k(e))])}8<H(s,0).length?([f,i]=q(H(s,16),8),e+=c(f)+c(i)):(f=H(s,8),e+=c(f))}return e}})(n.code2,i);if(E)return s(E);throw new Error(J+"Invalid compressed string");case 7:E=z[k(H(n.code2).slice(1))];return r=F.decompress(i,E),s(r=1==parseInt(H(n.code2).slice(0,1))?r.slice(0,-1):r);case 8:{var I,j,N=[];for(I of i){var B=I.charCodeAt(0);N.push(B>>8&255,255&B)}n.sequences&&N.pop();let e="";for(j of N)e+=String.fromCharCode(j);return 1&n.code2&&(e=e.replace(/[\x00-\x20\x7F-\xFF]/g,e=>"%"+e.charCodeAt(0).toString(16).padStart(2,"0").toUpperCase())),2&n.code2&&"undefined"!=typeof punycode&&((E=new URL(e)).hostname=punycode.toASCII(E.hostname),e=E.href),s(e)}case 9:{let r=0;var O=n.code2<15?n.code2+2:i.charCodeAt(r++)+2;let t="";for(let e=0;e<O;e++){var T=i.charCodeAt(r++),T=(await decompress(i.slice(r),!0)).slice(0,T);t+=T,r+=(await compress(T,{segmentation:!1,justc:n.repeatAfter,recursivecompression:n.sequences})).length}return s(t)}case 10:var E=15==n.code2,R=E?i.charCodeAt(0)+15:n.code2;return s((i=E?i.slice(1):i).repeat(R));case 31:{let r=i;var M=n.code2;for(let e=0;e<M;e++){if(31===L(r.charCodeAt(0)-32,!0).code)throw new Error(J+"Attempt to nested recursive compression");r=await decompress(r,!0)}return r}default:throw new Error(J+"Invalid compressed string")}}return{compress:compress,decompress:decompress,get[Symbol.toStringTag](){return x}}});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "strc",
3
- "version": "2.0.0-test",
4
- "description": "JavaScript String Compressor",
3
+ "version": "2.0.1",
4
+ "description": "JavaScript String Compressor - lossless string compression algorithm",
5
5
  "main": "index.js",
6
6
  "repository": {
7
7
  "type": "git",
package/test/index.js CHANGED
@@ -1,97 +1,122 @@
1
- const JSSC = require('../index.js');
2
-
3
- function stringChunks(str, num) {
4
- const output = [];
5
- for (let i = 0; i < str.length; i += num) {
6
- output.push(str.slice(i, i + num))
7
- }
8
- return output
9
- }
10
-
11
- const modes = [
12
- '00: No compression',
13
- '01: 2-3 characters in 1',
14
- '02: ASCII in UTF-16',
15
- '03: Integers (Any)',
16
- '04: Build alphabet',
17
- '05: Character encoding',
18
- '06: Integers ( < 15 )',
19
- '07: Frequency map',
20
- '08: URL',
21
- '09: Segmentation',
22
- '10: Repeating strings',
23
- '11: RESERVED',
24
- '12: RESERVED',
25
- '13: RESERVED',
26
- '14: RESERVED',
27
- '15: RESERVED',
28
- '16: RESERVED',
29
- '17: RESERVED',
30
- '18: RESERVED',
31
- '19: RESERVED',
32
- '20: RESERVED',
33
- '21: RESERVED',
34
- '22: RESERVED',
35
- '23: RESERVED',
36
- '24: RESERVED',
37
- '25: RESERVED',
38
- '26: RESERVED',
39
- '27: RESERVED',
40
- '28: RESERVED',
41
- '29: RESERVED',
42
- '30: RESERVED',
43
- '31: Recursive compression',
44
- ];
45
-
46
- async function test(text, name) {
47
- console.info('\n\n\n\n\nRunning compress tests (', name, ') ...');
48
-
49
- const a = await JSSC.compress(text);
50
- const b = await JSSC.decompress(a);
51
- const c = a.charCodeAt(0).toString(2).padStart(16, '0');
52
-
53
- const toString = typeof text != 'object' ? String(text) : JSON.stringify(text);
54
- const success = [
55
- text == b,
56
- a.length <= toString.length,
57
- ];
58
- const result = success[0] && success[1];
59
-
60
- const data = a.slice(0,1);
61
- const bits = stringChunks(c, 4).join(' ');
62
- const blocks = [];
63
- const code = [];
64
-
65
- for (const [x,y] of [
66
- [0,4], [4,5],
67
- [5,8], [8,9],
68
- [9,10], [10,11], [11]
69
- ]) blocks.push(c.slice(x,y));
70
-
71
- for (const [x,y] of [
72
- [11], [0,4], [5,8]
73
- ]) code.push(parseInt(c.slice(x,y), 2));
74
-
75
- console.log(
76
- '\n\n\nOriginal:', text, '\n\nCompressed:', a, '\n\nDecompressed:', b,
77
- '\n\n\nSuccess?', result, '(Decompressed successfully?', success[0], '; Compressed size ≤ Original size?', success[1], ')\nOriginal size:', toString.length * 16, 'bits\nCompressed size:', a.length * 16, 'bits\nSaved:', toString.length * 16 - a.length * 16, 'bits\nRatio:', (toString.length * 16) / (a.length * 16),
78
- ': 1\n\n\n16-bit Data/Header character:', data, '\nCharCode:', data.charCodeAt(0), '\nBits:', bits, '\nBlocks:', ...blocks, '\nCode 1:', code[0], '\nCode 2:', code[1], c.slice(10,11) == '1' ? '\nBeginID:' : '\nCode 3:', code[2], '\nSequences?', c.slice(4,5) == '1', (code[1] > 0 && code[0] == 0) || code[0] == 6 ? '\nReturn as number?' : '\nInput RLE?', c.slice(8,9) == '1', '\nOutput RLE?', c.slice(9,10) == '1', '\nCode 3 is BeginID?', c.slice(10,11) == '1',
79
- '\n\nMode:', modes[code[0]], '\n\n\n\n\n'
80
- );
81
-
82
- return result;
83
- }
84
- async function runTest(text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', name = 'Lorem ipsum') {
85
- const result = await test(text, name);
86
- if (!result) throw new Error('Failed to decompress. decompress(text) != text');
87
- }
88
-
89
- const tests = async function () {
90
- await runTest().catch(()=>{});
91
- await runTest('foo'.repeat(1000), 'foo x1000').catch(()=>{});
92
- await runTest('ыалалыылаар', 'ыалалыылаар').catch(()=>{});
93
- await runTest(String(Math.round(Math.random() * 256000000)), 'random numbers').catch(()=>{});
94
- await runTest('asdasdsasdsadsdadsadssssssssssssssssssssыꙮ'.repeat(15), 'absolutely random stuff').catch(()=>{});
95
- }
96
-
97
- tests().catch(()=>{})
1
+ const JSSC = require('../index.js');
2
+ const JSSCmin = require('../index.min.js');
3
+
4
+ function stringChunks(str, num) {
5
+ const output = [];
6
+ for (let i = 0; i < str.length; i += num) {
7
+ output.push(str.slice(i, i + num))
8
+ }
9
+ return output
10
+ }
11
+
12
+ const encodings = [
13
+ '00: JSSCBASE',
14
+ '01: JSSCRU',
15
+ '02: JSSCENRU',
16
+ '03: JSSCENKK',
17
+ '04: JSSCHI',
18
+ '05: JSSCENHI',
19
+ '06: JSSCBN',
20
+ '07: JSSCENBN',
21
+ '08: JSSCHIBN',
22
+ '09: JSSCJA',
23
+ '10: JSSCTelu',
24
+ '11: JSSCMR',
25
+ '12: JSSCB',
26
+ '13: JSSCE',
27
+ '14: JSSCAR',
28
+ ];
29
+ const modes = [
30
+ '00: No compression',
31
+ '01: 2-3 characters in 1',
32
+ '02: ASCII in UTF-16',
33
+ '03: Integers (Any)',
34
+ '04: Build alphabet',
35
+ '05: Character encoding',
36
+ '06: Integers ( < 15 )',
37
+ '07: Frequency map',
38
+ '08: URL',
39
+ '09: Segmentation',
40
+ '10: Repeating strings',
41
+ '11: RESERVED',
42
+ '12: RESERVED',
43
+ '13: RESERVED',
44
+ '14: RESERVED',
45
+ '15: RESERVED',
46
+ '16: RESERVED',
47
+ '17: RESERVED',
48
+ '18: RESERVED',
49
+ '19: RESERVED',
50
+ '20: RESERVED',
51
+ '21: RESERVED',
52
+ '22: RESERVED',
53
+ '23: RESERVED',
54
+ '24: RESERVED',
55
+ '25: RESERVED',
56
+ '26: RESERVED',
57
+ '27: RESERVED',
58
+ '28: RESERVED',
59
+ '29: RESERVED',
60
+ '30: RESERVED',
61
+ '31: Recursive compression',
62
+ ];
63
+
64
+ async function test(text, name) {
65
+ console.info('\n\n\n\n\nRunning compress tests (', name, ') ...');
66
+
67
+ const a = await JSSC.compress(text);
68
+ const b = await JSSC.decompress(a);
69
+ const c = a.charCodeAt(0).toString(2).padStart(16, '0');
70
+
71
+ const toString = typeof text != 'object' ? String(text) : JSON.stringify(text);
72
+
73
+ const data = a.slice(0,1);
74
+ const bits = stringChunks(c, 4).join(' ');
75
+ const blocks = [];
76
+ const code = [];
77
+
78
+ for (const [x,y] of [
79
+ [0,4], [4,5],
80
+ [5,8], [8,9],
81
+ [9,10], [10,11], [11]
82
+ ]) blocks.push(c.slice(x,y));
83
+
84
+ for (const [x,y] of [
85
+ [11], [0,4], [5,8]
86
+ ]) code.push(parseInt(c.slice(x,y), 2));
87
+
88
+ const d = await JSSCmin.compress(text);
89
+ const e = await JSSCmin.decompress(d);
90
+
91
+ const success = [
92
+ text == b,
93
+ a.length <= toString.length,
94
+ a == d,
95
+ b == e
96
+ ];
97
+ const result = success[0] && success[1] && success[2] && success[3];
98
+
99
+ console.log(
100
+ '\n\n\nOriginal:', text, '\n\nCompressed:', a, '\n\nDecompressed:', b,
101
+ '\n\n\nSuccess?', result, '(Decompressed successfully?', success[0], '; Compressed size ≤ Original size?', success[1], '; .min.js test:', success[2] && success[3], ')\nOriginal size:', toString.length * 16, 'bits\nCompressed size:', a.length * 16, 'bits\nSaved:', toString.length * 16 - a.length * 16, 'bits\nRatio:', (toString.length * 16) / (a.length * 16),
102
+ ': 1\n\n\n16-bit Data/Header character:', data, '\nCharCode:', data.charCodeAt(0), '\nBits:', bits, '\nBlocks:', ...blocks, '\nCode 1:', code[0], '\nCode 2:', code[1], c.slice(10,11) == '1' ? '\nBeginID:' : '\nCode 3:', code[2], '\nSequences?', c.slice(4,5) == '1', (code[1] > 0 && code[0] == 0) || code[0] == 6 ? '\nReturn as number?' : '\nInput RLE?', c.slice(8,9) == '1', '\nOutput RLE?', c.slice(9,10) == '1', '\nCode 3 is BeginID?', c.slice(10,11) == '1',
103
+ '\n\nMode:', modes[code[0]], code[0] == 5 ? '\nCharacter Encoding:' : code[0] == 31 ? '\nCompressed:' : '', code[0] == 5 ? encodings[code[1]] : code[0] == 31 ? code[1] + 1 : '', code[0] == 31 ? 'times' : '', '\n\n\n\n\n'
104
+ );
105
+
106
+ return result;
107
+ }
108
+ async function runTest(text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', name = 'Lorem ipsum') {
109
+ const result = await test(text, name);
110
+ if (!result) throw new Error('Failed to decompress. decompress(text) != text');
111
+ }
112
+
113
+ const tests = async function () {
114
+ await runTest();
115
+ await runTest('foo'.repeat(1000), 'foo x1000');
116
+ await runTest('ыалалыылаар', 'ыалалыылаар');
117
+ await runTest(String(Math.round(Math.random() * 256000000)), 'random numbers');
118
+ await runTest('asdasdsasdsadsdadsadssssssssssssssssssssыꙮ'.repeat(15), 'absolutely random stuff');
119
+ await runTest('aaaaaaaaaaaaaaa1ыыыыыыыыыыыыыꙮ'.repeat(30), 'should use recursive compression mode');
120
+ }
121
+
122
+ tests().then(()=>{});