UNPKG

@synthart/synthlite

Version:

A fast, lightweight Gen AI powered synthetic data generator written in TypeScript. 🌞

138 lines (137 loc) 4.47 kB
"use strict"; /** * * @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 = 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 = { teal: chalk_1.default.hex("#008080"), // Muted teal for debug messages gold: chalk_1.default.hex("#B8860B"), // Gold for banner messages gray: chalk_1.default.hex("#A9A9A9"), // Gray for subtle text }; 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, "red", false); } /** * Prints an info message to the console. * @param {string} message - The message to print. */ info(message) { return this.px("[→]", message, "blue", false); } /** * Prints a debug message to the console in teal. * @param {string} message - The message to print. */ debug(message) { return this.px("[◎]", message, "teal", true); } /** * Prints a warning message to the console. * @param {string} message - The message to print. */ warn(message) { return this.px("[!]", message, "yellow", false); } /** * Prints a success message to the console. * @param message The message to print. * @returns */ success(message) { return this.px("[✔]", message, "green", 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() === ""); } /** * Prints the SynthLite banner to the console. * @returns void */ printBanner() { const messages = [ "SynthLite: A fast, lightweight and flexible synthetic data generation tool.", "Author: Aditya Patange (AdiPat) <contact.adityapatange@gmail.com>", "GitHub: https://www.github.com/AdiPat/synthlite", "synthlite is a product of AdiPat Labs!", "\n", ]; messages.forEach((message) => { this.px("⚡️", message, "gold", false); }); } } exports.Printer = Printer; exports.printer = new Printer();