figlet.js
A FIG Driver written in JavaScript which aims to fully implement the FIGfont spec.
Top Related Projects
A general purpose syntax highlighter in pure Go
An implementation of figlet written in Python
my collection of figlet / toilet ascii art fonts
Quick Overview
FIGlet.js is a JavaScript library that generates ASCII art text from regular text input. It's a full implementation of FIGlet (Frank, Ian & Glenn's letters) in JavaScript, allowing developers to create stylized text for console applications, web interfaces, or any text-based project.
Pros
- Easy to use with a simple API
- Supports a wide variety of FIGlet fonts
- Can be used in both browser and Node.js environments
- Lightweight and has no dependencies
Cons
- Limited customization options beyond font selection
- Some fonts may not render correctly in all environments
- Performance can be slow for large amounts of text
- Documentation could be more comprehensive
Code Examples
- Basic usage:
const figlet = require('figlet');
figlet('Hello World!', function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
});
- Using a specific font:
const figlet = require('figlet');
figlet.text('Cool Text!', {
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);
});
- Synchronous usage:
const figlet = require('figlet');
console.log(figlet.textSync('Sync Text', {
font: 'Standard',
horizontalLayout: 'default',
verticalLayout: 'default'
}));
Getting Started
To use FIGlet.js in your project, follow these steps:
-
Install the package:
npm install figlet
-
Import and use in your JavaScript file:
const figlet = require('figlet'); figlet('Your Text Here', function(err, data) { if (err) { console.log('Something went wrong...'); console.dir(err); return; } console.log(data); });
This will output your text in ASCII art format using the default font. You can explore more options and fonts in the library's documentation.
Competitor Comparisons
A general purpose syntax highlighter in pure Go
Pros of Chroma
- Written in Go, offering better performance for syntax highlighting
- Supports a wider range of programming languages and file formats
- More actively maintained with frequent updates and contributions
Cons of Chroma
- Larger codebase and more complex to contribute to or modify
- Requires Go knowledge for development, unlike Figlet.js which uses JavaScript
- May be overkill for simple text styling needs compared to Figlet.js
Code Comparison
Figlet.js (JavaScript):
var figlet = require('figlet');
figlet('Hello World!', function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
});
Chroma (Go):
package main
import (
"fmt"
"github.com/alecthomas/chroma/quick"
)
func main() {
code := `print("Hello, World!")`
err := quick.Highlight(os.Stdout, code, "python", "terminal", "monokai")
if err != nil {
panic(err)
}
}
While Figlet.js focuses on ASCII art text generation, Chroma specializes in syntax highlighting for various programming languages. Figlet.js is simpler to use for basic text styling, while Chroma offers more advanced features for code highlighting and formatting.
An implementation of figlet written in Python
Pros of pyfiglet
- Written in Python, making it more accessible for Python developers
- Supports a wider range of font files, including those from the original FIGlet program
- Includes a command-line interface for easy use outside of Python scripts
Cons of pyfiglet
- Generally slower performance compared to figlet.js
- Less actively maintained, with fewer recent updates
- Limited browser support, as it's primarily designed for server-side use
Code Comparison
figlet.js:
const figlet = require('figlet');
figlet('Hello World!', function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
});
pyfiglet:
from pyfiglet import Figlet
f = Figlet(font='slant')
print(f.renderText('Hello World!'))
Both libraries aim to provide ASCII art text generation, but they cater to different ecosystems. figlet.js is more suitable for JavaScript and Node.js projects, offering better performance and active maintenance. pyfiglet, on the other hand, is ideal for Python developers and those who need compatibility with a wider range of FIGlet fonts. The choice between the two largely depends on the programming language and specific requirements of your project.
my collection of figlet / toilet ascii art fonts
Pros of figlet-fonts
- Extensive collection of FIGlet fonts (over 270 fonts)
- Focused solely on providing font files, making it lightweight
- Regular updates and contributions from the community
Cons of figlet-fonts
- No built-in JavaScript functionality for rendering FIGlet text
- Requires additional tools or libraries to use the fonts in projects
- Limited documentation on font usage and integration
Code Comparison
figlet.js:
const figlet = require('figlet');
figlet('Hello World!', function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
});
figlet-fonts: No direct code comparison available, as figlet-fonts is a collection of font files rather than a JavaScript library. To use these fonts, you would typically need to integrate them with a FIGlet rendering library like figlet.js.
Summary
figlet.js is a JavaScript library that provides functionality for rendering FIGlet text, while figlet-fonts is a comprehensive collection of FIGlet font files. figlet.js offers easy integration and usage in JavaScript projects, whereas figlet-fonts provides a wider variety of font options but requires additional tools for implementation. Developers may choose to use both repositories in conjunction, leveraging the rendering capabilities of figlet.js with the extensive font selection from figlet-fonts.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
___________.___ ________.__ __ __
\_ _____/| |/ _____/| | _____/ |_ |__| ______
| __) | / \ ___| | _/ __ \ __\ | |/ ___/
| \ | \ \_\ \ |_\ ___/| | | |\___ \
\___ / |___|\______ /____/\___ >__| /\ /\__| /____ >
\/ \/ \/ \/ \______| \/
This project aims to fully implement the FIGfont spec in JavaScript. It works in the browser and with Node.js. You can see it in action here: http://patorjk.com/software/taag/ (the figlet.js file was written to power that application)
Quick Start - Node.js
Install:
npm install figlet
Simple usage:
var figlet = require("figlet");
figlet("Hello World!!", function (err, data) {
if (err) {
console.log("Something went wrong...");
console.dir(err);
return;
}
console.log(data);
});
That should print out:
_ _ _ _ __ __ _ _ _ _
| | | | ___| | | ___ \ \ / /__ _ __| | __| | | |
| |_| |/ _ \ | |/ _ \ \ \ /\ / / _ \| '__| |/ _` | | |
| _ | __/ | | (_) | \ V V / (_) | | | | (_| |_|_|
|_| |_|\___|_|_|\___/ \_/\_/ \___/|_| |_|\__,_(_|_)
Basic Usage - Node.js
text
Calling the figlet object as a function is shorthand for calling the text function. This method allows you to create ASCII Art from text. It takes in 3 parameters:
- Input Text - A string of text to turn into ASCII Art.
- Options - Either a string indicating the font name or an options object (description below).
- Callback - A function to execute with the generated ASCII Art.
Example:
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);
}
);
That will print out:
.-. .-') ,---.
\ ( OO ) | |
;-----.\ .-'),-----. .-'),-----. | |
| .-. | ( OO' .-. '( OO' .-. '| |
| '-' /_)/ | | | |/ | | | || |
| .-. `. \_) | |\| |\_) | |\| || .'
| | \ | \ | | | | \ | | | |`--'
| '--' / `' '-' ' `' '-' '.--.
`------' `-----' `-----' '--'
textSync
This method is the synchronous version of the method above.
- Input Text - A string of text to turn into ASCII Art.
- Font Options - Either a string indicating the font name or an options object (description below).
Example:
console.log(
figlet.textSync("Boo!", {
font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
})
);
That will print out:
.-. .-') ,---.
\ ( OO ) | |
;-----.\ .-'),-----. .-'),-----. | |
| .-. | ( OO' .-. '( OO' .-. '| |
| '-' /_)/ | | | |/ | | | || |
| .-. `. \_) | |\| |\_) | |\| || .'
| | \ | \ | | | | \ | | | |`--'
| '--' / `' '-' ' `' '-' '.--.
`------' `-----' `-----' '--'
Options
The options object has several parameters which you can set:
font
Type: String
Default value: 'Standard'
A string value that indicates the FIGlet font to use.
horizontalLayout
Type: String
Default value: 'default'
A string value that indicates the horizontal layout to use. FIGlet fonts have 5 possible values for this: "default", "full", "fitted", "controlled smushing", and "universal smushing". "default" does the kerning the way the font designer intended, "full" uses full letter spacing, "fitted" moves the letters together until they almost touch, and "controlled smushing" and "universal smushing" are common FIGlet kerning setups.
verticalLayout
Type: String
Default value: 'default'
A string value that indicates the vertical layout to use. FIGlet fonts have 5 possible values for this: "default", "full", "fitted", "controlled smushing", and "universal smushing". "default" does the kerning the way the font designer intended, "full" uses full letter spacing, "fitted" moves the letters together until they almost touch, and "controlled smushing" and "universal smushing" are common FIGlet kerning setups.
width
Type: Number
Default value: undefined
This option allows you to limit the width of the output. For example, if you want your output to be a max of 80 characters wide, you would set this option to 80. Example
whitespaceBreak
Type: Boolean
Default value: false
This option works in conjunction with "width". If this option is set to true, then the library will attempt to break text up on whitespace when limiting the width. Example
Understanding Kerning
The 2 layout options allow you to override a font's default "kerning". Below you can see how this effects the text. The string "Kerning" was printed using the "Standard" font with horizontal layouts of "default", "fitted" and then "full".
_ __ _
| |/ /___ _ __ _ __ (_)_ __ __ _
| ' // _ \ '__| '_ \| | '_ \ / _` |
| . \ __/ | | | | | | | | | (_| |
|_|\_\___|_| |_| |_|_|_| |_|\__, |
|___/
_ __ _
| |/ / ___ _ __ _ __ (_) _ __ __ _
| ' / / _ \| '__|| '_ \ | || '_ \ / _` |
| . \| __/| | | | | || || | | || (_| |
|_|\_\\___||_| |_| |_||_||_| |_| \__, |
|___/
_ __ _
| |/ / ___ _ __ _ __ (_) _ __ __ _
| ' / / _ \ | '__| | '_ \ | | | '_ \ / _` |
| . \ | __/ | | | | | | | | | | | | | (_| |
|_|\_\ \___| |_| |_| |_| |_| |_| |_| \__, |
|___/
In most cases you'll either use the default setting or the "fitted" setting. Most fonts don't support vertical kerning, but a hand full of them do (like the "Standard" font).
metadata
The metadata function allows you to retrieve a font's default options and header comment. Example usage:
figlet.metadata("Standard", function (err, options, headerComment) {
if (err) {
console.log("something went wrong...");
console.dir(err);
return;
}
console.dir(options);
console.log(headerComment);
});
fonts
The fonts function allows you to get a list of all of the available fonts. Example usage:
figlet.fonts(function (err, fonts) {
if (err) {
console.log("something went wrong...");
console.dir(err);
return;
}
console.dir(fonts);
});
fontsSync
The synchronous version of the fonts method
console.log(figlet.fontsSync());
parseFont
Allows you to use a font from another source.
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"));
Getting Started - Webpack / React
Webpack/React usage will be very similar to what's talked about in the "Getting Started - The Browser" section. The main difference is that you import fonts via the importable-fonts folder. Example:
import figlet from "figlet";
import standard from "figlet/importable-fonts/Standard.js";
figlet.parseFont("Standard", standard);
figlet.text(
"test",
{
font: "Standard",
},
function (err, data) {
console.log(data);
}
);
Getting Started - The Browser
The browser API is the same as the Node API with the exception of the "fonts" method not being available. The browser version also requires fetch API (or a shim) for its loadFont function.
Example usage:
<script
type="text/javascript"
src="//cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"
></script>
<script type="text/javascript" src="figlet.js"></script>
<script>
figlet(inputText, "Standard", function (err, text) {
if (err) {
console.log("something went wrong...");
console.dir(err);
return;
}
console.log(text);
});
</script>
textSync
The browser API supports synchronous mode so long as fonts used are preloaded.
Example:
figlet.defaults({ fontPath: "assets/fonts" });
figlet.preloadFonts(["Standard", "Ghost"], ready);
function ready() {
console.log(figlet.textSync("ASCII"));
console.log(figlet.textSync("Art", "Ghost"));
}
That will print out:
_ ____ ____ ___ ___
/ \ / ___| / ___||_ _||_ _|
/ _ \ \___ \ | | | | | |
/ ___ \ ___) || |___ | | | |
/_/ \_\|____/ \____||___||___|
('-. _ .-') .-') _
( OO ).-.( \( -O ) ( OO) )
/ . --. / ,------. / '._
| \-. \ | /`. '|'--...__)
.-'-' | | | / | |'--. .--'
\| |_.' | | |_.' | | |
| .-. | | . '.' | |
| | | | | |\ \ | |
`--' `--' `--' '--' `--'
See the examples folder for a more robust front-end example.
Getting Started - Command Line
To use figlet.js on the command line, install figlet-cli:
npm install -g figlet-cli
And then you should be able run from the command line. Example:
figlet -f "Dancing Font" "Hi"
For more info see the figlet-cli.
Contributors
Thanks goes to these people: (emoji key)
Release History
- 2023.04.08 v1.6.0 Added npx support (ex: npx figlet test).
- 2021.08.11 v1.5.2 Minor bug fixes.
- 2020.07.12 v1.5.1 Fixed with vertical smushing, updated lodash version.
- 2020.07.12 v1.5.0 Added width and whitespaceBreak options.
- 2020.04.26 v1.4.0 Removed jQuery from preloader and examples.
- 2020.02.23 v1.3.0 Added the "ANSI Regular" font and updated the README with info on how to use with Webpack.
- 2018.03.26 v1.2.1 parseFont works in node for adding fonts manually
- 2016.09.27 v1.2.0 jQuery replaced with fetch API / polyfill.
- 2016.04.28 v1.1.2 textSync now works in the browser with font pre-loading.
- 2014.08.15 v1.1.0 Sync functions added.
- 2014.07.31 v1.0.1 Bug fixes.
- 2013.12.28 v1.0.7 README update and minor tweaks.
- 2013.01.02 v1.0.8 Added tests and command line info.
Top Related Projects
A general purpose syntax highlighter in pure Go
An implementation of figlet written in Python
my collection of figlet / toilet ascii art fonts
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot