UNPKG

lakutata

Version:

An IoC-based universal application framework.

182 lines (158 loc) 3.85 kB
import { g as e } from "../../../vendor/Package.5.mjs"; import "../../../vendor/Package.15.mjs"; import r from "crypto"; import { As as t } from "./As.mjs"; var a = {}; var n = r.randomBytes; const i = e(n); var s = { exports: {} }; var o = s.exports; (function(e, r) { function t() { this.chars = ""; } t.prototype.setType = function(e) { if (Array.isArray(e)) { for (var r = 0; r < e.length; r++) { this.chars += this.getCharacters(e[r]); } } else { this.chars = this.getCharacters(e); } }; t.prototype.getCharacters = function(e) { var r; var t = "0123456789"; var a = "abcdefghijklmnopqrstuvwxyz"; var n = a.toUpperCase(); var i = "abcdef"; var s = "01"; var o = "01234567"; if (e === "alphanumeric") { r = t + a + n; } else if (e === "numeric") { r = t; } else if (e === "alphabetic") { r = a + n; } else if (e === "hex") { r = t + i; } else if (e === "binary") { r = s; } else if (e === "octal") { r = o; } else { r = e; } return r; }; t.prototype.removeUnreadable = function() { var e = /[0OIl]/g; this.chars = this.chars.replace(e, ""); }; t.prototype.setcapitalization = function(e) { if (e === "uppercase") { this.chars = this.chars.toUpperCase(); } else if (e === "lowercase") { this.chars = this.chars.toLowerCase(); } }; t.prototype.removeDuplicates = function() { var e = this.chars.split(""); e = [ ...new Set(e) ]; this.chars = e.join(""); }; e.exports = r = t; })(s, s.exports); var c = s.exports; const h = e(c); "use strict"; var p = n; var l = c; function f(e) { var r = []; for (var t = 0; t < e; t++) { r.push(Math.floor(Math.random() * 255)); } return { length: e, readUInt8: function(e) { return r[e]; } }; } function u(e) { try { return p(e); } catch (r) { return f(e); } } function v(e, r, t, a, n) { var i = r; for (var s = 0; s < e.length && i.length < a; s++) { var o = e.readUInt8(s); if (o < n) { i += t.charAt(o % t.length); } } return i; } function m(e, r, t, a, n) { p(t, (function(i, s) { if (i) { n(i); } var o = v(s, e, r, t, a); if (o.length < t) { m(o, r, t, a, n); } else { n(null, o); } })); } var g = a.generate = function(e, r) { var t = new l; var a, n, i, s = ""; if (typeof e === "object") { a = typeof e.length === "number" ? e.length : 32; if (e.charset) { t.setType(e.charset); } else { t.setType("alphanumeric"); } if (e.capitalization) { t.setcapitalization(e.capitalization); } if (e.readable) { t.removeUnreadable(); } t.removeDuplicates(); } else if (typeof e === "number") { a = e; t.setType("alphanumeric"); } else { a = 32; t.setType("alphanumeric"); } var o = t.chars.length; var c = 256 - 256 % o; if (!r) { while (s.length < a) { var h = u(Math.ceil(a * 256 / c)); s = v(h, s, t.chars, a, c); } return s; } m(s, t.chars, a, c, r); }; var y = a; const d = e(y); function b(e, r) { return d.generate({ length: e !== undefined ? e : 32, charset: t(r !== undefined ? r : "alphanumeric") }); } export { b as RandomString };