Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
The figlet npm package allows you to create text banners in various ASCII art fonts. It is useful for adding stylistic text to command-line interfaces, logs, or any text-based output.
Basic Text to ASCII Art Conversion
This feature allows you to convert a simple string into an ASCII art representation. The code sample demonstrates how to convert the string 'Hello, World!' into ASCII art.
const figlet = require('figlet');
figlet('Hello, World!', function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
});
Custom Fonts
This feature allows you to specify a custom font for the ASCII art. The code sample demonstrates how to use the 'Ghost' font to render the string 'Hello, World!'.
const figlet = require('figlet');
figlet.text('Hello, World!', {
font: 'Ghost'
}, function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
});
Synchronous API
This feature provides a synchronous API for converting text to ASCII art. The code sample demonstrates how to synchronously convert the string 'Hello, World!' into ASCII art.
const figlet = require('figlet');
console.log(figlet.textSync('Hello, World!'));
The cowsay package generates ASCII pictures of a cow with a speech bubble containing a message. It is similar to figlet in that it creates ASCII art, but it focuses on generating cow characters with speech bubbles rather than stylized text.
The ascii-art package provides a wide range of ASCII art functionalities, including text-to-ASCII conversion, image-to-ASCII conversion, and more. It is more versatile than figlet, which focuses primarily on text-to-ASCII conversion.
The cli-banner package allows you to create customizable banners for command-line interfaces. It offers more customization options compared to figlet, such as colors and border styles, but it may not have as many font options.
___________.___ ________.__ __ __
\_ _____/| |/ _____/| | _____/ |_ |__| ______
| __) | / \ ___| | _/ __ \ __\ | |/ ___/
| \ | \ \_\ \ |_\ ___/| | | |\___ \
\___ / |___|\______ /____/\___ >__| /\ /\__| /____ >
\/ \/ \/ \/ \______| \/
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)
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 / (_) | | | | (_| |_|_|
|_| |_|\___|_|_|\___/ \_/\_/ \___/|_| |_|\__,_(_|_)
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:
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' .-. '| |
| '-' /_)/ | | | |/ | | | || |
| .-. `. \_) | |\| |\_) | |\| || .'
| | \ | \ | | | | \ | | | |`--'
| '--' / `' '-' ' `' '-' '.--.
`------' `-----' `-----' '--'
Similary you can use Promise API:
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);
}
This will print the same output.
This method is the synchronous version of the method above.
Example:
console.log(
figlet.textSync("Boo!", {
font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
})
);
That will print out:
.-. .-') ,---.
\ ( OO ) | |
;-----.\ .-'),-----. .-'),-----. | |
| .-. | ( OO' .-. '( OO' .-. '| |
| '-' /_)/ | | | |/ | | | || |
| .-. `. \_) | |\| |\_) | |\| || .'
| | \ | \ | | | | \ | | | |`--'
| '--' / `' '-' ' `' '-' '.--.
`------' `-----' `-----' '--'
The options object has several parameters which you can set:
Type: String
Default value: 'Standard'
A string value that indicates the FIGlet font to use.
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.
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.
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
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
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).
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);
});
The function also return a promise that return an array with two values:
try {
const [options, headerComment] = await figlet.metadata("Standard");
console.dir(options);
console.log(headerComment);
} catch (err) {
console.log("something went wrong...");
console.dir(err);
}
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);
});
fonts
is Node.js only.
The synchronous version of the fonts method
console.log(figlet.fontsSync());
same as fonts
, fontsSync
is Node.js only.
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"));
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);
}
);
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>
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.
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.
Thanks goes to these people: (emoji key)
FAQs
Creates ASCII Art from text. A full implementation of the FIGfont spec.
The npm package figlet receives a total of 1,079,412 weekly downloads. As such, figlet popularity was classified as popular.
We found that figlet demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.