UNPKG

lakutata

Version:

An IoC-based universal application framework.

194 lines (166 loc) 4.09 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const e = require("../../../vendor/Package.5.cjs"); require("../../../vendor/Package.15.cjs"); const r = require("crypto"); const t = require("./As.cjs"); const a = e => e && e.__esModule ? e : { default: e }; const n = a(r); var s = {}; var i = n.default.randomBytes; const o = e.getDefaultExportFromCjs(i); var c = { exports: {} }; var h = c.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 s = "abcdef"; var i = "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 + s; } else if (e === "binary") { r = i; } 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; })(c, c.exports); var l = c.exports; const u = e.getDefaultExportFromCjs(l); "use strict"; var p = i; var f = l; function v(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 g(e) { try { return p(e); } catch (r) { return v(e); } } function y(e, r, t, a, n) { var s = r; for (var i = 0; i < e.length && s.length < a; i++) { var o = e.readUInt8(i); if (o < n) { s += t.charAt(o % t.length); } } return s; } function d(e, r, t, a, n) { p(t, (function(s, i) { if (s) { n(s); } var o = y(i, e, r, t, a); if (o.length < t) { d(o, r, t, a, n); } else { n(null, o); } })); } var m = s.generate = function(e, r) { var t = new f; var a, n, s, i = ""; 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 (i.length < a) { var h = g(Math.ceil(a * 256 / c)); i = y(h, i, t.chars, a, c); } return i; } d(i, t.chars, a, c, r); }; var b = s; const x = e.getDefaultExportFromCjs(b); function j(e, r) { return x.generate({ length: e !== undefined ? e : 32, charset: t.As(r !== undefined ? r : "alphanumeric") }); } exports.RandomString = j;