lakutata
Version:
An IoC-based universal application framework.
187 lines (163 loc) • 4.01 kB
JavaScript
/* Build Date: Mon Jan 05 2026 23:52:23 GMT+0800 (China Standard Time) */
;
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
const e = require("../../../vendor/Package.internal.2.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;
var o = {
exports: {}
};
o.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 = t;
})(o, o.exports);
var c = o.exports;
var h = i;
var l = c;
function p(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 h(e);
} catch (r) {
return p(e);
}
}
function f(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 v(e, r, t, a, n) {
h(t, function(s, i) {
if (s) {
n(s);
}
var o = f(i, e, r, t, a);
if (o.length < t) {
v(o, r, t, a, n);
} else {
n(null, o);
}
});
}
s.generate = function(e, r) {
var t = new l;
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 s = t.chars.length;
var i = 256 - 256 % s;
if (!r) {
while (n.length < a) {
var o = u(Math.ceil(a * 256 / i));
n = f(o, n, t.chars, a, i);
}
return n;
}
v(n, t.chars, a, i, r);
};
var g = s;
const y = e.getDefaultExportFromCjs(g);
function d(e, r) {
return y.generate({
length: e !== undefined ? e : 32,
charset: t.As(r !== undefined ? r : "alphanumeric")
});
}
exports.RandomString = d;