lia-mysql
Version:
JavaScript library of data standards.
98 lines • 2.78 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Events = void 0;
const events_1 = require("events");
exports.Events = {
create: 'create',
initial: 'initial',
ready: 'ready',
};
class Installer extends events_1.EventEmitter {
constructor(name, target, debug, multiple) {
super();
this.initial = false;
this.multiple = false;
this.name = name;
this._target = target != null ? target : this;
this.multiple = multiple;
this.debug = debug == true ? 'all' : debug ? debug + '' : '';
this.emit(exports.Events.create);
}
get target() {
return this._target;
}
async load() {
const _this = this;
return new Promise(async (resolve, reject) => {
try {
this.emit(exports.Events.initial);
this.logInfo('install', 'multiple', this.multiple);
await this.install();
this.initial = true;
this.emit(exports.Events.ready);
resolve(_this);
}
catch (e) {
reject(e);
}
});
}
logInfo(...data) {
if (this.debug == '') {
return;
}
if (this.debug.indexOf('info') >= 0 || this.debug.indexOf('all') >= 0) {
this.log(...data);
}
}
logError(...data) {
if (this.debug == '') {
return;
}
if (this.debug.indexOf('error') >= 0 || this.debug.indexOf('all') >= 0) {
this.log(...data);
}
}
logSys(...data) {
if (this.debug == '') {
return;
}
if (this.debug.indexOf('sys') >= 0 || this.debug.indexOf('all') >= 0) {
this.log(...data);
}
}
log(...data) {
if (this.debug) {
// @ts-ignore
console.log(`🐰😁[${this.name}]`, `${this.dateTime()}`, ...data);
}
}
dateTime() {
const date = new Date();
// let f ='hh:mm:ss';
return `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
}
randomInt(maxNum) {
if (maxNum <= 0) {
return 0;
}
const minNum = 0;
try {
return parseInt(`${Math.random() * (maxNum - minNum + 1) + minNum}`, 10);
}
catch (e) {
}
return 0;
}
randomStr(length = 10) {
let e = '';
for (let n = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890', o = 0; o < length; o++) {
e += n.charAt(Math.floor(Math.random() * n.length));
}
return e;
}
async install() {
}
}
exports.default = Installer;
//# sourceMappingURL=installer.js.map