-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase62-random.min.js
1 lines (1 loc) · 1.11 KB
/
base62-random.min.js
1
"use strict";!function(){function e(){return l[Math.floor(62*Math.random())+0]}function n(){for(s=0;s<y;s++)f[s]=e();return c=0,d=f.join("")}function r(){return c=0,d=w.randomBytes(y).toString("base64").replace(/[+.=/]/g,"")}function t(){f=w.getRandomValues(f);var e=Array(y);for(s=0;s<y;s++)e.push(l[f[s]%62]);return c=0,d=e.join("")}function o(){d="",f=new Array(y),g=n}function i(){d="",f=new Uint8Array(y),g=t}function a(){d="",g=r}function u(e){if(!e||"number"!=typeof e)throw new Error('base62 length must be a number "'+e+'"');return d.length<c+e&&g(),d.slice(c,c+=e)}var f,s,d="",c=0,l="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",y=8192;if(u.test=function(e){return"string"==typeof e&&/^[0-9a-zA-Z]+$/.test(e)},u.generateBase62Math=n,u.generateBase62Node=r,u.generateBase62Browser=t,u.initMath=o,u.initNode=a,u.initBrowser=i,"undefined"!=typeof module&&"function"==typeof require){var w=require("crypto");module.exports=u}else"undefined"!=typeof window&&(window.base62=u);var g;if(c=y,void 0===w)o();else if(w.getRandomValues)i();else{if(!w.randomBytes)throw new Error("Non-standard crypto library");a()}}();