UNPKG

lia-mysql

Version:

JavaScript library of data standards.

92 lines 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Installer = exports.BaseInstaller = void 0; const events_1 = require("events"); const types_1 = require("../types/types"); class BaseInstaller 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(types_1.Events.create); } get target() { return this._target; } async load() { return new Promise(async (resolve, reject) => { try { this.emit(types_1.Events.initial); this.logInfo('install', 'multiple', this.multiple); await this.install(); this.initial = true; this.emit(types_1.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) { 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.BaseInstaller = BaseInstaller; exports.Installer = BaseInstaller; //# sourceMappingURL=base.js.map