Install figlet
mainTo use figlet in a Node.js project, install it via npm:
npm install figletTo use the figlet CLI globally, install it with the -g flag:
npm install -g figletrepository·main·Indexed 25 days ago
https://github.com/patorjk/figlet.jsA full implementation of the FIGfont specification in TypeScript that creates ASCII art from text. It supports both Node.js and browser environments, providing asynchronous (text()) and synchronous (textSync()) methods, a command-line interface (CLI), and the ability to load custom fonts via parseFont().
To use figlet in a Node.js project, install it via npm:
npm install figletTo use the figlet CLI globally, install it with the -g flag:
npm install -g figletWhen using ES modules in the browser, you should import the font files and parse them into figlet to ensure they are available.
import figlet from "figlet";
import standard from "figlet/fonts/Standard";
// Register the font
figlet.parseFont("Standard", standard);
async function doStuff() {
const text = await figlet.text("test", { font: "Standard" });
console.log(text);
}
doStuff();To use textSync() in the browser, you must preload the fonts first using preloadFonts().
figlet.defaults({ fontPath: "assets/fonts" });
figlet.preloadFonts(["Standard", "Ghost"], () => {
console.log(figlet.textSync("ASCII"));
console.log(figlet.textSync("Art", "Ghost"));
});You can pass an options object to text() or textSync() to customize the output:
| Option | Type | Default | Description |
|---|---|---|---|
font | String | 'Standard' | The FIGlet font to use. |
horizontalLayout | String | 'default' | Horizontal layout: "default", "full", "fitted", "controlled smushing", or "universal smushing". |
verticalLayout | String | 'default' | Vertical layout: "default", "full", "fitted", "controlled smushing", or "universal smushing". |
width | Number | undefined | Limits the output width in characters. |
whitespaceBreak | Boolean | false | If true, attempts to break text at whitespace when limiting width. |
When using smushmode -1 with the NV Script font, you may need to perform manual kerning to ensure letters connect properly:
'8' to fill gaps between letters.figlet CLI, use the --list (or -l) flag without providing any text.The NV Script font includes a second set of lowercase characters with special ligatures. To access these characters, use the character code 200 + the letter of the alphabet.
For example:
201 is 'a'226 is 'z'b + 215 + 213 + b.On Windows, you can enter these codes using Alt+# on the numpad. In other environments, you may need to use character encoding methods (e.g., perl -e 'print chr(210)' to get a special 'j').
--info <font> (or -i <font>) flag. This will output the font name and its configuration options in JSON format.The textSync() method is the synchronous version of text(). It is useful in environments where blocking is acceptable or when fonts are already preloaded (especially in the browser).
Parameters:
Input Text: A string to convert.Font Options: A string (font name) or an options object.import figlet from "figlet";
const ascii = figlet.textSync("Boo!", {
font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
});
console.log(ascii);You can use fonts from external sources by providing the raw font data via parseFont(name, data).
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"));The metadata() function retrieves a font's default options and header comment. It supports both a callback pattern and a Promise pattern (returning an array [options, headerComment]).
try {
const [options, headerComment] = await figlet.metadata("Standard");
console.dir(options);
console.log(headerComment);
} catch (err) {
console.error(err);
}The text() method (or calling the figlet object directly as a function) creates ASCII art from text. It is asynchronous and returns a Promise that resolves to the generated ASCII art. It also supports a classic callback pattern.
Parameters:
Input Text: A string to convert.Options: A string (font name) or an options object.Callback (Optional): A function (err, data) => void.import figlet from "figlet";
async function doStuff() {
const text = await figlet.text("Hello World!!");
console.log(text);
}
doStuff();Use fonts() (asynchronous) or fontsSync() (synchronous) to get a list of available fonts.
fonts() looks in the local fonts folder (configurable via defaults()).loadedFonts().