46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import * as plugins from './beautyfiglet.plugins.js';
|
|
|
|
export class BeautyFiglet {
|
|
/**
|
|
* Render text with a specific figlet font.
|
|
* @param text - The text to render.
|
|
* @param font - The font to use (optional).
|
|
* @returns A promise that resolves to the rendered ASCII art.
|
|
*/
|
|
static async renderText(text: string, font: plugins.figlet.Fonts = "Standard"): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
plugins.figlet.text(text, { font }, (err, result) => {
|
|
if (err) {
|
|
reject(`Error rendering text: ${err.message}`);
|
|
} else {
|
|
resolve(result || "");
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get a list of all available fonts in figlet.
|
|
* @returns A promise that resolves to an array of font names.
|
|
*/
|
|
static async listFonts(): Promise<string[]> {
|
|
return new Promise((resolve, reject) => {
|
|
plugins.figlet.fonts((err, fonts) => {
|
|
if (err) {
|
|
reject(`Error fetching fonts: ${err.message}`);
|
|
} else {
|
|
resolve(fonts || []);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Render text with a default font (Standard).
|
|
* @param text - The text to render.
|
|
* @returns A promise that resolves to the rendered ASCII art.
|
|
*/
|
|
static async renderDefault(text: string): Promise<string> {
|
|
return this.renderText(text, "Standard");
|
|
}
|
|
} |