@synthart/synthlite
Version:
A fast, lightweight Gen AI powered synthetic data generator written in TypeScript. 🌞
111 lines (110 loc) • 3.47 kB
JavaScript
;
/**
*
* @file printer.ts
* @author Aditya Patange (AdiPat) <contact.adityapatange@gmail.com>
* @description 🚀 Printer is a class that handles printing of messages to the terminal.
* @date January 2024
* @version 1.0.0
* @license Affero General Public License v3.0
* ✨ "We write to change." — Anonymous
*
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Printer = void 0;
const chalk_1 = __importDefault(require("chalk"));
/**
* Printer: Handles printing to the console.
* @class Printer
* @property {boolean} verbose - Whether to print verbose output.
*/
class Printer {
/**
* Sets the verbose property.
* @param {boolean} verbose - If true, print verbose output.
*/
constructor(verbose = false) {
this.verbose = false;
this.colourPrinter = {
pink: chalk_1.default.hex("#FF1493"),
};
this.verbose = verbose;
}
/**
* Sets the verbose property.
* @param {boolean} verbose - If true, print verbose output.
*/
setVerbose(verbose) {
this.verbose = verbose;
}
/**
* Returns the verbose property.
* @returns {boolean} - The verbose property.
*/
getVerbose() {
return this.verbose;
}
/**
* Wrapper function for printing messages to the console with a prefix, color, and verbose check.
* @param prefix The prefix to include in the message.
* @param message The message to print.
* @param colour The colour to print the message in.
* @param verboseCheck Whether to check for verbose output.
* @returns void
*/
px(prefix, message, colour, verboseCheck = false) {
var _a;
if (verboseCheck && !this.verbose) {
return;
}
if (this.isMessageEmpty(message)) {
console.log("\n");
return;
}
const chalkPrinter = (_a = chalk_1.default === null || chalk_1.default === void 0 ? void 0 : chalk_1.default[colour]) !== null && _a !== void 0 ? _a : this.colourPrinter[colour];
console.log(chalkPrinter(`${prefix} ${message}`));
}
/**
* Prints an error message to the console.
* @param {string} message - The message to print.
*/
error(message) {
return this.px("[!]", message, "redBright", false);
}
/**
* Prints an info message to the console.
* @param {string} message - The message to print.
*/
info(message) {
return this.px("[*]", message, "cyanBright", false);
}
/**
* Prints a debug message to the console in pink.
* @param {string} message - The message to print.
*/
debug(message) {
return this.px("→", message, "pink", true);
}
/**
* Prints a warning message to the console.
* @param {string} message - The message to print.
*/
warn(message) {
return this.px("[!]", message, "yellowBright", false);
}
/**
* Checks if the message is empty.
* @param message The message to print.
* @returns true if the message is empty, false otherwise.
*/
isMessageEmpty(message) {
return (message === "" ||
message === undefined ||
message === null ||
message.trim() === "");
}
}
exports.Printer = Printer;