UNPKG

@hopeio/utils

Version:
49 lines (48 loc) 1.15 kB
const d = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; function l(e, o) { let t = ""; do { let r = e % o; t += d.charAt(r), e = Math.floor(e / o); } while (e > 0); return t.split("").reverse().join(""); } function n(e, o) { let t = 0; for (let r = 0, a = e.length; r < a; r++) { let c = u(e.charAt(r).charCodeAt(0)), h = a - r - 1; t += c * Math.pow(o, h); } return t; } function u(e) { return e < 65 ? e - 48 : e > 90 ? 10 + e - 97 : 36 + e - 65; } console.log(l(1042018, 36)); console.log(n("1hf7eo69lkt", 36)); console.log(n("1hf63bvzph1", 36)); console.log(n("1fpw3y18veq", 36)); console.log((/* @__PURE__ */ new Date()).getTime()); function s(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 f(e) { return e === 100 ? !0 : Math.floor(Math.random() * 100) < e; } function i(e) { return +(Math.round(+(e + "e+2")) + "e-2"); } export { l as formatInt, f as lottery, n as parseInt, s as randomNum, i as roundToTwo };