UNPKG

nid

Version:

Nice clean-mouthed random id generation, without any swearing!

1 lines 1.78 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Nid=e()}}((function(){var e={};Object.defineProperty(e,"__esModule",{value:!0});const n=[[102,117,99,107],[115,104,105,116],[99,117,110,116],[110,105,103,103],[99,111,99,107],[115,117,99,107],[98,105,116,99,104],[97,115,115],[104,111,108,101],[119,104,111,114,101],[119,97,110,107],[115,108,117,116],[112,117,115,115],[101,114,114,111,114]],t={len:6,alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"};let l,o;function f(e){return"string"==typeof e&&(e=e.split(/\s*,\s*/)),Array.isArray(e)?function(n){const t=n.toLowerCase();for(let l=0;l<e.length;l++)if(-1!=t.indexOf(e[l]))return!0}:"function"==typeof e?e:e instanceof RegExp?n=>!!n.match(e):()=>!1}function r(e){let r=t.len||0,u=t.alphabet;null==l&&(o=n.map(e=>e.map(e=>String.fromCharCode(e)).join("")),l=f(o));let a=l;e&&(r=e.length||e.len||r||0,u=e.alphabet||u,a=e.curses?f(e.curses):a),u=null==u?"":u;let s=null;const i=u.length||0;do{const e=(new Date).getTime(),n=[];for(let t=0;t<r;t++){const t=Math.floor(e*Math.random()%i);n.push(u[t])}s=n.join("")}while(a(s));return s}function u(e){return e?"number"==typeof e?r({len:e}):"object"==typeof e?function(e){e.len=e.len||e.length,["len","alphabet","curses"].forEach((function(n){e[n]=void 0===e[n]?t[n]:e[n]})),e.hex?e.alphabet="0123456789abcdef":e.HEX&&(e.alphabet="0123456789ABCDEF"),e.curses=e.exclude||e.curses;let n=function(){return r(e)};const o=e.curses;return n.curses=()=>o||l,n.len=e.len,n.alphabet=e.alphabet,n}(e):r():r()}return u(),u.curses=()=>o,u.len=t.len,u.alphabet=t.alphabet,e.default=u,e=u}));