UNPKG

@wcj/generate-password

Version:

Generate Password is a generating random and unique passwords.

3 lines (2 loc) 1.46 kB
/*! @wcj/generate-password v1.0.4 | MIT © 2023 kenny wong <wowohoo@qq.com> https://jaywcjlove.github.io/generate-password */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GeneratePassword={})}(this,(function(e){"use strict";var t="abcdefghijklmnopqrstuvwxyz",n="ABCDEFGHIJKLMNOPQRSTUVWXYZ",a="0123456789",r="!@#$%^&*()_+~`|}{\\[\\]:;?>,.<-=\\/";function o(e){void 0===e&&(e={});var o=e.lowerCase,h=void 0===o||o,i=e.upperCase,d=void 0===i||i,l=e.numeric,u=void 0===l||l,c=e.special,f=void 0===c||c,s=e.length,p=void 0===s?10:s,g="";if(!(h||d||u||f))return g;for(;g.length<p;){var v=Math.ceil(t.length*Math.random()*Math.random())-1,M=Math.ceil(a.length*Math.random()*Math.random())-1,m=Math.ceil(r.length*Math.random()*Math.random())-1,A=Math.ceil(n.length*Math.random()*Math.random())-1;h&&g.length<p&&(g+=t.charAt(v)),d&&g.length<p&&(g+=n.charAt(A)),u&&g.length<p&&(g+=a.charAt(M)),f&&g.length<p&&(g+=r.charAt(m))}return g.trim()}e.LOWERCASE=t,e.NUMERIC=a,e.SPECIAL_CHARACTER=r,e.UPPERCASE=n,e.generate=o,e.generateMultiple=function(e,t){void 0===e&&(e=10);for(var n=[],a=0;a<e;a++)n.push(o(t));return n},e.validate=function(e){void 0===e&&(e="");var t=new Array;t.push("[".concat(r,"]")),t.push("[A-Z]"),t.push("[0-9]"),t.push("[a-z]");for(var n=0,a=0;a<t.length;a++)new RegExp(t[a]).test(e)&&n++;return n}}));