supergeneric
Version:
Supergeneric JS helper functions... formatters, math functions, sort functions, etc.
2 lines (1 loc) • 835 B
JavaScript
;function t(t){return t[(r=0,e=t.length-1,Math.floor(Math.random()*(e-r+1))+r)];var r,e}exports.generateHash=(r=6,e={})=>{const{ambiguous:n=!0,lower:o=!0,upper:a=!0,numeric:s=!0,alpha:i,symbols:f=!1,startWithLetter:p=!0,all:c,only:h,prefix:l=""}=e;if(!r)return l;const y=!1===i?"":"string"==typeof i?i:(!1===o?"":"string"==typeof o?o:"abcdefghijkmnopqrstuvwxyz"+(n?"l":""))+(!1===a?"":"string"==typeof a?a:"ABCDEFGHJKLMNPQRSTUVWXYZ"+(n?"IO":"")),u=c||y+(!1===s?"":"string"==typeof s?s:"123456789"+(n?"0":""))+(!1===f?"":"string"==typeof f?f:"!@#$%^&*");if(""===h)throw new Error("Character set cannot be empty");if(!h&&!u)throw new Error("Character set cannot be empty");const g=h||u;let m=g;if(!h&&p&&!c&&y&&(m=y),!m)throw new Error("Character set cannot be empty");let w=l+t(m);m=g;for(let e=1;e<r;e++)w+=t(m);return w};