@tktb-tess/util-fns 0.10.0 → 0.10.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.js CHANGED
@@ -470,18 +470,17 @@ const $ = (n) => {
470
470
  return BigInt.asIntN(7 * t, e);
471
471
  };
472
472
  class U extends Error {
473
- name;
474
- static name = "NamedError";
475
473
  constructor(t, e, r) {
476
- super(e, { cause: r }), this.name = t;
474
+ super(e, { cause: r }), this.errName = t;
477
475
  }
476
+ static name = "NamedError";
478
477
  toJSON() {
479
478
  const t = (() => {
480
479
  const s = this.cause;
481
480
  return typeof s == "string" || typeof s == "number" || typeof s == "boolean" ? s : typeof s == "bigint" ? s.toString() : typeof s == "object" && s !== null ? s instanceof Set || s instanceof Map ? Object.fromEntries(s) : s : void 0;
482
- })(), { name: e, message: r, stack: o } = this;
481
+ })(), { errName: e, message: r, stack: o } = this;
483
482
  return {
484
- name: e,
483
+ errName: e,
485
484
  message: r,
486
485
  stack: o,
487
486
  cause: t
@@ -504,7 +503,7 @@ const E = (n) => {
504
503
  ++t, n >>= 1n;
505
504
  return BigInt.asUintN(64, t);
506
505
  };
507
- class R {
506
+ class N {
508
507
  #t;
509
508
  static name = "FloatRng";
510
509
  constructor(t) {
@@ -633,11 +632,11 @@ class R {
633
632
  throw Error("exceeded loop limit");
634
633
  }
635
634
  }
636
- Object.defineProperty(R.prototype, Symbol.toStringTag, {
637
- value: R.name
635
+ Object.defineProperty(N.prototype, Symbol.toStringTag, {
636
+ value: N.name
638
637
  });
639
638
  const q = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], G = 0x5851f42d4c957f2dn;
640
- class N {
639
+ class R {
641
640
  /**
642
641
  * length = 2, `[state, increment]`
643
642
  */
@@ -706,8 +705,8 @@ class N {
706
705
  yield typeof e == "number" ? this.getBoundedU32Rand(e) : this.getU32Rand();
707
706
  }
708
707
  }
709
- Object.defineProperty(N.prototype, Symbol.toStringTag, {
710
- value: N.name
708
+ Object.defineProperty(R.prototype, Symbol.toStringTag, {
709
+ value: R.name
711
710
  });
712
711
  const z = [
713
712
  0xbe562cb412e2260en,
@@ -790,9 +789,9 @@ Object.defineProperty(x.prototype, Symbol.toStringTag, {
790
789
  value: x.name
791
790
  });
792
791
  export {
793
- R as FloatRng,
792
+ N as FloatRng,
794
793
  U as NamedError,
795
- N as PCGMinimal,
794
+ R as PCGMinimal,
796
795
  a as Rational,
797
796
  x as XoshiroMinimal,
798
797
  T as bailliePSW,
@@ -1,2 +1,2 @@
1
1
  var UtilFns=(function(c){"use strict";const F=new TextEncoder,V=(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 i=0;i<n.length;i++)if(!m(n[i],t[i]))return!1;return!0}if(n instanceof Set&&t instanceof Set){const i=[...n.values()],s=[...t.values()];return!!m(i,s)}if(n instanceof Map&&t instanceof Map){const i=[...n.keys()],s=[...t.keys()];if(!m(i,s))return!1;const o=[...n.values()],a=[...t.values()];return!!m(o,a)}if(e==="[object Object]"){const i=n,s=t,o=Object.keys(i),a=Object.keys(s);for(const l of o){const f=a.find(g=>g===l);if(f===void 0)return!1;const[h,d]=[i[l],s[f]];if(!m(h,d))return!1}return!0}throw Error(`comparing these objects is unavailable: ${n}, ${t}`,{cause:[n,t]})},k=()=>{let n,t;return{promise:new Promise((r,i)=>{n=r,t=i}),resolve:n,reject:t}},$=n=>new Promise(t=>{setTimeout(()=>t(),n)}),D=n=>Object.prototype.toString.call(n).match(/^\[Object\s(.+)\]$/)?.at(1),q=n=>(...t)=>()=>n(...t),K=n=>{const t=[];let e=[],r="",i=!1;for(let s=0;s<n.length;s++){const o=n[s];o==='"'&&(s===0||n[s-1]!=="\\")?i=!i:o===","&&!i?(e.push(r.trim()),r=""):o===`
2
- `&&!i?(e.push(r.trim()),t.push(e),e=[],r=""):r+=o}return e.push(r.trim()),t.push(e),t},G=async(n,t)=>{const e=F.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},z=()=>!!globalThis.process&&typeof process.version<"u"&&typeof process.versions.node<"u",W=n=>encodeURIComponent(n).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),X=n=>{if(n.includes("+"))throw Error("An input string has '+'");return decodeURIComponent(n)},H=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()},Y=(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},I=(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 i=Array.from(r,s=>s.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(i=i.replace(/^\d/,"1")),BigInt("0b"+i)},T=(n,t)=>{if(n>=t)throw Error("rangeError");const e=t-n,r=e.toString(2).length,i=(()=>{for(let o=0;o<1e5;o++){const a=I(r);if(a>=p(2n,BigInt(r),e))return a%e}throw Error("Failed to generate a random bigint")})();return n+i},p=(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},A=(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,i]=[1n,0n,n],[s,o,a]=[0n,-1n,t];for(;;){const l=i/a,f=i-l*a;if(f===0n)break;[e,s]=[s,e-l*s],[r,o]=[o,r-l*o],[i,a]=[a,f]}return a<0n&&(s*=-1n,o*=-1n,a*=-1n),{x:s,y:o,gcd:a}},w=(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 i=n+r|1n,s=w(n,i),o=w(i,t);return s*o},Z=n=>{let t=3n,e=1n,r=1n;const i=BigInt(n.toString(2).length)-1n;for(let s=i-1n;s>-1n;--s){const o=(n>>s)+1n|1n;r*=w(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 Z(n)<<t},v=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,b=(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},P=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},Q=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,i]=[t,e];let o=p(2n,r,n);if(o===1n)return!0;for(let a=0n;a<i;a++){if(o===n-1n)return!0;o=o*o%n}return!1},tt=n=>{let t=5n,e=B(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&P(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),nt=(n,t,e,r)=>{let i=1n,s=e;const o=n.toString(2).slice(1);for(const a of o)[i,s]=[y(i*s,t),U(s*s+r*i*i,t)],a==="1"&&([i,s]=[U(e*i+s,t),U(r*i+e*s,t)]);return[i,s]},et=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let i=n+1n,s=0n;for(;i%2n===0n;)i>>=1n,s+=1n;const[o,a]=nt(i,n,e,t);let l=a;if(o===0n)return!0;r=p(r,i,n);for(let f=0n;f<s;f++){if(l===0n)return!0;l=y(l*l-2n*r,n),r=p(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 s of t)if(n%s===0n)return n===s;if(!Q(n))return!1;const[e,r]=tt(n);if(r===0n)return!1;const i=(1n-e)/4n;return et(n,e,1n,i)},rt=(n,t)=>{if(t<2n)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=T(n,t);if(E(i))return i}throw Error("noPrimesFound")},st=(n,t=!1)=>{if(n<2)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=I(n,t);if(E(i))return i}throw Error("noPrimesFound")};class u{#t;#n;static name="Rational";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 u(0n,0n);if(Math.abs(t)===1/0)return new u(t>0?1n:-1n,0n);const r=t<0;r&&(t*=-1);const i=BigInt(Math.floor(t)),s=t-Number(i);if(s===0)return new u(r?-i:i,1n);t=1/s;let[o,a]=[1n,i],[l,f]=[0n,1n];for(;`${f}`.length<e+1;){const h=BigInt(Math.floor(t)),d=t-Number(h);if([o,a]=[a,h*a+o],[l,f]=[f,h*f+l],d===0)return new u(r?-a:a,f);t=1/d}return new u(r?-o:o,l)}#e(){const{gcd:t}=A(this.#t,this.#n);t!==0n&&(this.#t/=t,this.#n/=t)}minus(){return new u(-this.#t,this.#n)}inverse(){return new u(this.#n,this.#t)}add(t){const e=this.#n*t.#n,r=this.#t*t.#n+t.#t*this.#n;return new u(r,e)}substr(t){return this.add(t.minus())}multiply(t){const e=this.#n*t.#n,r=this.#t*t.#t;return new u(r,e)}divide(t){return this.multiply(t.inverse())}mediant(t){const e=this.#n+t.#n,r=this.#t+t.#t;return new u(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 u(e,r)}static parse(t){const r=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!r)throw Error("cannot parse");const i=r.at(1),s=r.at(2);if(!i||!s)throw Error("cannot parse");return new u(BigInt(i),BigInt(s))}}Object.defineProperty(u.prototype,Symbol.toStringTag,{value:u.name});const j=n=>{const t=Array.from(n,e=>String.fromCharCode(e));return btoa(t.join(""))},C=n=>{const t=atob(n);return Uint8Array.from(t,e=>e.charCodeAt(0))},it=n=>j(n).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""),ot=n=>{const t=n.length&3;t>0&&(n=n+"=".repeat(4-t));const e=n.replaceAll("-","+").replaceAll("_","/");return C(e)},ct=n=>{let t=Array.from(n,s=>s.toString(16).padStart(2,"0")).join("");const e=t.length%6;e&&(t="0".repeat(6-e)+t);const r=t.matchAll(/.{6}/g);return Array.from(r,s=>Number.parseInt(s[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")},at=n=>{const t=n.length&7;t&&(n="0".repeat(8-t)+n);const e=n.matchAll(/.{8}/g),i=Array.from(e,s=>{const o=s[0];return Number.parseInt(o,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(i,s=>Number.parseInt(s[0],16))},lt=n=>{const t=n<0n;t&&(n*=-1n);const e=n.toString(2).length,r=n===1n<<BigInt(e-1)&&!(e%7)&&t,i=Math.floor(e/7)+1;return r?i-1:i},ft=n=>{const t=lt(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let i=0;i<t-1;++i){const s=Number(n&127n)|128;e[i]=s,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},ut=n=>{const t=n.length;let e=0n;for(let r=0;r<t;++r){const i=BigInt(n[r]&127);e+=i<<BigInt(7*r)}return BigInt.asIntN(7*t,e)};class S extends Error{name;static name="NamedError";constructor(t,e,r){super(e,{cause:r}),this.name=t}toJSON(){const t=(()=>{const s=this.cause;return typeof s=="string"||typeof s=="number"||typeof s=="boolean"?s:typeof s=="bigint"?s.toString():typeof s=="object"&&s!==null?s instanceof Set||s instanceof Map?Object.fromEntries(s):s:void 0})(),{name:e,message:r,stack:i}=this;return{name:e,message:r,stack:i,cause:t}}}Object.defineProperty(S.prototype,Symbol.toStringTag,{value:S.name});const O=n=>{if(n===0)return 32;let t=0;for(;n>0&&!(n&1);)++t,n>>>=1;return t},_=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)};class R{#t;static name="FloatRng";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)}}})(),i=r&255;let s=126;if(i===0){s-=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 M=BigInt.asUintN(32,this.#t.getU64Rand());return Number(M)}}})();if(g===0){if(s-=32,s<0){s=0;break t}}else{s-=O(g);break t}++d}}else s-=O(i);const o=r>>>8&8388607;o===0&&r>>>31&&++s;const{buffer:a,byteOffset:l,length:f}=Uint32Array.from([s<<23|o]);return new Float32Array(a,l,f)[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())}})(),i=r&0x7ffn;let s=e-1n;if(i===0n){s-=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 M=BigInt(this.#t.getU32Rand()>>>0),mt=BigInt(this.#t.getU32Rand()>>>0);return M<<32n|mt}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})();if(g===0n){if(s-=64n,s<t){s=t;break t}}else{s-=_(g);break t}++d}}else s-=_(i);const o=BigInt.asUintN(52,r>>11n);o===0n&&r>>63n&&++s;const{buffer:a,byteOffset:l,length:f}=BigUint64Array.from([s<<52n|o]);return new Float64Array(a,l,f)[0]}getF64Rand(){for(let e=0;e<1e5;++e){const r=this.#e();if(r<1)return r}throw Error("exceeded loop limit")}}Object.defineProperty(R.prototype,Symbol.toStringTag,{value:R.name});const ht=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],dt=0x5851f42d4c957f2dn;class N{#t;static name="PCGMinimal";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(ht)}#n(){this.#t[0]=this.#t[0]*dt+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return v(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,i=1e5;for(let s=0;s<i;++s){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()}}Object.defineProperty(N.prototype,Symbol.toStringTag,{value:N.name});const gt=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class L{bits=64;#t;static name="XoshiroMinimal";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(gt)}#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]=b(this.#t[3],45n)}get value(){const t=b(this.#t[0]+this.#t[3],23n)+this.#t[0];return BigInt.asUintN(64,t)}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,i=1e5;for(let s=0;s<i;++s){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)}}return Object.defineProperty(L.prototype,Symbol.toStringTag,{value:L.name}),c.FloatRng=R,c.NamedError=S,c.PCGMinimal=N,c.Rational=u,c.XoshiroMinimal=L,c.bailliePSW=E,c.compress=H,c.decodeLEB128=ut,c.decodeRFC3986URIComponent=X,c.decompress=J,c.encodeLEB128=ft,c.encodeRFC3986URIComponent=W,c.exEuclidean=A,c.factorial=x,c.fromBase64=C,c.fromBase64Url=ot,c.fromOct=at,c.getHash=G,c.getRandBIByBitLength=I,c.getRandBIByRange=T,c.getRandPrimeByBitLength=st,c.getRandPrimeByRange=rt,c.getRndInt=Y,c.getStringTag=D,c.isDeepStrictEqual=m,c.isNode=z,c.isSquare=P,c.jacobiSymbol=B,c.lazify=q,c.modPow=p,c.parseCSV=K,c.promiseWithResolvers=k,c.residue=y,c.rot32=v,c.rot64=b,c.sameValueZero=V,c.sleep=$,c.toBase64=j,c.toBase64Url=it,c.toOct=ct,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),c})({});
2
+ `&&!i?(e.push(r.trim()),t.push(e),e=[],r=""):r+=o}return e.push(r.trim()),t.push(e),t},G=async(n,t)=>{const e=F.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},z=()=>!!globalThis.process&&typeof process.version<"u"&&typeof process.versions.node<"u",W=n=>encodeURIComponent(n).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),X=n=>{if(n.includes("+"))throw Error("An input string has '+'");return decodeURIComponent(n)},H=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()},Y=(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},I=(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 i=Array.from(r,s=>s.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(i=i.replace(/^\d/,"1")),BigInt("0b"+i)},T=(n,t)=>{if(n>=t)throw Error("rangeError");const e=t-n,r=e.toString(2).length,i=(()=>{for(let o=0;o<1e5;o++){const a=I(r);if(a>=p(2n,BigInt(r),e))return a%e}throw Error("Failed to generate a random bigint")})();return n+i},p=(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},A=(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,i]=[1n,0n,n],[s,o,a]=[0n,-1n,t];for(;;){const l=i/a,f=i-l*a;if(f===0n)break;[e,s]=[s,e-l*s],[r,o]=[o,r-l*o],[i,a]=[a,f]}return a<0n&&(s*=-1n,o*=-1n,a*=-1n),{x:s,y:o,gcd:a}},w=(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 i=n+r|1n,s=w(n,i),o=w(i,t);return s*o},Z=n=>{let t=3n,e=1n,r=1n;const i=BigInt(n.toString(2).length)-1n;for(let s=i-1n;s>-1n;--s){const o=(n>>s)+1n|1n;r*=w(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 Z(n)<<t},v=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,b=(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},P=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},Q=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,i]=[t,e];let o=p(2n,r,n);if(o===1n)return!0;for(let a=0n;a<i;a++){if(o===n-1n)return!0;o=o*o%n}return!1},tt=n=>{let t=5n,e=B(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&P(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),nt=(n,t,e,r)=>{let i=1n,s=e;const o=n.toString(2).slice(1);for(const a of o)[i,s]=[y(i*s,t),U(s*s+r*i*i,t)],a==="1"&&([i,s]=[U(e*i+s,t),U(r*i+e*s,t)]);return[i,s]},et=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let i=n+1n,s=0n;for(;i%2n===0n;)i>>=1n,s+=1n;const[o,a]=nt(i,n,e,t);let l=a;if(o===0n)return!0;r=p(r,i,n);for(let f=0n;f<s;f++){if(l===0n)return!0;l=y(l*l-2n*r,n),r=p(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 s of t)if(n%s===0n)return n===s;if(!Q(n))return!1;const[e,r]=tt(n);if(r===0n)return!1;const i=(1n-e)/4n;return et(n,e,1n,i)},rt=(n,t)=>{if(t<2n)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=T(n,t);if(E(i))return i}throw Error("noPrimesFound")},st=(n,t=!1)=>{if(n<2)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=I(n,t);if(E(i))return i}throw Error("noPrimesFound")};class u{#t;#n;static name="Rational";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 u(0n,0n);if(Math.abs(t)===1/0)return new u(t>0?1n:-1n,0n);const r=t<0;r&&(t*=-1);const i=BigInt(Math.floor(t)),s=t-Number(i);if(s===0)return new u(r?-i:i,1n);t=1/s;let[o,a]=[1n,i],[l,f]=[0n,1n];for(;`${f}`.length<e+1;){const h=BigInt(Math.floor(t)),d=t-Number(h);if([o,a]=[a,h*a+o],[l,f]=[f,h*f+l],d===0)return new u(r?-a:a,f);t=1/d}return new u(r?-o:o,l)}#e(){const{gcd:t}=A(this.#t,this.#n);t!==0n&&(this.#t/=t,this.#n/=t)}minus(){return new u(-this.#t,this.#n)}inverse(){return new u(this.#n,this.#t)}add(t){const e=this.#n*t.#n,r=this.#t*t.#n+t.#t*this.#n;return new u(r,e)}substr(t){return this.add(t.minus())}multiply(t){const e=this.#n*t.#n,r=this.#t*t.#t;return new u(r,e)}divide(t){return this.multiply(t.inverse())}mediant(t){const e=this.#n+t.#n,r=this.#t+t.#t;return new u(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 u(e,r)}static parse(t){const r=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!r)throw Error("cannot parse");const i=r.at(1),s=r.at(2);if(!i||!s)throw Error("cannot parse");return new u(BigInt(i),BigInt(s))}}Object.defineProperty(u.prototype,Symbol.toStringTag,{value:u.name});const j=n=>{const t=Array.from(n,e=>String.fromCharCode(e));return btoa(t.join(""))},C=n=>{const t=atob(n);return Uint8Array.from(t,e=>e.charCodeAt(0))},it=n=>j(n).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""),ot=n=>{const t=n.length&3;t>0&&(n=n+"=".repeat(4-t));const e=n.replaceAll("-","+").replaceAll("_","/");return C(e)},ct=n=>{let t=Array.from(n,s=>s.toString(16).padStart(2,"0")).join("");const e=t.length%6;e&&(t="0".repeat(6-e)+t);const r=t.matchAll(/.{6}/g);return Array.from(r,s=>Number.parseInt(s[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")},at=n=>{const t=n.length&7;t&&(n="0".repeat(8-t)+n);const e=n.matchAll(/.{8}/g),i=Array.from(e,s=>{const o=s[0];return Number.parseInt(o,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(i,s=>Number.parseInt(s[0],16))},lt=n=>{const t=n<0n;t&&(n*=-1n);const e=n.toString(2).length,r=n===1n<<BigInt(e-1)&&!(e%7)&&t,i=Math.floor(e/7)+1;return r?i-1:i},ft=n=>{const t=lt(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let i=0;i<t-1;++i){const s=Number(n&127n)|128;e[i]=s,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},ut=n=>{const t=n.length;let e=0n;for(let r=0;r<t;++r){const i=BigInt(n[r]&127);e+=i<<BigInt(7*r)}return BigInt.asIntN(7*t,e)};class S extends Error{constructor(t,e,r){super(e,{cause:r}),this.errName=t}static name="NamedError";toJSON(){const t=(()=>{const s=this.cause;return typeof s=="string"||typeof s=="number"||typeof s=="boolean"?s:typeof s=="bigint"?s.toString():typeof s=="object"&&s!==null?s instanceof Set||s instanceof Map?Object.fromEntries(s):s:void 0})(),{errName:e,message:r,stack:i}=this;return{errName:e,message:r,stack:i,cause:t}}}Object.defineProperty(S.prototype,Symbol.toStringTag,{value:S.name});const O=n=>{if(n===0)return 32;let t=0;for(;n>0&&!(n&1);)++t,n>>>=1;return t},_=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)};class R{#t;static name="FloatRng";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)}}})(),i=r&255;let s=126;if(i===0){s-=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 M=BigInt.asUintN(32,this.#t.getU64Rand());return Number(M)}}})();if(g===0){if(s-=32,s<0){s=0;break t}}else{s-=O(g);break t}++d}}else s-=O(i);const o=r>>>8&8388607;o===0&&r>>>31&&++s;const{buffer:a,byteOffset:l,length:f}=Uint32Array.from([s<<23|o]);return new Float32Array(a,l,f)[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())}})(),i=r&0x7ffn;let s=e-1n;if(i===0n){s-=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 M=BigInt(this.#t.getU32Rand()>>>0),mt=BigInt(this.#t.getU32Rand()>>>0);return M<<32n|mt}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})();if(g===0n){if(s-=64n,s<t){s=t;break t}}else{s-=_(g);break t}++d}}else s-=_(i);const o=BigInt.asUintN(52,r>>11n);o===0n&&r>>63n&&++s;const{buffer:a,byteOffset:l,length:f}=BigUint64Array.from([s<<52n|o]);return new Float64Array(a,l,f)[0]}getF64Rand(){for(let e=0;e<1e5;++e){const r=this.#e();if(r<1)return r}throw Error("exceeded loop limit")}}Object.defineProperty(R.prototype,Symbol.toStringTag,{value:R.name});const ht=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],dt=0x5851f42d4c957f2dn;class N{#t;static name="PCGMinimal";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(ht)}#n(){this.#t[0]=this.#t[0]*dt+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return v(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,i=1e5;for(let s=0;s<i;++s){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()}}Object.defineProperty(N.prototype,Symbol.toStringTag,{value:N.name});const gt=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class L{bits=64;#t;static name="XoshiroMinimal";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(gt)}#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]=b(this.#t[3],45n)}get value(){const t=b(this.#t[0]+this.#t[3],23n)+this.#t[0];return BigInt.asUintN(64,t)}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,i=1e5;for(let s=0;s<i;++s){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)}}return Object.defineProperty(L.prototype,Symbol.toStringTag,{value:L.name}),c.FloatRng=R,c.NamedError=S,c.PCGMinimal=N,c.Rational=u,c.XoshiroMinimal=L,c.bailliePSW=E,c.compress=H,c.decodeLEB128=ut,c.decodeRFC3986URIComponent=X,c.decompress=J,c.encodeLEB128=ft,c.encodeRFC3986URIComponent=W,c.exEuclidean=A,c.factorial=x,c.fromBase64=C,c.fromBase64Url=ot,c.fromOct=at,c.getHash=G,c.getRandBIByBitLength=I,c.getRandBIByRange=T,c.getRandPrimeByBitLength=st,c.getRandPrimeByRange=rt,c.getRndInt=Y,c.getStringTag=D,c.isDeepStrictEqual=m,c.isNode=z,c.isSquare=P,c.jacobiSymbol=B,c.lazify=q,c.modPow=p,c.parseCSV=K,c.promiseWithResolvers=k,c.residue=y,c.rot32=v,c.rot64=b,c.sameValueZero=V,c.sleep=$,c.toBase64=j,c.toBase64Url=it,c.toOct=ct,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),c})({});
@@ -4,11 +4,11 @@ interface NamedError<EName extends string> {
4
4
  readonly cause?: unknown;
5
5
  }
6
6
  declare class NamedError<EName extends string> extends Error {
7
- readonly name: EName;
7
+ readonly errName: EName;
8
8
  static readonly name = "NamedError";
9
- constructor(name: EName, message: string, cause?: unknown);
9
+ constructor(errName: EName, message: string, cause?: unknown);
10
10
  toJSON(): {
11
- name: EName;
11
+ errName: EName;
12
12
  message: string;
13
13
  stack: string | undefined;
14
14
  cause: string | number | boolean | object | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tktb-tess/util-fns",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Utility functions for personal use",
5
5
  "files": [
6
6
  "dist"
@@ -26,12 +26,12 @@
26
26
  },
27
27
  "homepage": "https://github.com/tktb-tess/util-fns/blob/main/README.md",
28
28
  "devDependencies": {
29
- "@types/node": "^24.6.2",
30
- "tsx": "^4.20.6",
29
+ "@types/node": "^24.10.2",
30
+ "tsx": "^4.21.0",
31
31
  "typescript": "^5.9.3",
32
- "vite": "^7.1.9",
32
+ "vite": "^7.2.7",
33
33
  "vite-plugin-dts": "^4.5.4",
34
- "vitest": "^3.2.4"
34
+ "vitest": "^4.0.15"
35
35
  },
36
36
  "volta": {
37
37
  "node": "22.21.0"