figlet-go
v0.1.2
Published
FIGlet ASCII art text generator - WebAssembly module compiled from Go
Downloads
12
Maintainers
Readme
figlet-go
FIGlet ASCII art text generator - WebAssembly module compiled from Go
Generate beautiful ASCII art text from your JavaScript/Node.js applications using the power of WebAssembly.
Installation
npm install figlet-goQuick Start
const figlet = require('figlet-go');
// Simple rendering
const art = await figlet.render('Hello!');
console.log(art);
// Output:
// _ _ _ _ _
// | | | | ___| | | ___ | |
// | |_| |/ _ \ | |/ _ \| |
// | _ | __/ | | (_) |_|
// |_| |_|\___|_|_|\___/(_)API Reference
render(text: string): Promise<string>
Render text using the default font (standard).
const art = await figlet.render('Hello');renderWithFont(text: string, font: string): Promise<string>
Render text with a specific font.
const art = await figlet.renderWithFont('Hello', 'slant');listFonts(): Promise<string[]>
Get a list of all available fonts.
const fonts = await figlet.listFonts();
console.log(fonts); // ['banner', 'big', 'block', ...]getVersion(): Promise<string>
Get the FIGlet version.
const version = await figlet.getVersion();
console.log(version); // '2.2.5'createInstance(options?): Promise<FigletInstance>
Create a configured FIGlet instance for more control.
const fig = await figlet.createInstance({
font: 'slant',
width: 100,
justification: 'center'
});
const result = fig.render('Hello');
console.log(result.result);Multi-Instance Support
Each instance created with createInstance is fully isolated. This means you can maintain different configurations (font, width, smush modes, etc.) simultaneously without interference.
const fig1 = await figlet.createInstance({ font: 'standard', deutsch: false });
const fig2 = await figlet.createInstance({ font: 'standard', deutsch: true });
// [ will render differently in each instance
console.log(fig1.render('[').result);
console.log(fig2.render('[').result);Options
| Option | Type | Description |
|--------|------|-------------|
| font | string | Font name to use |
| width | number | Output width (default: 80) |
| justification | 'left' \| 'center' \| 'right' \| 'auto' | Text alignment |
| colors | string[] | Array of color names or hex codes (requires HTML parser) |
| parser | 'terminal' \| 'terminal-color' \| 'html' | Output format |
| smushMode | number | Smushing mode (0: kerning, -1: full width, 1-63: smushing) |
| rightToLeft | number | Text direction (0: left, 1: right, -1: auto) |
| paragraph | boolean | Enable paragraph mode |
| deutsch | boolean | Enable Deutsch character mapping ([ -> Ä, etc.) |
FigletInstance Methods
All instance methods return a boolean indicating success, except render, renderWithFont, listFonts, and getVersion.
render(text: string): RenderResultrenderWithFont(text: string, font: string): RenderResultsetFont(font: string): FontResultsetWidth(width: number): booleansetJustification(align: 'left' | 'center' | 'right' | 'auto'): booleansetColors(colors: string[]): booleansetParser(parser: string): booleansetSmushMode(mode: number): booleansetRightToLeft(mode: number): booleansetParagraph(enabled: boolean): booleansetDeutsch(enabled: boolean): booleanaddControlFile(name: string): booleanclearControlFiles(): boolean
Available Fonts
The package includes 146 built-in fonts from the FIGlet font database:
Popular fonts: standard, banner, big, block, slant, shadow, script, small, doom, graffiti, starwars, larry3d, colossal, gothic, epic, poison, roman, rounded, speed, stellar, and many more!
Use listFonts() to see all available fonts.
Browser Usage
<script src="https://unpkg.com/figlet-go/dist/wasm_exec.js"></script>
<script type="module">
import figlet from 'https://unpkg.com/figlet-go/dist/index.mjs';
// Initialize with WASM path
await figlet.init('https://unpkg.com/figlet-go/dist/figlet.wasm');
const art = await figlet.render('Hello Web!');
console.log(art);
</script>Animation Support
FIGlet-Go supports high-performance animations! You can list available animation types and generate frames directly:
// List available animations
const animations = await figlet.listAnimations();
// ['reveal', 'scroll', 'rain', 'wave', 'explosion']
// Generate frames for an animation
const frames = await figlet.generateAnimation('Hello!', 'wave', 50);
// Each frame contains:
// - content: The rendered string for this frame
// - delay: Suggested delay in ms
// - baselineOffset: Vertical offset for the frame
console.log(frames[0].content);Stable Color Mapping
All animations support high-fidelity, character-pinned coloring. Characters maintain their colors as they move, ensuring smooth and professional effects. 坐
TypeScript Support
Full TypeScript definitions are included:
import figlet, { FigletInstance } from 'figlet-go';
const art: string = await figlet.render('Hello');
const fonts: string[] = await figlet.listFonts();
const instance: FigletInstance = await figlet.createInstance({
font: 'slant',
justification: 'center'
});Examples
Generate multiple styles
const figlet = require('figlet-go');
const fonts = ['standard', 'slant', 'banner', 'big'];
for (const font of fonts) {
console.log(`\n--- ${font} ---\n`);
const art = await figlet.renderWithFont('Hello', font);
console.log(art);
}Custom width and alignment
const fig = await figlet.createInstance({
font: 'small',
width: 60,
justification: 'center'
});
const result = fig.render('Centered');
console.log(result.result);Performance
This package uses WebAssembly compiled from Go, providing:
- Fast rendering: Native-speed text generation
- 146 fonts: All fonts from figlet.org embedded
- Consistent output: Same results across all platforms
- Multi-Instance: Isolated configurations for concurrent use
Development
Running Tests
To run the test suite, you need to have Node.js and Go installed.
# Run from the root directory
make test-npm
# Or from the npm directory
cd npm
npm install
npm testLinks
License
BSD-3-Clause © Leandro Ferreira
Based on FIGlet by Glenn Chappell, Ian Chai, John Cowan, Christiaan Keet, and Claudio Matsuoka.
