Creates ASCII Art from text with a full implementation of the FIGfont specification
npx @tessl/cli install tessl/npm-figlet@1.8.0FIGlet creates ASCII art from text using a comprehensive implementation of the FIGfont specification. It provides both synchronous and asynchronous APIs for text conversion, supports extensive font management with 400+ built-in fonts, and offers advanced layout control with horizontal and vertical fitting rules for precise output formatting.
npm install figletconst figlet = require("figlet");For ES modules:
import figlet from "figlet";Individual function imports:
const { text, textSync, loadFont, fonts } = require("figlet");const figlet = require("figlet");
// Simple async usage with callback
figlet("Hello World", function(err, data) {
if (err) {
console.log("Error:", err);
return;
}
console.log(data);
});
// Promise-based usage
figlet.text("Hello World", { font: "Ghost" })
.then(data => console.log(data))
.catch(err => console.error(err));
// Synchronous usage (Node.js only)
try {
const result = figlet.textSync("Hello World", { font: "Big" });
console.log(result);
} catch (err) {
console.error(err);
}FIGlet is built around several key components:
Core text-to-ASCII conversion functionality supporting both synchronous and asynchronous operations with extensive font and layout options.
// Main function (alias for figlet.text)
function figlet(text, options, callback);
// Async text generation
function text(text, options, callback);
// Sync text generation (Node.js only)
function textSync(text, options);Font loading, listing, and management system supporting both browser and Node.js environments with comprehensive font discovery.
// Load font asynchronously
function loadFont(name, callback);
// Load font synchronously (Node.js only)
function loadFontSync(name);
// Preload multiple fonts
function preloadFonts(fonts, callback);
// List available fonts (Node.js only)
function fonts(callback);
function fontsSync();Configuration management, default settings, and font metadata access for advanced usage scenarios.
// Configure defaults
function defaults(options);
// Font metadata access
function metadata(fontName, callback);
// Font parsing
function parseFont(fontName, data);
// Internal font storage (read-only access)
figlet.figFonts;// Options interface for text generation
interface FigletOptions {
font?: string; // Font name (default: "Standard")
horizontalLayout?: string; // "default" | "full" | "fitted" | "controlled smushing" | "universal smushing"
verticalLayout?: string; // "default" | "full" | "fitted" | "controlled smushing" | "universal smushing"
width?: number; // Text width limit (-1 for unlimited)
whitespaceBreak?: boolean; // Enable whitespace-aware line breaking
printDirection?: number; // 0 = left-to-right, 1 = right-to-left
showHardBlanks?: boolean; // Show hard blank characters
}
// Font metadata structure
interface FontMetadata {
hardBlank: string;
height: number;
baseline: number;
maxLength: number;
oldLayout: number;
numCommentLines: number;
printDirection: number;
fullLayout: number;
codeTagCount: number;
fittingRules: object;
}
// Error types
class Error {
message: string;
name: string;
}