cerceis-lib
Version:
Contains list of quality of life functions that is written in TypeScript and es6
82 lines (81 loc) • 2.61 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/logger/index.ts
var logger_exports = {};
__export(logger_exports, {
Logger: () => Logger
});
module.exports = __toCommonJS(logger_exports);
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);
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Logger
});
//# sourceMappingURL=index.js.map