-
Notifications
You must be signed in to change notification settings - Fork 9
/
mudder.min.mjs
2 lines (2 loc) · 5.27 KB
/
mudder.min.mjs
1
2
var y={},u={get exports(){return y},set exports(e){y=e}};function T(e){for(let t of e)for(let n of e)if(n!==t&&t.startsWith(n))return!1;return!0}function A(e){e=Array.from(e).sort();for(let[t,n]of e.entries()){let r=e[t-1];if(r!==n&&n.startsWith(r))return!1}return!0}T=A;function a(e,t){"use strict";if(typeof this>"u")throw new TypeError("constructor called as a function");if(typeof e=="string")e=e.split("");else if(!Array.isArray(e))throw new TypeError("symbolsArr must be string or array");if(typeof t>"u")t=new Map(e.map((r,o)=>[r,o]));else if(t instanceof Object&&!(t instanceof Map))t=new Map(Object.entries(t));else if(!(t instanceof Map))throw new TypeError("symbolsMap can be omitted, a Map, or an Object");let n=new Set(t.values());for(let r=0;r<e.length;r++)if(!n.has(r))throw new RangeError(e.length+" symbols given but "+r+" not found in symbol table");this.num2sym=e,this.sym2num=t,this.maxBase=this.num2sym.length,this.isPrefixCode=T(e)}a.prototype.numberToDigits=function(e,t){t=t||this.maxBase;let n=[];for(;e>=1;)n.push(e%t),e=Math.floor(e/t);return n.length?n.reverse():[0]};a.prototype.digitsToString=function(e){return e.map(t=>this.num2sym[t]).join("")};a.prototype.stringToDigits=function(e){if(!this.isPrefixCode&&typeof e=="string")throw new TypeError("parsing string without prefix code is unsupported. Pass in array of stringy symbols?");if(typeof e=="string"){let t=new RegExp("("+Array.from(this.sym2num.keys()).join("|")+")","g");e=e.match(t)}return e.map(t=>this.sym2num.get(t))};a.prototype.digitsToNumber=function(e,t){t=t||this.maxBase;let n=1;return e.reduceRight((r,o)=>{let i=r+o*n;return n*=t,i},0)};a.prototype.numberToString=function(e,t){return this.digitsToString(this.numberToDigits(e,t))};a.prototype.stringToNumber=function(e,t){return this.digitsToNumber(this.stringToDigits(e),t)};function m(e,t,n){return e.reduce((r,o)=>{let i=o+r.rem*n;return{res:r.res.concat(Math.floor(i/t)),rem:i%t,den:t}},{res:[],rem:0,den:t})}function x(e,t,n,r=[],o=0){if(e.length!==t.length)throw new Error("same length arrays needed");if(r.length!==0&&r.length!==2)throw new Error("zero or two remainders expected");e=e.slice(),r.length&&(e=e.concat(r[0]),t=t.slice().concat(r[1]));let i=Array(e.length).fill(0);e:for(let s=e.length-1;s>=0;--s){if(e[s]>=t[s]){i[s]=e[s]-t[s];continue}if(s===0)throw new Error("cannot go negative");for(let c=s-1;c>=0;--c)if(e[c]>0){e[c]--;for(let l=c+1;l<s;++l)e[l]+=n-1;i[s]=e[s]+(r.length>0&&s===e.length-1?o:n)-t[s];continue e}throw new Error("failed to find digit to borrow from")}return r.length?{res:i.slice(0,-1),rem:i[i.length-1],den:o}:{res:i,rem:0,den:o}}function w(e,t,n,r,o){if(e.length!==t.length)throw new Error("same length arrays needed");let i=r>=o,s=t.slice();return i&&(r-=o),e.reduceRight((c,l,h)=>{let f=l+t[h]+i;i=f>=n,s[h]=i?f-n:f},null),{res:s,carry:i,rem:r,den:o}}function v(e,t,n){let r=Math.max(0,t-e.length);return e.concat(Array(r).fill(n||0))}function _(e,t,n,r,o){if(e.length<t.length?e=v(e,t.length):t.length<e.length&&(t=v(t,e.length)),e.length===t.length&&e.every((f,d)=>f===t[d]))throw new Error("Start and end strings lexicographically inseparable");let i=m(e,o,n),s=m(t,o,n),c=x(e,i.res,n,[0,i.rem],o),l=s,h=[];for(let f=1;f<=r;++f){let d=w(c.res,l.res,n,c.rem+l.rem,o);h.push(d),c=x(c.res,i.res,n,[c.rem,i.rem],o),l=w(l.res,s.res,n,l.rem+s.rem,o)}return h}function S(e,t,n){let r=Math.max(0,t-e.length);return Array(r).fill(n||0).concat(e)}a.prototype.roundFraction=function(e,t,n){n=n||this.maxBase;var r=Math.ceil(Math.log(t)/Math.log(n)),o=Math.pow(n,r),i=Math.round(e/t*o),s=this.numberToDigits(i,n);return S(s,r,0)};function j(e,t,n=0){for(let r=n;r<t.length;r++)if(t[r]&&e[r]!==t[r])return t.slice(0,r+1);return t}function L(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!==t[r])return e[r]<t[r];return e.length<t.length}function C(e,t=0){let n=!L(e[0],e[1]);n&&e.reverse();let r=e.slice(1).reduce((o,i)=>o.concat([j(o[o.length-1],i,t)]),[e[0]]);return n&&r.reverse(),r}function P(e,t){let n=e>t;return n&&([e,t]=[t,e]),n?[t,e]:[e,t]}a.prototype.mudder=function(e,t,n,r,o,i=0){typeof e=="number"&&(n=e,e="",t=""),e=e||this.num2sym[0],t=t||this.num2sym[this.num2sym.length-1].repeat(e.length+6),n=typeof n=="number"?n:1,r=r||this.maxBase,o=o||n+1,[e,t]=P(e,t);let s=this.stringToDigits(e,r),c=this.stringToDigits(t,r),h=_(s,c,r,n,o).map(f=>f.res.concat(this.roundFraction(f.rem,f.den,r)));return h.unshift(s),h.push(c),C(h,i).slice(1,h.length-1).map(f=>this.digitsToString(f))};var g=(e,t)=>Array.from(Array(t),(n,r)=>String.fromCharCode(e.charCodeAt(0)+r)),B=new a(g("0",10).concat(g("A",26)).concat(g("a",26))),D=g("0",10).concat(g("a",26)),M=D.concat(g("A",26));function p(e){return Array.from(Array(e),(t,n)=>n)}var O=p(10).concat(p(26).map(e=>e+10)).concat(p(26).map(e=>e+10));function E(e,t){return Array.from(Array(e.length),(n,r)=>[e[r],t[r]])}var k=new a(D,new Map(E(M,O))),N=new a(g("a",26),new Map(E(g("a",26).concat(g("A",26)),p(26).concat(p(26)))));u.exports={SymbolTable:a,base62:B,base36:k,alphabet:N,longLinspace:_};var R,z,F,W,H;Object.isExtensible(u.exports)&&Object.keys(u.exports).length===5&&(R=u.exports.SymbolTable,z=u.exports.base62,F=u.exports.base36,W=u.exports.alphabet,H=u.exports.longLinspace);var V=u.exports;export{R as SymbolTable,W as alphabet,F as base36,z as base62,V as default,H as longLinspace};
//# sourceMappingURL=mudder.min.mjs.map