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