-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsecure-random-password.min.js
1 lines (1 loc) · 5.49 KB
/
secure-random-password.min.js
1
(()=>{var r={10:(r,t,e)=>{"use strict";var n=e(744).Z,o=e(505),a=e(502);Object.keys(o).forEach((function(r){t[r]=o[r]}));var c=["Il1|","O0"];function u(r){var t={avoidAmbiguous:!0,characters:[o.lower,{characters:o.upper,exactly:1},{characters:o.symbols,exactly:1}],length:12,predicate:function(){return!0},random:n},e=function(r){if(!r.characters)return[];var t=Array.isArray(r.characters)?r.characters:[r.characters];return function(r,t){var e=r.map((function(r){return r.characters})).join(""),n=t.filter((function(r){return a.intersection(r,e).length>1})).join("");r.forEach((function(r){r.characters=a.toArray(r.characters).filter((function(r){return n.indexOf(r)<0})).join("")}))}(t=t.map((function(r){return a.isString(r)?{characters:r}:r})),!0===r.avoidAmbiguous?c:r.avoidAmbiguous||[]),t}(r=a.assign({},t,r));if(!a.isInteger(r.length))throw new Error("length must be an integer");if(r.length<1)throw new Error("length must be > 0");if(r.length<e.length)throw new Error("length must be >= # of character sets passed");if(e.some((function(r){return!r.characters})))throw new Error("No character set may be empty");if(0===e.length)throw new Error("Must pass one or more character sets");if("function"!=typeof r.predicate)throw new Error("predicate must be a function");var u,s=e.map((function(r){return r.exactly||1})).reduce((function(r,t){return r+t}),0);if(r.length<s)throw new Error("length is too short for character set rules");if(e.every((function(r){return r.exactly}))&&e.reduce((function(r,t){return r+t.exactly}),0)!==r.length)throw new Error("Must pass a set without exactly rule to generate the specified length");do{u=i(e,r.length,r.random)}while(!r.predicate(u));return u}function i(r,t,e){var n=r.map((function(r){return r.exactly?a.repeat(r.characters,r.exactly):[r.characters]})).reduce((function(r,t){return r.concat(t)})).map((function(r){return e.choose(r)})),o=r.filter((function(r){return!r.exactly})).map((function(r){return r.characters})).join(""),c=a.range(t-n.length).map((function(){return e.choose(o)}));return e.shuffle(n.concat(c)).join("")}t.randomPassword=u,t.randomString=function(r){var t={characters:[o.lower,o.upper,o.digits,o.symbols],length:20};return(r=a.assign({},t,r)).avoidAmbiguous=!1,u(r)}},505:(r,t)=>{t.lower="abcdefghijklmnopqrstuvwxyz",t.upper=t.lower.toUpperCase(),t.consonants="bcdfghjklmnpqrstvwxyz",t.vowels="aeiou",t.digits="1234567890",t.symbols="!@#$%^&*()",t.fullSymbols="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",t.copyableSymbols="_"},744:(r,t,e)=>{"use strict";var n=e(64),o=e(502);function a(r){if("function"!=typeof r)throw new Error("Must pass a randomSource function");this._randomSource=r}function c(r){for(var t=0,e=1,n=(r=r||[]).length-1;n>=0;n--)t+=r[n]*e,e*=256;return t}a.prototype.choose=function(r){if(!r||!r.length)throw new Error("Must pass 1 or more choices");return r[this._getInt(r.length)]},a.prototype.getInt=function(r){if(void 0===r)throw new Error("Must pass an upper bound");if(!o.isInteger(r))throw new Error("Upper bound must be a number");if(r<1)throw new Error("Upper bound must be > 0");return this._getInt(r)},a.prototype._getInt=function(r){if(1===r)return 0;var t,e=Math.ceil(Math.log(r)/Math.log(256)),n=Math.pow(2,8*e)-Math.pow(2,8*e)%r;do{t=c(this._randomSource(e))}while(t>=n);return t%r},a.prototype.shuffle=function(r){r=Array.prototype.slice.call(r||[]);for(var t=[];r.length;)t.push(r.splice(this._getInt(r.length),1)[0]);return t},t.Z=new a(n)},502:(r,t)=>{"use strict";function e(r){return Array.apply(null,Array(r)).map((function(r,t){return t}))}function n(r){return Array.prototype.slice.call(r)}t.assign=function(){var r=n(arguments),t=r[0],e=r.slice(1);return e.filter((function(r){return!!r})).forEach((function(r){Object.keys(r).forEach((function(e){t[e]=r[e]}))})),t},t.intersection=function(r,t){r=n(r),t=n(t);var e={};r.forEach((function(r){e[r]=!0}));var o={};return t.forEach((function(r){o[r]=!0})),Object.keys(e).filter((function(r){return Object.prototype.hasOwnProperty.call(o,r)}))},t.isInteger=function(r){return"number"==typeof r&&isFinite(r)&&Math.floor(r)===r},t.isString=function(r){return"string"==typeof r||r instanceof String},t.range=e,t.repeat=function(r,t){return e(t).map((function(){return r}))},t.toArray=n},64:function(r,t,e){var n;!function(o){"use strict";function a(r,t){if(t=t||{type:"Array"},"undefined"!=typeof process&&"number"==typeof process.pid&&process.versions&&process.versions.node)return function(r,t){var n=e(954).randomBytes(r);switch(t.type){case"Array":return[].slice.call(n);case"Buffer":return n;case"Uint8Array":for(var o=new Uint8Array(r),a=0;a<r;++a)o[a]=n.readUInt8(a);return o;default:throw new Error(t.type+" is unsupported.")}}(r,t);if(!window.crypto&&!window.msCrypto)throw new Error("Your browser does not support window.crypto.");return function(r,t){var e=new Uint8Array(r);switch((window.crypto||window.msCrypto).getRandomValues(e),t.type){case"Array":return[].slice.call(e);case"Buffer":try{new Buffer(1)}catch(r){throw new Error("Buffer not supported in this environment. Use Node.js or Browserify for browser support.")}return new Buffer(e);case"Uint8Array":return e;default:throw new Error(t.type+" is unsupported.")}}(r,t)}void 0===(n=function(){return a}.apply(t,[]))||(r.exports=n),a.randomArray=function(r){return a(r,{type:"Array"})},a.randomUint8Array=function(r){return a(r,{type:"Uint8Array"})},a.randomBuffer=function(r){return a(r,{type:"Buffer"})}}()},954:()=>{}},t={};window.secureRandomPassword=function e(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return r[n].call(a.exports,a,a.exports,e),a.exports}(10)})();