### Install Figlet.js Globally for Command Line Source: https://github.com/patorjk/figlet.js/blob/main/README.md Install the Figlet.js package globally to use its command-line interface. ```sh npm install -g figlet ``` -------------------------------- ### Install Figlet.js (Node.js) Source: https://github.com/patorjk/figlet.js/blob/main/README.md Install the figlet package using npm. This is the first step to using Figlet.js in a Node.js project. ```sh npm install figlet ``` -------------------------------- ### FIGlet Control File Example Source: https://github.com/patorjk/figlet.js/blob/main/doc/figfont.txt This example demonstrates a FIGlet control file with two transformation stages. The first stage converts lowercase ASCII letters to uppercase, and the second maps 'Q' to '~'. The 'f' command is crucial for applying these transformations. ```figlet flc2a t a-z A-Z f t Q ~ ``` -------------------------------- ### CLI usage Source: https://context7.com/patorjk/figlet.js/llms.txt Generate ASCII art from the terminal. After global installation (`npm install -g figlet`) or via `npx figlet`, the CLI accepts text arguments and flags to control font and layout. ```APIDOC ## CLI usage ### Description Generate ASCII art from the terminal. After global installation (`npm install -g figlet`) or via `npx figlet`, the CLI accepts text arguments and flags to control font and layout. Use `--list` to enumerate all available fonts. ### Examples Basic usage with default Standard font: ```sh figlet "Hello World" ``` Specify a font: ```sh figlet -f "Dancing Font" "Hi" ``` Limit output width with whitespace-aware line breaking: ```sh figlet -f "Standard" -w 40 "Longer text that wraps" ``` Set horizontal layout: ```sh figlet -f "Standard" -h "fitted" "Kerning Test" ``` List all available fonts: ```sh figlet --list ``` Show metadata for a specific font: ```sh figlet --info "Ghost" ``` Use npx without global install: ```sh npx figlet -f "Big" "Quick Test" ``` ``` -------------------------------- ### CLI Usage for Generating ASCII Art Source: https://context7.com/patorjk/figlet.js/llms.txt After global installation (`npm install -g figlet`) or via `npx figlet`, the CLI accepts text arguments and flags to control font and layout. Use `--list` to enumerate all available fonts. ```bash # Basic usage with default Standard font figlet "Hello World" ``` ```bash # Specify a font figlet -f "Dancing Font" "Hi" ``` ```bash # Limit output width with whitespace-aware line breaking figlet -f "Standard" -w 40 "Longer text that wraps" ``` ```bash # Set horizontal layout figlet -f "Standard" -h "fitted" "Kerning Test" ``` ```bash # List all available fonts figlet --list ``` ```bash # Show metadata for a specific font figlet --info "Ghost" ``` ```bash # Use npx without global install npx figlet -f "Big" "Quick Test" ``` -------------------------------- ### Command Line Usage of Figlet.js Source: https://github.com/patorjk/figlet.js/blob/main/README.md Generate ASCII art from the command line using the installed Figlet.js package. Specify the font and the text to convert. ```sh figlet -f "Dancing Font" "Hi" ``` -------------------------------- ### Get List of Available Fonts (Callback) Source: https://github.com/patorjk/figlet.js/blob/main/README.md Retrieves a list of all available fonts using a callback function. Handles potential errors. ```javascript figlet.fonts(function (err, fonts) { if (err) { console.log("something went wrong..."); console.dir(err); return; } console.dir(fonts); }); ``` -------------------------------- ### fontsSync Source: https://github.com/patorjk/figlet.js/blob/main/README.md Synchronously gets a list of all available fonts. ```APIDOC ## fontsSync ### Description Synchronously gets a list of all available fonts. Similar to `fonts`, but without callback or promise support. ### Method `figlet.fontsSync()` ### Request Example ```js console.log(figlet.fontsSync()); ``` ### Response #### Success Response - **fonts** (Array) - An array of available font names. ``` -------------------------------- ### Get List of Available Fonts (Synchronous) Source: https://github.com/patorjk/figlet.js/blob/main/README.md Retrieves a list of all available fonts synchronously. ```javascript console.log(figlet.fontsSync()); ``` -------------------------------- ### Get Font Metadata (Promise) Source: https://github.com/patorjk/figlet.js/blob/main/README.md Retrieves the default options and header comment for a given font using a Promise. Includes error handling with try-catch. ```javascript try { const [options, headerComment] = await figlet.metadata("Standard"); console.dir(options); console.log(headerComment); } catch (err) { console.log("something went wrong..."); console.dir(err); } ``` -------------------------------- ### fonts Source: https://github.com/patorjk/figlet.js/blob/main/README.md Gets a list of all available fonts. Supports callbacks and returns a promise. ```APIDOC ## fonts ### Description Gets a list of all available fonts. In Node.js, it lists fonts from the configured font folder. In the browser, it lists fonts bundled with the library. ### Method `figlet.fonts([callback])` or `await figlet.fonts()` ### Parameters #### Callback (Optional) - **callback** (Function) - A function that accepts `err` and `fonts` (an array of font names). ### Request Example (Callback) ```js figlet.fonts(function (err, fonts) { if (err) { console.log("something went wrong..."); console.dir(err); return; } console.dir(fonts); }); ``` ### Request Example (Promise) ```js try { const fonts = await figlet.fonts(); console.dir(fonts); } catch (err) { console.log("something went wrong..."); console.dir(err); } ``` ### Response #### Success Response - **fonts** (Array) - An array of available font names. ``` -------------------------------- ### Get Font Metadata (Callback) Source: https://github.com/patorjk/figlet.js/blob/main/README.md Retrieves the default options and header comment for a given font using a callback function. Handles potential errors. ```javascript figlet.metadata("Standard", function (err, options, headerComment) { if (err) { console.log("something went wrong..."); console.dir(err); return; } console.dir(options); console.log(headerComment); }); ``` -------------------------------- ### FIGcharacter Definition with Code Tags Source: https://github.com/patorjk/figlet.js/blob/main/doc/figfont.txt Example demonstrating code-tagged FIGcharacters. Each tag includes the character code followed by whitespace and an optional comment (FIGcharacter name). ```plaintext 161 INVERTED EXCLAMATION MARK _ @ (_) | | | | |_| @@ ``` ```plaintext 162 CENT SIGN _ @ | | @ / __)@ || (__ @ | \ )@ | |_| @@ ``` -------------------------------- ### Get Font Metadata with figlet.metadata() Source: https://context7.com/patorjk/figlet.js/llms.txt Retrieve font metadata and header comments using either Promises or callbacks. Ensure the font name is valid. ```javascript import figlet from "figlet"; // Promise style const [options, headerComment] = await figlet.metadata("Standard"); console.dir(options); // { // hardBlank: '$', // height: 6, // baseline: 5, // maxLength: 16, // oldLayout: 15, // numCommentLines: 3, // printDirection: 0, // fullLayout: 24463, // fittingRules: { hLayout: 3, hRule1: true, hRule2: true, ... } // } console.log(headerComment); // "Standard by Glenn Chappell & Ian Chai..." // Callback style figlet.metadata("Ghost", function (err, options, headerComment) { if (err) { console.error("Error:", err); return; } console.log("Font height:", options.height); console.log("Comment:", headerComment); }); ``` -------------------------------- ### List Available Fonts (Async) Source: https://context7.com/patorjk/figlet.js/llms.txt Returns a Promise that resolves to an array of available font name strings. In Node.js, it reads the 'fonts/' directory; in the browser it returns the built-in font list. Also accepts an optional Node-style callback. ```javascript import figlet from "figlet"; // Promise style const fonts = await figlet.fonts(); console.log(fonts); // ['1Row', '3-D', '3D Diagonal', 'ANSI Compact', 'ANSI Regular', 'ANSI Shadow', 'Standard', ...] // Callback style figlet.fonts(function (err, fonts) { if (err) { console.error("Error:", err); return; } fonts.sort().forEach((font) => console.log(font)); }); ``` -------------------------------- ### FIGlet.js Initialization and Font Preloading Source: https://github.com/patorjk/figlet.js/blob/main/examples/front-end/index.htm Initializes FIGlet.js with a font path and preloads specified fonts. This is useful for ensuring fonts are available before generating text, especially in browser environments where fetch might not support the 'file:' protocol. ```javascript import figlet from '../../dist/figlet.mjs'; if (window.location.protocol === "file:") { alert("fetch APi does not support file: protocol."); } figlet.defaults({ fontPath: "../../fonts", }); figlet.preloadFonts(["Standard", "Ghost", "Dancing Font", "3D Diagonal"], function (err, fonts) { if (err) { console.error("There was an error prefetching fonts: ", err); } console.log("prefetching done."); } ); ``` -------------------------------- ### Generate ASCII Art with Async/Await (Node.js) Source: https://github.com/patorjk/figlet.js/blob/main/README.md Use the async/await syntax with figlet.text to generate ASCII art. This is the modern approach for handling asynchronous operations in Node.js. ```javascript import figlet from "figlet"; async function doStuff() { const text = await figlet.text("Hello World!!"); console.log(text); } doStuff(); ``` -------------------------------- ### defaults Source: https://github.com/patorjk/figlet.js/blob/main/README.md Sets default configuration values for the Figlet.js library. ```APIDOC ## defaults ### Description Allows setting default configuration values that will be used by the library unless overridden. ### Method `figlet.defaults(options)` ### Parameters #### Request Body - **options** (Object) - An object containing default settings. - **font** (String) - Default font to use. Defaults to 'Standard'. - **fontPath** (String) - Default path to look for fonts. Defaults to './fonts'. - **fetchFontIfMissing** (Boolean) - For browser environments, whether to attempt to fetch a font if it's not found. Defaults to `false`. ### Request Example ```js figlet.defaults({ font: "Standard", // default font fontPath: "some-random-place/fonts", // default font path location fetchFontIfMissing: true, // for the browser, fetch a font if its missing }); ``` ``` -------------------------------- ### Generate ASCII Art with Options (Promise - Node.js) Source: https://github.com/patorjk/figlet.js/blob/main/README.md Generate ASCII art using the figlet.text method with custom options and the Promise API. This is an alternative to callbacks for handling asynchronous operations. ```javascript try { console.log( await figlet.text("Boo!", { font: "Ghost", horizontalLayout: "default", verticalLayout: "default", width: 80, whitespaceBreak: true, }) ); } catch (err) { console.log("Something went wrong..."); console.dir(err); } ``` -------------------------------- ### Generate ASCII Art with Options (Callback - Node.js) Source: https://github.com/patorjk/figlet.js/blob/main/README.md Generate ASCII art using the figlet.text method with custom options and a callback function. This allows for fine-grained control over the output, including font, layout, and width. ```javascript figlet.text( "Boo!", { font: "Ghost", horizontalLayout: "default", verticalLayout: "default", width: 80, whitespaceBreak: true, }, function (err, data) { if (err) { console.log("Something went wrong..."); console.dir(err); return; } console.log(data); } ); ``` -------------------------------- ### Async ASCII Art Generation with Options Source: https://context7.com/patorjk/figlet.js/llms.txt The primary async method for generating ASCII art. Accepts a full options object for fine-grained control over font, layout, width, and line-breaking behavior. Returns a Promise resolving to the ASCII art string. ```javascript import figlet from "figlet"; // Full options object with Promise try { const art = await figlet.text("Boo!", { font: "Ghost", horizontalLayout: "default", // "default" | "full" | "fitted" | "controlled smushing" | "universal smushing" verticalLayout: "default", width: 80, whitespaceBreak: true, }); console.log(art); // Output: // .-. .-') ,---. // \ ( OO ) | | // ;-----.\ .-'),-----. .-'),-----. | | // | .-. | ( OO' .-. '( OO' .-. '| | // | '-' /_)/ | | | |/ | | | || | // | .-. `. \_) | |\| |\_) | |\| || .' // | | \ | \ | | | | \ | | | |`--' // | '--' / `' '-' ' `' '-' '.--. // `------' `-----' `-----' '--' } catch (err) { console.error("Something went wrong:", err); } ``` -------------------------------- ### metadata Source: https://github.com/patorjk/figlet.js/blob/main/README.md Retrieves a font's default options and header comment. Can be used with callbacks or promises. ```APIDOC ## metadata ### Description Retrieves a font's default options and header comment. ### Method `figlet.metadata(fontName, [callback])` or `await figlet.metadata(fontName)` ### Parameters #### Path Parameters - **fontName** (String) - The name of the font to retrieve metadata for. #### Callback (Optional) - **callback** (Function) - A function that accepts `err`, `options`, and `headerComment`. ### Request Example (Callback) ```js figlet.metadata("Standard", function (err, options, headerComment) { if (err) { console.log("something went wrong..."); console.dir(err); return; } console.dir(options); console.log(headerComment); }); ``` ### Request Example (Promise) ```js try { const [options, headerComment] = await figlet.metadata("Standard"); console.dir(options); console.log(headerComment); } catch (err) { console.log("something went wrong..."); console.dir(err); } ``` ### Response #### Success Response - **options** (Object) - An object containing the font's default options. - **headerComment** (String) - The header comment of the font. ``` -------------------------------- ### HZ Mode Character Encoding Source: https://github.com/patorjk/figlet.js/blob/main/doc/figfont.txt The 'h' command enables HZ mode for Chinese text. It defines how two-byte sequences starting with '~' are interpreted and processed, including specific handling for '~{' and '~~'. ```figlet first character * 256 + second character ``` -------------------------------- ### Generate ASCII Art with Callbacks (Node.js) Source: https://github.com/patorjk/figlet.js/blob/main/README.md Use the classic callback pattern with figlet.text to generate ASCII art. This method is suitable for older Node.js projects or when preferred over promises. ```javascript const figlet = require('figlet'); figlet("Hello World!!", function (err, data) { if (err) { console.log("Something went wrong..."); console.dir(err); return; } console.log(data); }); ``` -------------------------------- ### Generate ASCII Art Synchronously (Node.js) Source: https://github.com/patorjk/figlet.js/blob/main/README.md Generate ASCII art synchronously using figlet.textSync with custom options. This method blocks the event loop and should be used with caution, typically for simple scripts or during startup. ```javascript console.log( figlet.textSync("Boo!", { font: "Ghost", horizontalLayout: "default", verticalLayout: "default", width: 80, whitespaceBreak: true, }) ); ``` -------------------------------- ### Async Text Generation (Promise & Callback) Source: https://context7.com/patorjk/figlet.js/llms.txt Use the figlet object directly for shorthand async text generation. Supports Promise-based or Node-style callback usage. ```javascript import figlet from "figlet"; // Promise style — font name as string shorthand const art = await figlet("Hello World!", "Standard"); console.log(art); // Output: // _ _ _ _ __ __ _ _ _ _ // | | | | ___| | | ___ \ \ / /__ _ __| | __| | | | // | |_| |/ _ \ | |/ _ \ \ \ /\ / / _ \| '__| |/ _` | | | // | _ | __/ | | (_) | \ V V / (_) | | | | (_| |_|_| // |_| |_|\___|_|_|\___/ \_/\_/ \___/|_| |_|\__,_(_|_) // Callback style figlet("Hello!", "Ghost", function (err, data) { if (err) { console.error("Error:", err); return; } console.log(data); }); ``` -------------------------------- ### figlet.textSync Source: https://github.com/patorjk/figlet.js/blob/main/README.md Generates ASCII Art from text synchronously. It accepts input text and font options. This is the synchronous version of `figlet.text`. ```APIDOC ## figlet.textSync ### Description Generates ASCII Art from text synchronously. It accepts input text and font options. This is the synchronous version of `figlet.text`. ### Method `figlet.textSync(text, options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **Input Text** (string) - The text to convert into ASCII Art. - **Font Options** (object | string) - Either a string representing the font name or an options object. - **font** (string) - Default: `'Standard'`. The FIGlet font to use. - **horizontalLayout** (string) - Default: `'default'`. Horizontal layout option ('default', 'full', 'fitted', 'controlled smushing', 'universal smushing'). - **verticalLayout** (string) - Default: `'default'`. Vertical layout option. - **width** (number) - Default: `80`. The width of the output. - **whitespaceBreak** (boolean) - Default: `false`. Whether to break on whitespace. ### Request Example ```javascript console.log( figlet.textSync("Boo!", { font: "Ghost", horizontalLayout: "default", verticalLayout: "default", width: 80, whitespaceBreak: true, }) ); ``` ### Response #### Success Response - **data** (string) - The generated ASCII Art. #### Response Example ``` .-. .-') ,---. \ ( OO ) | | ;-----.\ .-'),-----. .-'),-----. | | | .-. | ( OO' .-. '( OO' .-. '| | | '-' /_)/ | | | |/ | | | || | | .-. `. \_) | |\| |\_) | |\| || .' | | \ | \ | | | | \ | | | |`--' | '--' / `' '-' ' `' '-' '.--. `------' `-----' `-----' '--' ``` ``` -------------------------------- ### Async Font Loading with figlet.loadFont() Source: https://context7.com/patorjk/figlet.js/llms.txt Asynchronously load, parse, and cache fonts by name. Subsequent calls for the same font are immediate. Supports both Promises and callbacks. ```javascript import figlet from "figlet"; // Load a font explicitly before calling textSync await figlet.loadFont("Graffiti"); const art = figlet.textSync("Loaded!", "Graffiti"); console.log(art); // With callback figlet.loadFont("Banner", function (err, fontOptions) { if (err) { console.error("Failed to load font:", err); return; } console.log("Banner font loaded, height:", fontOptions.height); console.log(figlet.textSync("Ready", "Banner")); }); ``` -------------------------------- ### Preload Multiple Fonts with figlet.preloadFonts() (Browser) Source: https://context7.com/patorjk/figlet.js/llms.txt Fetch and parse an array of fonts asynchronously, primarily for browser use to ensure fonts are ready for synchronous rendering. Returns a Promise resolving when all fonts are loaded. Also supports callbacks. ```javascript import figlet from "figlet"; // Set the font path to your static assets figlet.defaults({ fontPath: "assets/fonts" }); // Preload fonts before rendering synchronously await figlet.preloadFonts(["Standard", "Ghost", "Dancing Font"]); console.log(figlet.textSync("ASCII")); // uses Standard console.log(figlet.textSync("Art", "Ghost")); // uses Ghost // Callback style (useful in non-async contexts) figlet.preloadFonts(["Standard", "Big"], function (err) { if (err) { console.error("Preload error:", err); return; } document.querySelector("#output").textContent = figlet.textSync("Ready!"); }); ``` -------------------------------- ### Set Default Library Options Source: https://github.com/patorjk/figlet.js/blob/main/README.md Configures default settings for the Figlet.js library, such as the default font, font path, and fetch behavior in the browser. ```javascript figlet.defaults({ font: "Standard", // default font fontPath: "some-random-place/fonts", // default font path location fetchFontIfMissing: true, // for the browser, fetch a font if its missing }) ``` -------------------------------- ### figlet.loadFont(fontName, [callback]) Source: https://context7.com/patorjk/figlet.js/llms.txt Asynchronously loads a font by its name. It handles fetching the font file from disk (Node.js) or via `fetch` (browser), parsing it, and caching it for future use. Returns a Promise resolving to the font's metadata. ```APIDOC ## `figlet.loadFont(fontName, [callback])` — Async font loading Asynchronously loads a font by name from disk (Node.js) or via `fetch` (browser), parses it, and caches it. Returns a Promise resolving to the `FontMetadata` object. Subsequent calls for the same font return the cached result immediately. ### Parameters #### Path Parameters - **fontName** (string) - Required - The name of the font to load. - **callback** (function) - Optional - A callback function that receives an error and the font options. ### Request Example ```javascript import figlet from "figlet"; // Load a font explicitly before calling textSync await figlet.loadFont("Graffiti"); const art = figlet.textSync("Loaded!", "Graffiti"); console.log(art); // With callback figlet.loadFont("Banner", function (err, fontOptions) { if (err) { console.error("Failed to load font:", err); return; } console.log("Banner font loaded, height:", fontOptions.height); console.log(figlet.textSync("Ready", "Banner")); }); ``` ### Response #### Success Response - **fontOptions** (object) - The metadata of the loaded font. #### Error Response - **err** (Error) - An error object if the font fails to load. ``` -------------------------------- ### figlet.preloadFonts(fontNames, [callback]) Source: https://context7.com/patorjk/figlet.js/llms.txt Preloads multiple fonts asynchronously, primarily intended for browser environments to ensure fonts are available before synchronous rendering. It returns a Promise that resolves once all specified fonts are loaded. ```APIDOC ## `figlet.preloadFonts(fontNames, [callback])` — Preload multiple fonts (browser) Fetches and parses an array of fonts asynchronously. Designed for browser use to ensure fonts are available before calling `textSync`. Returns a Promise that resolves when all fonts are loaded. ### Parameters #### Path Parameters - **fontNames** (array of strings) - Required - An array of font names to preload. - **callback** (function) - Optional - A callback function that is called upon completion or error. ### Request Example ```javascript import figlet from "figlet"; // Set the font path to your static assets figlet.defaults({ fontPath: "assets/fonts" }); // Preload fonts before rendering synchronously await figlet.preloadFonts(["Standard", "Ghost", "Dancing Font"]); console.log(figlet.textSync("ASCII")); // uses Standard console.log(figlet.textSync("Art", "Ghost")); // uses Ghost // Callback style (useful in non-async contexts) figlet.preloadFonts(["Standard", "Big"], function (err) { if (err) { console.error("Preload error:", err); return; } document.querySelector("#output").textContent = figlet.textSync("Ready!"); }); ``` ### Response #### Success Response - None explicitly defined, resolves when all fonts are loaded. #### Error Response - **err** (Error) - An error object if any of the fonts fail to load. ``` -------------------------------- ### Browser Synchronous Text Generation with Figlet.js Source: https://github.com/patorjk/figlet.js/blob/main/README.md Use `textSync` in the browser when fonts are preloaded. Configure the font path and preload necessary fonts before calling `textSync`. ```javascript figlet.defaults({ fontPath: "assets/fonts" }); figlet.preloadFonts(["Standard", "Ghost"], ready); function ready() { console.log(figlet.textSync("ASCII")); console.log(figlet.textSync("Art", "Ghost")); } ``` -------------------------------- ### `figlet.fonts([callback])` — List available fonts Source: https://context7.com/patorjk/figlet.js/llms.txt Asynchronously retrieves a list of all available font names. Returns a Promise that resolves to an array of strings, or accepts an optional Node-style callback. ```APIDOC ## `figlet.fonts([callback])` — List available fonts ### Description Returns a Promise that resolves to an array of available font name strings. In Node.js, it reads the `fonts/` directory; in the browser it returns the built-in font list. Also accepts an optional Node-style callback. ### Method Asynchronous (Promise + optional callback) ### Endpoint N/A (Function call) ### Parameters - **callback** (function) - Optional - A Node-style callback function `(err, fonts) => {}`. ### Request Example ```javascript import figlet from "figlet"; // Promise style const fonts = await figlet.fonts(); console.log(fonts); // Callback style figlet.fonts(function (err, fonts) { if (err) { console.error("Error:", err); return; } fonts.sort().forEach((font) => console.log(font)); }); ``` ### Response #### Success Response - **(Array)** - An array of strings, where each string is the name of an available font. #### Error Response - **(Error)** - An error object if the font list cannot be retrieved. ``` -------------------------------- ### `figlet(text, [options|fontName], [callback])` — Shorthand async text generation Source: https://context7.com/patorjk/figlet.js/llms.txt This is a shorthand for `figlet.text` that generates ASCII art asynchronously. It returns a Promise that resolves to the generated string and also accepts an optional Node-style callback. ```APIDOC ## `figlet(text, [options|fontName], [callback])` — Shorthand async text generation ### Description Calling the `figlet` object directly as a function is a shorthand for `figlet.text`. It returns a Promise that resolves to the generated ASCII art string, and also accepts an optional Node-style callback as the last argument. ### Method Asynchronous (Promise + optional callback) ### Parameters - **text** (string) - Required - The input text to convert to ASCII art. - **options|fontName** (object|string) - Optional - Either a string representing the font name or an options object. - **callback** (function) - Optional - A Node-style callback function `(err, data) => {}`. ### Request Example ```javascript import figlet from "figlet"; // Promise style — font name as string shorthand const art = await figlet("Hello World!", "Standard"); console.log(art); // Callback style figlet("Hello!", "Ghost", function (err, data) { if (err) { console.error("Error:", err); return; } console.log(data); }); ``` ### Response #### Success Response - **(string)** - The generated ASCII art string. #### Error Response - **(Error)** - An error object if generation fails. ``` -------------------------------- ### Manage Global Defaults with figlet.defaults() Source: https://context7.com/patorjk/figlet.js/llms.txt Read or override global library defaults for font, font path, and fetch behavior. Returns a deep copy of the defaults. Changes affect subsequent calls to text generation. ```javascript import figlet from "figlet"; // Read current defaults const current = figlet.defaults(); console.log(current); // { font: 'Standard', fontPath: './fonts', fetchFontIfMissing: true } // Override defaults figlet.defaults({ font: "Big", fontPath: "assets/fonts", fetchFontIfMissing: false, // disable auto-fetch in browser }); // Now figlet.text("hi") will use "Big" font from "assets/fonts" const art = await figlet.text("hi"); console.log(art); ``` -------------------------------- ### figlet.defaults([opts]) Source: https://context7.com/patorjk/figlet.js/llms.txt Allows reading or overriding the global default settings for the Figlet library, such as the default font and font path. Returns a copy of the current defaults. ```APIDOC ## `figlet.defaults([opts])` — Get or set global defaults Reads or overrides the library's global defaults: `font` (default `"Standard"`), `fontPath` (default `"./fonts"`), and `fetchFontIfMissing` (default `true`). Returns a deep copy of the current defaults object. ### Parameters #### Path Parameters - **opts** (object) - Optional - An object containing properties to override the default settings. - **font** (string) - The default font to use. - **fontPath** (string) - The default path to look for fonts. - **fetchFontIfMissing** (boolean) - Whether to automatically fetch fonts if they are missing. ### Request Example ```javascript import figlet from "figlet"; // Read current defaults const current = figlet.defaults(); console.log(current); // Override defaults figlet.defaults({ font: "Big", fontPath: "assets/fonts", fetchFontIfMissing: false, // disable auto-fetch in browser }); // Now figlet.text("hi") will use "Big" font from "assets/fonts" const art = await figlet.text("hi"); console.log(art); ``` ### Response - **defaults** (object) - A deep copy of the current global defaults. ``` -------------------------------- ### List Available Fonts (Synchronous) Source: https://context7.com/patorjk/figlet.js/llms.txt Synchronous version of figlet.fonts. Returns the font name array immediately without I/O in browsers; reads the fonts directory synchronously in Node.js. ```javascript import figlet from "figlet"; const fonts = figlet.fontsSync(); console.log(`${fonts.length} fonts available`); // 250 fonts available console.log(fonts.slice(0, 5)); // ['1Row', '3-D', '3D Diagonal', '3D-ASCII', '3x5'] ``` -------------------------------- ### figlet.metadata(fontName, [callback]) Source: https://context7.com/patorjk/figlet.js/llms.txt Retrieves metadata and the header comment for a specified font. It supports both Promise-based and callback-based usage. ```APIDOC ## `figlet.metadata(fontName, [callback])` — Get font metadata and header comment Returns a Promise that resolves to a `[FontMetadata, string]` tuple containing the font's parsed options (height, layout rules, baseline, etc.) and the font's header comment block. Also accepts an optional callback. ### Parameters #### Path Parameters - **fontName** (string) - Required - The name of the font to retrieve metadata for. - **callback** (function) - Optional - A callback function that receives an error, options, and header comment. ### Request Example ```javascript import figlet from "figlet"; // Promise style const [options, headerComment] = await figlet.metadata("Standard"); console.dir(options); console.log(headerComment); // Callback style figlet.metadata("Ghost", function (err, options, headerComment) { if (err) { console.error("Error:", err); return; } console.log("Font height:", options.height); console.log("Comment:", headerComment); }); ``` ### Response #### Success Response - **options** (object) - An object containing font metadata like height, baseline, etc. - **headerComment** (string) - The header comment block of the font. #### Error Response - **err** (Error) - An error object if the font metadata cannot be retrieved. ``` -------------------------------- ### Synchronous ASCII Art Generation Source: https://context7.com/patorjk/figlet.js/llms.txt Synchronous version of figlet.text. Requires the target font to already be loaded. Ideal for Node.js scripts where async is not needed. ```javascript import figlet from "figlet"; // Node.js (font loaded from disk automatically) // Simple string font name console.log(figlet.textSync("Hello World!", "Standard")); // Full options object const art = figlet.textSync("Last time...", { font: "Standard", horizontalLayout: "full", verticalLayout: "full", }); console.log(art); ``` -------------------------------- ### `figlet.text(text, [options|fontName], [callback])` — Async ASCII art generation Source: https://context7.com/patorjk/figlet.js/llms.txt The primary asynchronous method for generating ASCII art. It supports a full options object for detailed control over font, layout, width, and line-breaking. Returns a Promise resolving to the ASCII art string. ```APIDOC ## `figlet.text(text, [options|fontName], [callback])` — Async ASCII art generation ### Description The primary async method for generating ASCII art. Accepts a full options object for fine-grained control over font, layout, width, and line-breaking behavior. Returns a Promise resolving to the ASCII art string. ### Method Asynchronous (Promise + optional callback) ### Endpoint N/A (Function call) ### Parameters - **text** (string) - Required - The input text to convert to ASCII art. - **options** (object) - Optional - An object containing generation options: - **font** (string) - The name of the font to use (e.g., "Ghost"). - **horizontalLayout** (string) - Horizontal layout mode (e.g., "default", "full", "fitted", "controlled smushing", "universal smushing"). - **verticalLayout** (string) - Vertical layout mode (e.g., "default"). - **width** (number) - The target width for the output. - **whitespaceBreak** (boolean) - Whether to break lines at whitespace. - **callback** (function) - Optional - A Node-style callback function `(err, data) => {}`. ### Request Example ```javascript import figlet from "figlet"; try { const art = await figlet.text("Boo!", { font: "Ghost", horizontalLayout: "default", verticalLayout: "default", width: 80, whitespaceBreak: true, }); console.log(art); } catch (err) { console.error("Something went wrong:", err); } ``` ### Response #### Success Response - **(string)** - The generated ASCII art string. #### Error Response - **(Error)** - An error object if generation fails. ``` -------------------------------- ### loadedFonts Source: https://github.com/patorjk/figlet.js/blob/main/README.md Returns an array of font names that have been loaded into memory. ```APIDOC ## loadedFonts ### Description Returns an array of font names that have been loaded into memory (e.g., via `loadFont` or `parseFont`). ### Method `figlet.loadedFonts()` ### Request Example ```js console.log(figlet.loadedFonts()); ``` ### Response #### Success Response - **fonts** (Array) - An array of loaded font names. ``` -------------------------------- ### List Cached Fonts with figlet.loadedFonts() Source: https://context7.com/patorjk/figlet.js/llms.txt Retrieve a list of font name strings for all fonts currently cached in memory. This is useful for verifying which fonts have been loaded. ```javascript import figlet from "figlet"; await figlet.loadFont("Standard"); await figlet.loadFont("Ghost"); console.log(figlet.loadedFonts()); // ['Standard', 'Ghost'] ``` -------------------------------- ### Generate ASCII Art with FIGlet.js Source: https://github.com/patorjk/figlet.js/blob/main/examples/front-end/index.htm Generates ASCII art from input text using specified font and layout options. This function is called on user input changes to dynamically update the displayed ASCII art. ```javascript let update = function () { let fontName = document.querySelector("#font option:checked").value, inputText = document.querySelector("#inputText").value, vLayout = document.querySelector("#vLayout option:checked").value, hLayout = document.querySelector("#hLayout option:checked").value, width = document.querySelector("#width option:checked").value, whitespaceBreak = document.querySelector("#whitespaceBreak option:checked").value; /* How to use the text output. The below call could also have been: figlet.text(...) */ figlet( inputText, { font: fontName, horizontalLayout: hLayout, verticalLayout: vLayout, width: width === "none" ? undefined : width, whitespaceBreak: width === "none" ? undefined : whitespaceBreak === "true" ? true : false, }, function (err, text) { if (err) { console.log("something went wrong..."); console.dir(err); return; } document.querySelector("#outputFigDisplay").innerHTML = "
" + text + "
"; }); /* How to read the metadata for a font */ /* figlet.metadata(fontName, function(err, options, headerComment) { if (err) { console.log('something went wrong...'); console.dir(err); return; } console.dir(options); console.log(headerComment); }); */ }; ``` -------------------------------- ### Import Fonts as JavaScript Modules in Browser Source: https://context7.com/patorjk/figlet.js/llms.txt In bundler-based browser environments, fonts can be imported directly as JavaScript modules from `figlet/fonts/` and registered with `parseFont`, avoiding runtime HTTP fetches. ```javascript import figlet from "figlet"; import standard from "figlet/fonts/Standard"; import ghost from "figlet/fonts/Ghost"; figlet.parseFont("Standard", standard); figlet.parseFont("Ghost", ghost); // Now textSync works without any network requests console.log(figlet.textSync("No fetch needed!", "Standard")); console.log(figlet.textSync("Spooky", "Ghost")); // Also works with the async API const art = await figlet.text("Bundled", { font: "Standard" }); console.log(art); ``` -------------------------------- ### parseFont Source: https://github.com/patorjk/figlet.js/blob/main/README.md Allows using a font from a custom source by providing its name and data. ```APIDOC ## parseFont ### Description Loads a font from a provided string of font data. This is useful for using custom or dynamically loaded fonts. ### Method `figlet.parseFont(fontName, fontData)` ### Parameters #### Path Parameters - **fontName** (String) - The name to assign to the font. - **fontData** (String) - The content of the font file (e.g., read from a .flf file). ### Request Example ```js const fs = require("fs"); const path = require("path"); let data = fs.readFileSync(path.join(__dirname, "myfont.flf"), "utf8"); figlet.parseFont("myfont", data); console.log(figlet.textSync("myfont!", "myfont")); ``` ``` -------------------------------- ### FIGlet.js Event Listeners for GUI Controls Source: https://github.com/patorjk/figlet.js/blob/main/examples/front-end/index.htm Attaches event listeners to various GUI controls to trigger ASCII art updates when user selections change. This ensures the output reflects the current settings. ```javascript /* GUI Controls */ document.querySelector("#hLayout").addEventListener("change", update); document.querySelector("#vLayout").addEventListener("change", update); document.querySelector("#font").addEventListener("change", update); document.querySelector("#inputText").addEventListener("keyup", update); document.querySelector("#width").addEventListener("change", update); document.querySelector("#whitespaceBreak").addEventListener("change", update); update(); // init ```