@hopeio/utils
Version:
javascript utils
2 lines (1 loc) • 995 B
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",s=97,f=48,c=65,i=90;function l(e,o){let r="";do{let t=e%o;r+=u.charAt(t),e=Math.floor(e/o)}while(e>0);return r.split("").reverse().join("")}function n(e,o){let r=0;for(let t=0,a=e.length;t<a;t++){let d=g(e.charAt(t).charCodeAt(0)),h=a-t-1;r+=d*Math.pow(o,h)}return r}function g(e){return e<c?e-f:e>i?10+e-s:36+e-c}console.log(l(1042018,36));console.log(n("1hf7eo69lkt",36));console.log(n("1hf63bvzph1",36));console.log(n("1fpw3y18veq",36));console.log(new Date().getTime());function M(e,o){switch(arguments.length){case 1:return Math.floor(Math.random()*e+1);case 2:return Math.floor(Math.random()*(o-e+1)+e);default:return 0}}function m(e){return e===100?!0:Math.floor(Math.random()*100)<e}function A(e){return+(Math.round(+(e+"e+2"))+"e-2")}exports.formatInt=l;exports.lottery=m;exports.parseInt=n;exports.randomNum=M;exports.roundToTwo=A;