UNPKG

lakutata

Version:

An IoC-based universal application framework.

175 lines (155 loc) 3.81 kB
/* Build Date: Mon Jan 05 2026 23:52:23 GMT+0800 (China Standard Time) */ import { a as e } from "../../../vendor/Package.internal.2.mjs"; import r from "crypto"; import { As as t } from "./As.mjs"; var a = {}; var n = r.randomBytes; var i = { exports: {} }; i.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 = t; })(i, i.exports); var s = i.exports; var o = n; var c = s; function h(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 l(e) { try { return o(e); } catch (r) { return h(e); } } function p(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 f(e, r, t, a, n) { o(t, function(i, s) { if (i) { n(i); } var o = p(s, e, r, t, a); if (o.length < t) { f(o, r, t, a, n); } else { n(null, o); } }); } a.generate = function(e, r) { var t = new c; var a, n = ""; 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 i = t.chars.length; var s = 256 - 256 % i; if (!r) { while (n.length < a) { var o = l(Math.ceil(a * 256 / s)); n = p(o, n, t.chars, a, s); } return n; } f(n, t.chars, a, s, r); }; var u = a; const v = e(u); function m(e, r) { return v.generate({ length: e !== undefined ? e : 32, charset: t(r !== undefined ? r : "alphanumeric") }); } export { m as RandomString };