@tktb-tess/util-fns 0.9.1 → 0.9.2-alpha.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.
- package/dist/bundle.esm.js +896 -0
- package/dist/bundle.js +2 -896
- package/package.json +5 -5
- package/dist/bundle.umd.cjs +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tktb-tess/util-fns",
|
|
3
|
-
"version": "0.9.1",
|
|
3
|
+
"version": "0.9.2-alpha.1",
|
|
4
4
|
"description": "Utility functions for personal use",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"author": "Tessyrrhaqt",
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"main": "./dist/bundle.
|
|
12
|
-
"module": "./dist/bundle.js",
|
|
11
|
+
"main": "./dist/bundle.js",
|
|
12
|
+
"module": "./dist/bundle.esm.js",
|
|
13
13
|
"types": "./dist/main.d.ts",
|
|
14
14
|
"exports": {
|
|
15
15
|
"types": "./dist/main.d.ts",
|
|
16
|
-
"import": "./dist/bundle.js",
|
|
17
|
-
"require": "./dist/bundle.
|
|
16
|
+
"import": "./dist/bundle.esm.js",
|
|
17
|
+
"require": "./dist/bundle.js"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": "^22",
|
package/dist/bundle.umd.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
(function(c,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(c=typeof globalThis<"u"?globalThis:c||self,p(c.TktbTessUtilFns={}))})(this,(function(c){"use strict";const p=new TextEncoder,x=(n,t)=>[n].includes(t),m=(n,t)=>{if(typeof n!=typeof t)return!1;const e=Object.prototype.toString.call(n),r=Object.prototype.toString.call(t);if(e!==r)return!1;if(typeof n=="string"||typeof n=="bigint"||typeof n=="boolean"||typeof n=="symbol"||n==null)return n===t;if(typeof n=="number")return n!==n&&t!==t||n===t;if(typeof n=="function")return!1;if(Array.isArray(n)&&Array.isArray(t)){if(n.length!==t.length)return!1;for(let s=0;s<n.length;s++)if(!m(n[s],t[s]))return!1;return!0}if(n instanceof Set&&t instanceof Set){const s=[...n.values()],i=[...t.values()];return!!m(s,i)}if(n instanceof Map&&t instanceof Map){const s=[...n.keys()],i=[...t.keys()];if(!m(s,i))return!1;const o=[...n.values()],a=[...t.values()];return!!m(o,a)}if(e==="[object Object]"){const s=n,i=t,o=Object.keys(s),a=Object.keys(i);for(const l of o){const u=a.find(g=>g===l);if(u===void 0)return!1;const[h,d]=[s[l],i[u]];if(!m(h,d))return!1}return!0}throw Error(`comparing these objects is unavailable: ${n}, ${t}`,{cause:[n,t]})},V=()=>{let n,t;return{promise:new Promise((r,s)=>{n=r,t=s}),resolve:n,reject:t}},O=n=>new Promise(t=>{setTimeout(()=>t(),n)}),$=n=>(...t)=>()=>n(...t),k=n=>{const t=[];let e=[],r="",s=!1;for(let i=0;i<n.length;i++){const o=n[i];o==='"'&&(i===0||n[i-1]!=="\\")?s=!s:o===","&&!s?(e.push(r.trim()),r=""):o===`
|
|
2
|
-
`&&!s?(e.push(r.trim()),t.push(e),e=[],r=""):r+=o}return e.push(r.trim()),t.push(e),t},D=async(n,t)=>{const e=p.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},q=()=>!!globalThis.process&&typeof process.version<"u"&&typeof process.versions.node<"u",K=n=>encodeURIComponent(n).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),z=n=>{if(n.includes("+"))throw Error("An input string has '+'");return decodeURIComponent(n)},W=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new CompressionStream(t));return new Response(r).bytes()},J=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(r).bytes()},G=(n,t)=>Math.floor(Math.random()*(t-n)+n),y=(n,t)=>{t<0n&&(t*=-1n);const e=n%t;return e<0n?e+t:e},w=(n,t=!1)=>{if(!Number.isFinite(n))throw Error("`length` is not a valid number");if(n<=0)throw Error("`length` must be positive");const e=Math.ceil(n/8),r=crypto.getRandomValues(new Uint8Array(e));let s=Array.from(r,i=>i.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(s=s.replace(/^\d/,"1")),BigInt("0b"+s)},v=(n,t)=>{if(n>=t)throw Error("rangeError");const e=t-n,r=e.toString(2).length,s=(()=>{for(let o=0;o<1e5;o++){const a=w(r);if(a>=b(2n,BigInt(r),e))return a%e}throw Error("Failed to generate a random bigint")})();return n+s},b=(n,t,e)=>{if(e<1n)throw Error("`mod` must be positive");if(t<0n)throw Error("`power` must not be negative");if(n=y(n,e),e===1n)return 0n;if(n%e===1n||n%e===0n)return n;if(n===e-1n)return t&1n?e-1n:1n;let r=1n;for(;t>0n;)t&1n&&(r=r*n%e),n=n*n%e,t>>=1n;return r},C=(n,t)=>{if(n===0n&&t===0n)return{x:0n,y:0n,gcd:0n};if(n===0n)return t>0n?{x:0n,y:-1n,gcd:t}:{x:0n,y:1n,gcd:-t};if(t===0n)return n>0n?{x:1n,y:0n,gcd:n}:{x:-1n,y:0n,gcd:-n};let[e,r,s]=[1n,0n,n],[i,o,a]=[0n,-1n,t];for(;;){const l=s/a,u=s-l*a;if(u===0n)break;[e,i]=[i,e-l*i],[r,o]=[o,r-l*o],[s,a]=[a,u]}return a<0n&&(i*=-1n,o*=-1n,a*=-1n),{x:i,y:o,gcd:a}},I=(n,t)=>{if(n>=t)return 1n;const e=BigInt((t-2n).toString(2).length),r=(t-n)/2n;if(e*r<63n){let a=n;for(let l=n+2n;l<t;l+=2n)a*=l;return a}const s=n+r|1n,i=I(n,s),o=I(s,t);return i*o},H=n=>{let t=3n,e=1n,r=1n;const s=BigInt(n.toString(2).length)-1n;for(let i=s-1n;i>-1n;--i){const o=(n>>i)+1n|1n;r*=I(t,o),t=o,e*=r}return e},X=n=>{if(n<0n)throw Error("'n' must be non-negative");if(n===0n)return 1n;const t=n-BigInt(n.toString(2).match(/1/g)?.length??0);return H(n)<<t},j=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,S=(n,t)=>BigInt.asUintN(64,n>>(t&63n)|n<<(-t&63n)),B=(n,t)=>{if(t<1n||t%2n===0n)throw Error("`n` is invalid");for(;n<0n;)n+=t;n%=t;let e=1n;for(;n!==0n;){for(;n%2n===0n;){n/=2n;const r=t%8n;(r===3n||r===5n)&&(e*=-1n)}[n,t]=[t,n],n%4n===3n&&t%4n===3n&&(e*=-1n),n%=t}return t===1n?e:0n},_=n=>{if(n<0n)return!1;if(n===0n)return!0;let t=1n,e=n;for(;t+1n<e;){const r=(t+e)/2n;r**2n<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},Y=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;let t=n-1n,e=0n;for(;t%2n===0n;)t>>=1n,e+=1n;const[r,s]=[t,e];let o=b(2n,r,n);if(o===1n)return!0;for(let a=0n;a<s;a++){if(o===n-1n)return!0;o=o*o%n}return!1},Z=n=>{let t=5n,e=B(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&_(n))return[0n,0n];e=B(t,n)}return[t,e]},U=(n,t)=>(n&1n)===1n?y(n+t>>1n,t):y(n>>1n,t),Q=(n,t,e,r)=>{let s=1n,i=e;const o=n.toString(2).slice(1);for(const a of o)[s,i]=[y(s*i,t),U(i*i+r*s*s,t)],a==="1"&&([s,i]=[U(e*s+i,t),U(r*s+e*i,t)]);return[s,i]},tt=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let s=n+1n,i=0n;for(;s%2n===0n;)s>>=1n,i+=1n;const[o,a]=Q(s,n,e,t);let l=a;if(o===0n)return!0;r=b(r,s,n);for(let u=0n;u<i;u++){if(l===0n)return!0;l=y(l*l-2n*r,n),r=b(r,2n,n)}return!1},E=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;const t=[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n];for(const i of t)if(n%i===0n)return n===i;if(!Y(n))return!1;const[e,r]=Z(n);if(r===0n)return!1;const s=(1n-e)/4n;return tt(n,e,1n,s)},nt=(n,t)=>{if(t<2n)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const s=v(n,t);if(E(s))return s}throw Error("noPrimesFound")},et=(n,t=!1)=>{if(n<2)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const s=w(n,t);if(E(s))return s}throw Error("noPrimesFound")};class f{#t;#n;static name="Rational";[Symbol.toStringTag]=f.name;constructor(t,e){e===0n?(this.#n=0n,this.#t=t===0n?0n:t>0n?1n:-1n):e>0n?(this.#t=t,this.#n=e):(this.#t=-t,this.#n=-e),this.#e()}static fromDecimal(t,e=5){if(Number.isNaN(t))return new f(0n,0n);if(Math.abs(t)===1/0)return new f(t>0?1n:-1n,0n);const r=t<0;r&&(t*=-1);const s=BigInt(Math.floor(t)),i=t-Number(s);if(i===0)return new f(r?-s:s,1n);t=1/i;let[o,a]=[1n,s],[l,u]=[0n,1n];for(;`${u}`.length<e+1;){const h=BigInt(Math.floor(t)),d=t-Number(h);if([o,a]=[a,h*a+o],[l,u]=[u,h*u+l],d===0)return new f(r?-a:a,u);t=1/d}return new f(r?-o:o,l)}#e(){const{gcd:t}=C(this.#t,this.#n);t!==0n&&(this.#t/=t,this.#n/=t)}minus(){return new f(-this.#t,this.#n)}inverse(){return new f(this.#n,this.#t)}add(t){const e=this.#n*t.#n,r=this.#t*t.#n+t.#t*this.#n;return new f(r,e)}substr(t){return this.add(t.minus())}multiply(t){const e=this.#n*t.#n,r=this.#t*t.#t;return new f(r,e)}divide(t){return this.multiply(t.inverse())}mediant(t){const e=this.#n+t.#n,r=this.#t+t.#t;return new f(r,e)}toDecimal(){return Number(this.#t)/Number(this.#n)}toString(){return this.#t===0n&&this.#n===0n?"NaN":this.#t===0n?"0":this.#n===0n?this.#t<0n?"-Infinity":"Infinity":this.#n===1n?`${this.#t}`:`${this.#t}/${this.#n}`}valueOf(){return this.toDecimal()}toJSON(){return{type:"Rational",value:["0x"+this.#t.toString(16),"0x"+this.#n.toString(16)]}}static fromData(t){const e=BigInt(t.value[0]),r=BigInt(t.value[1]);return new f(e,r)}static parse(t){const r=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!r)throw Error("cannot parse");const s=r.at(1),i=r.at(2);if(!s||!i)throw Error("cannot parse");return new f(BigInt(s),BigInt(i))}}const rt=new TextEncoder,st=new TextDecoder,it=(n,t)=>{switch(t){case"utf-8":return rt.encode(n);case"base64":return Uint8Array.from(atob(n),e=>e.charCodeAt(0));case"base64url":{const e=n.length&3;return e>0&&(n=n+"=".repeat(4-e)),n=n.replaceAll("-","+").replaceAll("_","/"),Uint8Array.from(atob(n),r=>r.charCodeAt(0))}case"hex":{n.length&1&&(n="0"+n);const r=n.matchAll(/.{2}/g);return Uint8Array.from(r,s=>Number.parseInt(s[0],16))}case"oct":{const e=n.length&7;e&&(n="0".repeat(8-e)+n);const r=n.matchAll(/.{8}/g),i=Array.from(r,o=>{const a=o[0];return Number.parseInt(a,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(i,o=>Number.parseInt(o[0],16))}case"bin":{const e=n.length&7;e&&(n="0".repeat(8-e)+n);const r=n.matchAll(/.{8}/g),s=Array.from(r,i=>Number.parseInt(i[0],2));return Uint8Array.from(s)}default:throw Error(`Invalid encoding: ${t}`,{cause:t})}},ot=(n,t)=>{switch(t){case"utf-8":return st.decode(n);case"base64":{const e=Array.from(n,r=>String.fromCharCode(r)).join("");return btoa(e)}case"base64url":{const e=Array.from(n,s=>String.fromCharCode(s)).join("");return btoa(e).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}case"hex":return Array.from(n,r=>r.toString(16).padStart(2,"0")).join("").replace(/^0+/,"");case"oct":{let e=Array.from(n,o=>o.toString(16).padStart(2,"0")).join("");const r=e.length%6;r&&(e="0".repeat(6-r)+e);const s=e.matchAll(/.{6}/g);return Array.from(s,o=>Number.parseInt(o[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")}case"bin":return Array.from(n,r=>r.toString(2).padStart(8,"0")).join("").replace(/^0+/,"");default:throw Error(`Invalid encoding: ${t}`,{cause:t})}},ct=n=>{const t=n<0n;t&&(n*=-1n);const e=n.toString(2).length,r=n===1n<<BigInt(e-1)&&!(e%7)&&t,s=Math.floor(e/7)+1;return r?s-1:s},at=n=>{const t=ct(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let s=0;s<t-1;++s){const i=Number(n&127n)|128;e[s]=i,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},lt=n=>{const t=n.length;let e=0n;for(let r=0;r<t;++r){const s=BigInt(n[r]&127);e+=s<<BigInt(7*r)}return BigInt.asIntN(7*t,e)};class R{#t;#n;static name="Queue";[Symbol.toStringTag]=R.name;constructor(...t){this.#t=t,this.#n=[]}enqueue(...t){return this.#t.push(...t),this.#t.length+this.#n.length}dequeue(){if(this.#n.length===0)for(;this.#t.length>0;){const t=this.#t.pop();this.#n.push(t)}return this.#n.pop()}toArray(){return this.#n.slice().reverse().concat(this.#t)}toJSON(){return this.toArray()}toString(){return this.toArray().toString()}}class N extends Error{name;static name="NamedError";[Symbol.toStringTag]=N.name;constructor(t,e,r){super(e,{cause:r}),this.name=t}toJSON(){const t=(()=>{const i=this.cause;return typeof i=="string"||typeof i=="number"||typeof i=="boolean"?i:typeof i=="bigint"?i.toString():typeof i=="object"&&i!==null?i instanceof Set||i instanceof Map?Object.fromEntries(i):i:void 0})(),{name:e,message:r,stack:s}=this;return{name:e,message:r,stack:s,cause:t}}}const P=n=>{if(n===0)return 32;let t=0;for(;n>0&&!(n&1);)++t,n>>>=1;return t},F=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)};class A{#t;static name="FloatRand";[Symbol.toStringTag]=A.name;constructor(t){this.#t=t}#n(){const r=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const h=this.#t.getU64Rand()&0xffffffffn;return Number(h)}}})(),s=r&255;let i=126;if(s===0){i-=8;const h=1e5;let d=0;t:for(;;){if(d>h)throw Error("loop exceeded limit");const g=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const L=BigInt.asUintN(32,this.#t.getU64Rand());return Number(L)}}})();if(g===0){if(i-=32,i<0){i=0;break t}}else{i-=P(g);break t}++d}}else i-=P(s);const o=r>>>8&8388607;o===0&&r>>>31&&++i;const{buffer:a,byteOffset:l,length:u}=Uint32Array.from([i<<23|o]);return new Float32Array(a,l,u)[0]}getF32Rand(){for(let e=0;e<1e5;++e){const r=this.#n();if(r<1)return r}throw Error("exceeded loop limit")}#e(){const t=0n,e=1023n,r=(()=>{switch(this.#t.bits){case 32:{const h=BigInt(this.#t.getU32Rand()>>>0),d=BigInt(this.#t.getU32Rand()>>>0);return h<<32n|d}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})(),s=r&0x7ffn;let i=e-1n;if(s===0n){i-=11n;const h=1e5;let d=0;t:for(;;){if(d>h)throw Error("loop exceeded limit");const g=(()=>{switch(this.#t.bits){case 32:{const L=BigInt(this.#t.getU32Rand()>>>0),dt=BigInt(this.#t.getU32Rand()>>>0);return L<<32n|dt}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})();if(g===0n){if(i-=64n,i<t){i=t;break t}}else{i-=F(g);break t}++d}}else i-=F(s);const o=BigInt.asUintN(52,r>>11n);o===0n&&r>>63n&&++i;const{buffer:a,byteOffset:l,length:u}=BigUint64Array.from([i<<52n|o]);return new Float64Array(a,l,u)[0]}getF64Rand(){for(let e=0;e<1e5;++e){const r=this.#e();if(r<1)return r}throw Error("exceeded loop limit")}}const ut=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],ft=0x5851f42d4c957f2dn;class T{#t;static name="PCGMinimal";[Symbol.toStringTag]=T.name;bits=32;constructor(t){t&&t.length>=2?(this.#t=new BigUint64Array(2),this.#t[1]=t[1]<<1n|1n,this.#n(),this.#t[0]+=t[0],this.#n()):this.#t=BigUint64Array.from(ut)}#n(){this.#t[0]=this.#t[0]*ft+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return j(r,e)}getU32Rand(){return this.#n(),this.#e}getBoundedU32Rand(t){if(t>4294967296)throw Error("`bound` exceeded limit (2^32)");if(t<=0)throw Error("'bound' must be positive");const r=4294967296%t,s=1e5;for(let i=0;i<s;++i){const o=this.getU32Rand();if(o>=r)return o%t}throw Error("exceeded loop limit")}*genU32Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;r++)yield typeof e=="number"?this.getBoundedU32Rand(e):this.getU32Rand()}}const ht=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class M{bits=64;#t;static name="XoshiroMinimal";[Symbol.toStringTag]=M.name;constructor(t){t&&t.length>=4?(this.#t=new BigUint64Array(4),this.#t[0]=t[0],this.#t[1]=t[1],this.#n(),this.#t[2]+=t[2],this.#t[3]+=t[3]):this.#t=BigUint64Array.from(ht)}#n(){const t=this.#t[1]<<17n;this.#t[2]^=this.#t[0],this.#t[3]^=this.#t[1],this.#t[1]^=this.#t[2],this.#t[0]^=this.#t[3],this.#t[2]^=t,this.#t[3]=S(this.#t[3],45n)}get value(){return S(this.#t[0]+this.#t[3],23n)+this.#t[0]}getU64Rand(){const t=this.value;return this.#n(),t}getU32Rand(){const t=BigInt.asUintN(32,this.getU64Rand());return Number(t)}getBoundedU64Rand(t){const e=1n<<64n;if(t>e)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=e%t,s=1e5;for(let i=0;i<s;++i){const o=this.getU64Rand();if(o>=r)return o%t}throw Error("exceeded loop limit")}getBoundedU32Rand(t){if(t>4294967296)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=this.getBoundedU64Rand(BigInt(t));return Number(r)}*genU64Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getU64Rand():this.getBoundedU64Rand(e)}*genU32Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getU32Rand():this.getBoundedU32Rand(e)}}c.FloatRng=A,c.NamedError=N,c.PCGMinimal=T,c.Queue=R,c.Rational=f,c.XoshiroMinimal=M,c.bailliePSW=E,c.compress=W,c.decodeLEB128=lt,c.decodeRFC3986URIComponent=z,c.decompress=J,c.encodeLEB128=at,c.encodeRFC3986URIComponent=K,c.exEuclidean=C,c.factorial=X,c.fromString=it,c.getHash=D,c.getRandBIByBitLength=w,c.getRandBIByRange=v,c.getRandPrimeByBitLength=et,c.getRandPrimeByRange=nt,c.getRndInt=G,c.isDeepStrictEqual=m,c.isNode=q,c.isSquare=_,c.jacobiSymbol=B,c.lazify=$,c.modPow=b,c.parseCSV=k,c.promiseWithResolvers=V,c.residue=y,c.rot32=j,c.rot64=S,c.sameValueZero=x,c.sleep=O,c.toString=ot,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
|