cerceis-lib
Version:
Contains list of quality of life functions that is written in TypeScript and es6
57 lines • 1.6 kB
JavaScript
// src/logger/index.ts
var ANSI = {
Red: 31,
Green: 32,
Yellow: 33,
Blue: 34,
Magenta: 35,
Cyan: 36,
White: 37
};
var timestamp = () => `[LOG] - ${(/* @__PURE__ */ new Date()).toLocaleString()} `;
var Logger = {
disabled: false,
log(msg, color = "White") {
if (this.disabled) return;
console.log(`%s\x1B[${ANSI[color]}m%s\x1B[0m`, timestamp(), msg);
},
error(msg) {
if (this.disabled) return;
console.log(`%s\x1B[31m%s\x1B[0m`, timestamp(), msg);
},
warn(msg) {
if (this.disabled) return;
console.log(`%s\x1B[33m%s\x1B[0m`, timestamp(), msg);
},
succ(msg) {
if (this.disabled) return;
console.log(`%s\x1B[32m%s\x1B[0m`, timestamp(), msg);
},
/**
* Renders a progress bar to stdout.
* @param current Current progress value.
* @param total Total value.
* @param sameLine Overwrite the current line instead of printing a new one.
*/
nodeProgress(current, total, sameLine = false) {
const percent = current / total;
const barLen = 20;
const filled = Math.round(barLen * percent);
const empty = barLen - filled;
let bar = filled > 1 ? "\u2764\uFE0F".repeat(filled - 1) + "\u{1F430}" : "\u{1F430}";
if (empty > 0) bar += " ".repeat(empty - 1) + "\u{1F955}";
const text = `[${bar}] ${Math.round(percent * 100)}%`;
if (sameLine) {
process.stdout.clearLine(0);
process.stdout.cursorTo(0);
process.stdout.write(text);
if (percent >= 1) process.stdout.write("\n");
} else {
console.log(text);
}
}
};
export {
Logger
};
//# sourceMappingURL=index.mjs.map