-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.min.js
6 lines (6 loc) · 9.48 KB
/
index.min.js
1
2
3
4
5
6
/*!
* base-62.js (c) 2015 Brian Norton
* This library may be freely distributed under the MIT license.
*/
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.base62=n()}}(function(){var n;return function e(n,t,r){function o(u,s){if(!t[u]){if(!n[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var l=t[u]={exports:{}};n[u][0].call(l.exports,function(e){var t=n[u][1][e];return o(t?t:e)},l,l.exports,e,n,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(n,e,t){function r(){return d.encode(a())}function o(n){var e=f(n,10,16);return e?e:null}function i(n){return f(n.toString().toLowerCase(),16,10)}function u(n,e,t){for(var r=[],o=Math.max(n.length,e.length),i=0,u=0;o>u||i;){var s=u<n.length?n[u]:0,c=u<e.length?e[u]:0,f=i+s+c;r.push(f%t),i=Math.floor(f/t),u++}return r}function s(n,e,t){if(0>n)return null;if(0==n)return[];for(var r=[],o=e;;){if(1&n&&(r=u(r,o,t)),n>>=1,0===n)break;o=u(o,o,t)}return r}function c(n,e){for(var t=n.split(""),r=[],o=t.length-1;o>=0;o--){var i=parseInt(t[o],e);if(isNaN(i))return null;r.push(i)}return r}function f(n,e,t){var r=c(n,e);if(null===r)return null;for(var o=[],i=[1],f=0;f<r.length;f++)r[f]&&(o=u(o,s(r[f],i,t),t)),i=s(e,i,t);for(var l="",f=o.length-1;f>=0;f--)l+=o[f].toString(t);return l}var l=n("big.js"),a=n("random.js").randomInt,h="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",d={encode:function(n){var e=n;n=n.toString();try{l(n)}catch(t){console.log("Big init error on ",e,n)}var r=l(n),o="";if("0"==n)return"0";for(;r.gt(0);)o=h[r.mod(62).toFixed()]+o,r=l(r.div(62).toFixed(2).split(".")[0]);return o},decode:function(n){n=n.toString();var e=l(0),t=l(62),r=n.split("").reverse();return r.forEach(function(n,r){e=e.plus(t.pow(r).times(h.indexOf(n)))}),e.toFixed()},encodeHex:function(n){return d.encode(i(n.toString()))},decodeHex:function(n){return o(d.decode(n))},"short":function(n){return n?d.encodeHex(n):null},id:function(n){return n?d.decodeHex(n):null},token:function(){return r()+r()+r()+r()+r()}};e.exports=d},{"big.js":2,"random.js":3}],2:[function(e,t,r){!function(e){"use strict";function r(){function n(e){var t=this;return t instanceof n?(e instanceof n?(t.s=e.s,t.e=e.e,t.c=e.c.slice()):i(t,e),void(t.constructor=n)):void 0===e?r():new n(e)}return n.prototype=g,n.DP=f,n.RM=l,n}function o(n,e,t){var r=n.constructor,o=e-(n=new r(n)).e,i=n.c;for(i.length>++e&&u(n,o,r.RM),i[0]?t?o=e:(i=n.c,o=n.e+o+1):++o;i.length<o;i.push(0));return o=n.e,1===t||t&&(o>=e||d>=o)?(n.s<0&&i[0]?"-":"")+(i.length>1?i[0]+"."+i.join("").slice(1):i[0])+(0>o?"e":"e+")+o:n.toString()}function i(n,e){var t,r,o;for(0===e&&0>1/e?e="-0":v.test(e+="")||s(NaN),n.s="-"==e.charAt(0)?(e=e.slice(1),-1):1,(t=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(0>t&&(t=r),t+=+e.slice(r+1),e=e.substring(0,r)):0>t&&(t=e.length),r=0;"0"==e.charAt(r);r++);if(r==(o=e.length))n.c=[n.e=0];else{for(;"0"==e.charAt(--o););for(n.e=t-r-1,n.c=[],t=0;o>=r;n.c[t++]=+e.charAt(r++));}return n}function u(n,e,t,r){var o,i=n.c,u=n.e+e+1;if(1===t?r=i[u]>=5:2===t?r=i[u]>5||5==i[u]&&(r||0>u||i[u+1]!==o||1&i[u-1]):3===t?r=r||i[u]!==o||0>u:(r=!1,0!==t&&s("!Big.RM!")),1>u||!i[0])r?(n.e=-e,n.c=[1]):n.c=[n.e=0];else{if(i.length=u--,r)for(;++i[u]>9;)i[u]=0,u--||(++n.e,i.unshift(1));for(u=i.length;!i[--u];i.pop());}return n}function s(n){var e=new Error(n);throw e.name="BigError",e}var c,f=20,l=1,a=1e6,h=1e6,d=-7,m=21,g={},v=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;g.abs=function(){var n=new this.constructor(this);return n.s=1,n},g.cmp=function(n){var e,t=this,r=t.c,o=(n=new t.constructor(n)).c,i=t.s,u=n.s,s=t.e,c=n.e;if(!r[0]||!o[0])return r[0]?i:o[0]?-u:0;if(i!=u)return i;if(e=0>i,s!=c)return s>c^e?1:-1;for(i=-1,u=(s=r.length)<(c=o.length)?s:c;++i<u;)if(r[i]!=o[i])return r[i]>o[i]^e?1:-1;return s==c?0:s>c^e?1:-1},g.div=function(n){var e=this,t=e.constructor,r=e.c,o=(n=new t(n)).c,i=e.s==n.s?1:-1,c=t.DP;if((c!==~~c||0>c||c>a)&&s("!Big.DP!"),!r[0]||!o[0])return r[0]==o[0]&&s(NaN),o[0]||s(i/0),new t(0*i);var f,l,h,d,m,g,v=o.slice(),p=f=o.length,x=r.length,w=r.slice(0,f),b=w.length,M=n,S=M.c=[],y=0,N=c+(M.e=e.e-n.e)+1;for(M.s=i,i=0>N?0:N,v.unshift(0);b++<f;w.push(0));do{for(h=0;10>h;h++){if(f!=(b=w.length))d=f>b?1:-1;else for(m=-1,d=0;++m<f;)if(o[m]!=w[m]){d=o[m]>w[m]?1:-1;break}if(!(0>d))break;for(l=b==f?o:v;b;){if(w[--b]<l[b]){for(m=b;m&&!w[--m];w[m]=9);--w[m],w[b]+=10}w[b]-=l[b]}for(;!w[0];w.shift());}S[y++]=d?h:++h,w[0]&&d?w[b]=r[p]||0:w=[r[p]]}while((p++<x||w[0]!==g)&&i--);return S[0]||1==y||(S.shift(),M.e--),y>N&&u(M,c,t.RM,w[0]!==g),M},g.eq=function(n){return!this.cmp(n)},g.gt=function(n){return this.cmp(n)>0},g.gte=function(n){return this.cmp(n)>-1},g.lt=function(n){return this.cmp(n)<0},g.lte=function(n){return this.cmp(n)<1},g.sub=g.minus=function(n){var e,t,r,o,i=this,u=i.constructor,s=i.s,c=(n=new u(n)).s;if(s!=c)return n.s=-c,i.plus(n);var f=i.c.slice(),l=i.e,a=n.c,h=n.e;if(!f[0]||!a[0])return a[0]?(n.s=-c,n):new u(f[0]?i:0);if(s=l-h){for((o=0>s)?(s=-s,r=f):(h=l,r=a),r.reverse(),c=s;c--;r.push(0));r.reverse()}else for(t=((o=f.length<a.length)?f:a).length,s=c=0;t>c;c++)if(f[c]!=a[c]){o=f[c]<a[c];break}if(o&&(r=f,f=a,a=r,n.s=-n.s),(c=(t=a.length)-(e=f.length))>0)for(;c--;f[e++]=0);for(c=e;t>s;){if(f[--t]<a[t]){for(e=t;e&&!f[--e];f[e]=9);--f[e],f[t]+=10}f[t]-=a[t]}for(;0===f[--c];f.pop());for(;0===f[0];)f.shift(),--h;return f[0]||(n.s=1,f=[h=0]),n.c=f,n.e=h,n},g.mod=function(n){var e,t=this,r=t.constructor,o=t.s,i=(n=new r(n)).s;return n.c[0]||s(NaN),t.s=n.s=1,e=1==n.cmp(t),t.s=o,n.s=i,e?new r(t):(o=r.DP,i=r.RM,r.DP=r.RM=0,t=t.div(n),r.DP=o,r.RM=i,this.minus(t.times(n)))},g.add=g.plus=function(n){var e,t=this,r=t.constructor,o=t.s,i=(n=new r(n)).s;if(o!=i)return n.s=-i,t.minus(n);var u=t.e,s=t.c,c=n.e,f=n.c;if(!s[0]||!f[0])return f[0]?n:new r(s[0]?t:0*o);if(s=s.slice(),o=u-c){for(o>0?(c=u,e=f):(o=-o,e=s),e.reverse();o--;e.push(0));e.reverse()}for(s.length-f.length<0&&(e=f,f=s,s=e),o=f.length,i=0;o;)i=(s[--o]=s[o]+f[o]+i)/10|0,s[o]%=10;for(i&&(s.unshift(i),++c),o=s.length;0===s[--o];s.pop());return n.c=s,n.e=c,n},g.pow=function(n){var e=this,t=new e.constructor(1),r=t,o=0>n;for((n!==~~n||-h>n||n>h)&&s("!pow!"),n=o?-n:n;1&n&&(r=r.times(e)),n>>=1,n;)e=e.times(e);return o?t.div(r):r},g.round=function(n,e){var t=this,r=t.constructor;return null==n?n=0:(n!==~~n||0>n||n>a)&&s("!round!"),u(t=new r(t),n,null==e?r.RM:e),t},g.sqrt=function(){var n,e,t,r=this,o=r.constructor,i=r.c,c=r.s,f=r.e,l=new o("0.5");if(!i[0])return new o(r);0>c&&s(NaN),c=Math.sqrt(r.toString()),0===c||c===1/0?(n=i.join(""),n.length+f&1||(n+="0"),e=new o(Math.sqrt(n).toString()),e.e=((f+1)/2|0)-(0>f||1&f)):e=new o(c.toString()),c=e.e+(o.DP+=4);do t=e,e=l.times(t.plus(r.div(t)));while(t.c.slice(0,c).join("")!==e.c.slice(0,c).join(""));return u(e,o.DP-=4,o.RM),e},g.mul=g.times=function(n){var e,t=this,r=t.constructor,o=t.c,i=(n=new r(n)).c,u=o.length,s=i.length,c=t.e,f=n.e;if(n.s=t.s==n.s?1:-1,!o[0]||!i[0])return new r(0*n.s);for(n.e=c+f,s>u&&(e=o,o=i,i=e,f=u,u=s,s=f),e=new Array(f=u+s);f--;e[f]=0);for(c=s;c--;){for(s=0,f=u+c;f>c;)s=e[f]+i[c]*o[f-c-1]+s,e[f--]=s%10,s=s/10|0;e[f]=(e[f]+s)%10}for(s&&++n.e,e[0]||e.shift(),c=e.length;!e[--c];e.pop());return n.c=e,n},g.toString=g.valueOf=g.toJSON=function(){var n=this,e=n.e,t=n.c.join(""),r=t.length;if(d>=e||e>=m)t=t.charAt(0)+(r>1?"."+t.slice(1):"")+(0>e?"e":"e+")+e;else if(0>e){for(;++e;t="0"+t);t="0."+t}else if(e>0)if(++e>r)for(e-=r;e--;t+="0");else r>e&&(t=t.slice(0,e)+"."+t.slice(e));else r>1&&(t=t.charAt(0)+"."+t.slice(1));return n.s<0&&n.c[0]?"-"+t:t},g.toExponential=function(n){return null==n?n=this.c.length-1:(n!==~~n||0>n||n>a)&&s("!toExp!"),o(this,n,1)},g.toFixed=function(n){var e,t=this,r=d,i=m;return d=-(m=1/0),null==n?e=t.toString():n===~~n&&n>=0&&a>=n&&(e=o(t,t.e+n),t.s<0&&t.c[0]&&e.indexOf("-")<0&&(e="-"+e)),d=r,m=i,e||s("!toFix!"),e},g.toPrecision=function(n){return null==n?this.toString():((n!==~~n||1>n||n>a)&&s("!toPre!"),o(this,n-1,2))},c=r(),"function"==typeof n&&n.amd?n(function(){return c}):"undefined"!=typeof t&&t.exports?t.exports=c:e.Big=c}(this)},{}],3:[function(n,e,t){randomInt=function(n){if((void 0===n||null===n)&&(n={}),(void 0===n.min||null===n)&&(n.min=0),(void 0===n.max||null===n)&&(n.max=4294967295),n.min>n.max){var e=n.min;n.min=n.max,n.max=e}return Math.floor(Math.random()*(n.max-n.min)+n.min)},randomFloat=function(n){return(void 0===n||null===n)&&(n={}),(void 0===n.min||null===n)&&(n.min=0),(void 0===n.max||null===n)&&(n.max=1),Math.random()*(n.max-n.min)+n.min},randomString=function(n){(void 0===n||null===n)&&(n={}),(void 0===n.length||null===n.length)&&(n.length=20),(void 0===n.set||null===n.set)&&(n.set="alphanum");var e;switch(n.set){case"alpha":e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";break;case"alphanum":e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";break;case"num":e="0123456789";break;case"hex":e="0123456789ABCDEF";break;case"custom":if(void 0===n.custom||null===n.custom)return console.error("can't generate a random string with custom set of characters if options.custom is null or undefined"),"";e=n.custom}for(var t="",r=0;r<n.length;r++){var o=randomInt({min:0,max:e.length});t+=e[o]}return t},e.exports.randomInt=randomInt,e.exports.randomFloat=randomFloat,e.exports.randomString=randomString},{}]},{},[1])(1)});
//# sourceMappingURL=index.min.js.map