dlovely-websocket
Version:
WebSocket For Dlovely
63 lines (62 loc) • 2.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toast = exports.Toast = exports.conStyle = exports.con_style = exports.randomString = void 0;
function randomString(len = 32) {
const $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678_';
const maxPos = $chars.length;
let pwd = '';
for (let i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
exports.randomString = randomString;
exports.con_style = {
bright: '\x1B[1m',
grey: '\x1B[2m',
italic: '\x1B[3m',
underline: '\x1B[4m',
reverse: '\x1B[7m',
hidden: '\x1B[8m',
black: '\x1B[30m',
red: '\x1B[31m',
green: '\x1B[32m',
yellow: '\x1B[33m',
blue: '\x1B[34m',
magenta: '\x1B[35m',
cyan: '\x1B[36m',
white: '\x1B[37m',
blackBG: '\x1B[40m',
redBG: '\x1B[41m',
greenBG: '\x1B[42m',
yellowBG: '\x1B[43m',
blueBG: '\x1B[44m',
magentaBG: '\x1B[45m',
cyanBG: '\x1B[46m',
whiteBG: '\x1B[47m'
};
const conStyle = (text, ...styles) => `${styles.map(style => exports.con_style[style]).join('')}${text}\x1B[0m`;
exports.conStyle = conStyle;
const con = (header, type, c1, c2) => (...message) => console[type]((0, exports.conStyle)(`[${header}]`, c1), (0, exports.conStyle)(`[${new Date().toLocaleString()}]`, c1), ...message.map(msg => (0, exports.conStyle)(msg, c2)));
const empty = () => { };
class Toast {
name;
constructor(name) {
this.name = name;
}
log = empty;
warn = empty;
error = empty;
open() {
this.log = con(this.name, 'log', 'green', 'blue');
this.warn = con(this.name, 'warn', 'yellow', 'cyan');
this.error = con(this.name, 'error', 'red', 'magenta');
}
close() {
this.log = empty;
this.warn = empty;
this.error = empty;
}
}
exports.Toast = Toast;
exports.toast = new Toast('SocketApp');