10 Commits

8 changed files with 173 additions and 221 deletions

18
.gitignore vendored
View File

@ -1,5 +1,19 @@
.nogit/
node_modules/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
#------# custom

View File

@ -1,5 +1,36 @@
# Changelog
## 2025-01-14 - 1.0.10 - fix(test)
Add logging for rendered text outputs in test cases
- Added console.log statements for outputs of rendered ASCII art in test cases.
- Ensure the correctness of rendering operations by outputting results during tests.
## 2025-01-14 - 1.0.9 - fix(npm)
Updated package description and added more keywords for better visibility
## 2025-01-14 - 1.0.8 - fix(documentation)
Update README to reflect recent changes
- Updated package description for accuracy.
- Adjusted installation instructions for clarity.
- Added a new command-line interface example.
- Enhanced section on error handling with illustrative examples.
- Simplified integration guidelines with web servers using Express.
## 2025-01-14 - 1.0.7 - fix(core)
Improve error messages in renderText and listFonts methods
- Improved error handling in renderText and listFonts methods
- Ensure proper rejection messages during errors
## 2025-01-14 - 1.0.6 - fix(core)
Update .gitignore to improve ignored paths
- Ignored various build and cache directories to reduce clutter in the repository.
- Refactored .gitignore to categorize ignored paths for better readability and maintenance.
## 2025-01-14 - 1.0.5 - fix(package)
Fix scripts section in package.json by adding missing comma

View File

@ -10,15 +10,22 @@
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "beautyfiglet",
"description": "A Node.js module for creating figlet text displays.",
"description": "A Node.js module for creating customizable ASCII art using figlet with options for different fonts and layouts.",
"npmPackagename": "@push.rocks/beautyfiglet",
"license": "MIT",
"keywords": [
"ASCII art",
"figlet",
"text display",
"Node.js",
"npm module",
"typescript"
"text rendering",
"font customization",
"Node.js module",
"typescript",
"command-line interface",
"error handling",
"web integration",
"npm package",
"testing",
"synchronous rendering"
]
}
},

View File

@ -1,7 +1,7 @@
{
"name": "@push.rocks/beautyfiglet",
"version": "1.0.5",
"description": "A Node.js module for creating figlet text displays.",
"version": "1.0.10",
"description": "A Node.js module for creating customizable ASCII art using figlet with options for different fonts and layouts.",
"exports": {
".": "./dist_ts/index.js"
},
@ -22,11 +22,18 @@
"url": "https://code.foss.global/push.rocks/beautyfiglet.git"
},
"keywords": [
"ASCII art",
"figlet",
"text display",
"Node.js",
"npm module",
"typescript"
"text rendering",
"font customization",
"Node.js module",
"typescript",
"command-line interface",
"error handling",
"web integration",
"npm package",
"testing",
"synchronous rendering"
],
"devDependencies": {
"@git.zone/tsbuild": "^2.2.0",

View File

@ -1 +0,0 @@

298
readme.md
View File

@ -1,10 +1,9 @@
```markdown
# @push.rocks/beautyfiglet
figlet display in nodejs
A Node.js module that facilitates the creation of ASCII art using figlet with customizable fonts and layouts.
## Install
To install `@push.rocks/beautyfiglet`, you need to have Node.js and npm installed on your machine. Then, you can install it via npm:
To install `@push.rocks/beautyfiglet`, ensure you have Node.js along with npm set up on your machine. Executing the following command in your terminal will install this module via npm:
```sh
npm install @push.rocks/beautyfiglet
@ -15,12 +14,12 @@ Alternatively, you can add it as a dependency in your `package.json`:
```json
{
"dependencies": {
"@push.rocks/beautyfiglet": "^1.0.3"
"@push.rocks/beautyfiglet": "^1.0.8"
}
}
```
Then run:
Then execute:
```sh
npm install
@ -28,315 +27,208 @@ npm install
## Usage
The `@push.rocks/beautyfiglet` package is designed to allow you to display figlet text in your nodejs application. Below are instructions and examples on how to use it efficiently in your projects. We will cover all functionalities and illustrate several practical scenarios.
`@push.rocks/beautyfiglet` is a comprehensive Node.js package that empowers developers to generate visually engaging figlet-style ASCII art. This section will delve into detailed use-case scenarios, ensuring you have a robust understanding of how to integrate and utilize this module effectively within your projects.
### Basic Usage
### Getting Started
First, you'll need to import the package. Here's an example of basic usage:
To begin using `@push.rocks/beautyfiglet`, import the `BeautyFiglet` class in your TypeScript file. This class serves as the gateway to generating your ASCII art.
```typescript
import * as beautyfiglet from '@push.rocks/beautyfiglet';
import { BeautyFiglet } from '@push.rocks/beautyfiglet';
console.log(beautyfiglet.standardExport); // Outputs: Hi there! :) This is an exported string
console.log('Welcome to BeautyFiglet!'); // Outputs: Welcome to BeautyFiglet!
```
### Creating Figlet Text
### Rendering Text with Figlet
Lets say you want to display custom figlet text. Follow these steps:
1. Import `figlet` from the figlet package, which `@push.rocks/beautyfiglet` might internally use.
2. Use the `figlet` function to create ASCII art.
Here is a simple example:
The quintessential feature of this module is its ability to convert plain text into ASCII art using popular figlet formats. Below is an example of how to achieve this with `renderDefault`.
```typescript
import figlet from 'figlet';
figlet('Hello World', function(err, data) {
if (err) {
console.error('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
});
```
### Using Promises
To work with promises and async/await, you can wrap the `figlet` method within a Promise:
```typescript
import figlet from 'figlet';
const renderFiglet = (text: string): Promise<string> => {
return new Promise((resolve, reject) => {
figlet(text, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
};
// Usage example
(async () => {
try {
const figletText = await renderFiglet('Hello World');
console.log(figletText);
} catch (error) {
console.error(error);
}
const figletText = await BeautyFiglet.renderDefault('Hello, World!');
console.log(figletText); // Displays "Hello, World!" in ASCII format using the default font.
})();
```
### Customizing Fonts
### Custom Font Selection
Figlet allows for a variety of fonts to customize the output text. Here is how you can specify a font:
One of the striking features of `BeautyFiglet` is the ability to select from a variety of fonts. This allows for a unique representation of your text.
```typescript
import figlet from 'figlet';
const renderFiglet = (text: string, font: string): Promise<string> => {
return new Promise((resolve, reject) => {
figlet.text(text, { font }, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
};
// Usage example
(async () => {
try {
const figletText = await renderFiglet('Hello World', 'Ghost');
console.log(figletText);
} catch (error) {
console.error(error);
}
const customFiglet = await BeautyFiglet.renderText('Beautiful Text', 'Ghost');
console.log(customFiglet); // Renders the text "Beautiful Text" with the Ghost style.
})();
```
### Available Fonts
### Exploring Available Fonts
To see the list of available fonts, you can use `figlet.fonts` method. Heres how to get a list of all fonts:
Knowing which fonts you can work with enhances your creative freedom. By listing available fonts, you can make informed choices.
```typescript
import figlet from 'figlet';
figlet.fonts((err, fonts) => {
if (err) {
console.error(err);
return;
}
console.log(fonts);
});
(async () => {
const fontsList = await BeautyFiglet.listFonts();
console.log('Available Fonts:');
console.log(fontsList.join(', ')); // Lists all fonts available for use in figlet.
})();
```
### Text Layout Options
### Custom Text Layouts
You can also customize text layout with `horizontalLayout` and `verticalLayout` options:
Layouts, which refer to the arrangement of text, can be customized. Modify the horizontal and vertical layouts for dynamic artistry.
```typescript
import figlet from 'figlet';
const renderFiglet = (text: string, font: string, hLayout: string, vLayout: string): Promise<string> => {
const renderCustomLayout = (text: string, font: string, hLayout: string, vLayout: string): Promise<string> => {
return new Promise((resolve, reject) => {
figlet.text(text, { font, horizontalLayout: hLayout, verticalLayout: vLayout }, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
if (err) reject(`Error: ${err.message}`);
else resolve(data);
});
});
};
// Usage example
// Application Example
(async () => {
try {
const figletText = await renderFiglet('Hello World', 'Ghost', 'full', 'default');
console.log(figletText);
const customLayoutText = await renderCustomLayout('Creative Layout', 'Ghost', 'full', 'full');
console.log(customLayoutText); // Renders with specified layout adjustments.
} catch (error) {
console.error(error);
}
})();
```
### Synchronous Usage
### Synchronous Text Rendering
To generate Figlet text synchronously, use `figlet.textSync` method:
For scenarios demanding immediate rendering results, such as testing or small scripts, `textSync` is a beneficial synchronous method.
```typescript
import figlet from 'figlet';
import { figlet } from '@push.rocks/beautyfiglet.plugins';
const figletText = figlet.textSync('Hello World', {
font: 'Ghost',
const artwork = figlet.textSync('Synchronicity!', {
font: 'Standard',
horizontalLayout: 'default',
verticalLayout: 'default'
});
console.log(figletText);
console.log(artwork); // Output is rendered immediately without asynchronous behavior.
```
### Styling and Coloring
### Adding Color to the Output
While `figlet` itself doesnt support colored text directly, you can use other npm packages like `chalk` to add colors to figlet text. Heres an example:
To create more vibrant and visually appealing text displays, utilize libraries such as `chalk` to incorporate colors.
```typescript
import figlet from 'figlet';
import chalk from 'chalk';
const renderFiglet = (text: string, font: string): Promise<string> => {
return new Promise((resolve, reject) => {
figlet.text(text, { font }, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
};
// Usage example
(async () => {
try {
const figletText = await renderFiglet('Hello World', 'Ghost');
console.log(chalk.blue(figletText));
} catch (error) {
console.error(error);
}
const colorizedText = await BeautyFiglet.renderText('Color Me Beautiful', 'Standard');
console.log(chalk.magentaBright(colorizedText)); // Renders ASCII art in bright magenta.
})();
```
### Error Handling
### Robust Error Handling
Handling errors properly is crucial for robust applications. Heres an example of how you can handle errors comprehensively:
Effectively managing potential errors (e.g., when a specified font is unavailable) is essential to prevent application crashes.
```typescript
import figlet from 'figlet';
const renderFiglet = (text: string, font: string): Promise<string> => {
return new Promise((resolve, reject) => {
figlet.text(text, { font }, (err, data) => {
if (err) {
reject(new Error(`Error generating figlet text: ${err.message}`));
} else {
resolve(data);
}
});
});
};
// Usage example
(async () => {
try {
const figletText = await renderFiglet('Hello World', 'InvalidFontName');
console.log(figletText);
const result = await BeautyFiglet.renderText('Error Test', 'NonExistentFont');
console.log(result);
} catch (error) {
console.error(error.message); // Output: Error generating figlet text: Font not found
console.error(`Caught an error: ${error}`); // Captures and logs errors without halting the program.
}
})();
```
### Integration with Web Servers
### Web Server Integration
You can integrate `@push.rocks/beautyfiglet` with a Node.js web server like Express. Heres an example:
The functionality of this module can be extended to serve ASCII art over HTTP, allowing integration with web services. Heres a demonstration using Express.
```typescript
import express from 'express';
import figlet from 'figlet';
import { BeautyFiglet } from '@push.rocks/beautyfiglet';
const app = express();
const renderFiglet = (text: string, font: string): Promise<string> => {
return new Promise((resolve, reject) => {
figlet.text(text, { font }, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
};
app.get('/figlet/:text', async (req, res) => {
const { text } = req.params;
app.get('/api/art/:text', async (req, res) => {
const textToRender = req.params.text;
try {
const figletText = await renderFiglet(text, 'Standard');
res.send(`<pre>${figletText}</pre>`);
const asciiArt = await BeautyFiglet.renderDefault(textToRender);
res.send(`<pre>${asciiArt}</pre>`); // Sends the rendered ASCII art in a preformatted text block over HTTP.
} catch (error) {
res.status(500).send(error.message);
res.status(500).send(`Error: ${error.message}`); // Manages errors with a 500 Internal Server Error status code.
}
});
app.listen(3000, () => {
console.log('Server started on port 3000');
app.listen(4000, () => {
console.log('Server running at http://localhost:4000/');
});
```
### CLI Tool Example
### Command-Line Interface (CLI)
You can also create a command-line tool using `@push.rocks/beautyfiglet`. Heres an example using Node.js:
Creating a CLI tool enhances accessibility, allowing direct ASCII art generation from the terminal. Here's a demonstration:
```typescript
#!/usr/bin/env node
import figlet from 'figlet';
import { program } from 'commander';
import { BeautyFiglet } from '@push.rocks/beautyfiglet';
import { Command } from 'commander';
const program = new Command();
program.version('1.0.8');
program
.version('1.0.0')
.description('A simple Node CLI for generating Figlet text')
.option('-t, --text <text>', 'Text to render as Figlet')
.option('-f, --font <font>', 'Font to use', 'Standard');
.option('-t, --text <text>', 'Text to render')
.option('-f, --font <font>', 'Font for rendering', 'Standard')
.action(async (cmd) => {
try {
const asciiArt = await BeautyFiglet.renderText(cmd.text, cmd.font);
console.log(asciiArt); // Renders text directly in CLI using specified options.
} catch (error) {
console.error(`Error: ${error.message}`);
}
});
program.parse(process.argv);
const options = program.opts();
figlet.text(options.text, { font: options.font }, (err, data) => {
if (err) {
console.error('Something went wrong...');
console.error(err.message);
return;
}
console.log(data);
});
```
To use this script as a CLI tool:
**CLI Tool Usage:**
1. Save the script as `figlet-cli.ts`.
2. Add a line to your `package.json` to register this as a bin command:
```json
"bin": {
"figlet-cli": "./path/to/figlet-cli.ts"
}
```
3. Make sure `figlet-cli.ts` is executable:
1. Save the script as `beautyfiglet-cli.ts`.
2. Make it executable:
```sh
chmod +x ./path/to/figlet-cli.ts
chmod +x ./beautyfiglet-cli.ts
```
4. Then you can run:
3. Establish a link via npm:
```sh
npm link
figlet-cli --text "Hello World"
```
This concludes the extensive usage documentation for the @push.rocks/beautyfiglet package, showcasing multiple ways to generate ASCII art using figlet in Node.js. Explore the various options and configurations to best fit your project's needs.
4. Run the command using:
```sh
beautyfiglet-cli --text "Hello World" --font "Ghost"
```
This CLI approach demonstrates seamless integration into development workflows, adding simplicity and efficiency for users.
### Comprehensive Summary
Throughout this comprehensive guide, we have demonstrated the varied and extensive capabilities of the `@push.rocks/beautyfiglet` module. From initializing the module and employing basic rendering to exploring intricate font customization, layout configurations, and error handling, the guide has covered an exhaustive list of functionalities available within this versatile module.
Developers are encouraged to delve deeper into exploring font selections and engaging with additional configuration settings to thoroughly harness the potential of this tool. By integrating colorful text arrangements and utilizing robust error management, applications can balance both aesthetic appeal and operational reliability.
This expansive exploration into the `@push.rocks/beautyfiglet` module underscores the creativity and potential this tool offers for implementing ASCII art in your Node.js projects.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.

View File

@ -9,8 +9,9 @@ tap.test('setup', async () => {
});
tap.test('should render text with the default font', async () => {
const text = "Hello, World!";
const result = await testFiglet.renderDefault(text);
const text = "serve.zone";
const result = await testFiglet.renderDefault(text, '');
console.log(result);
expect(result).toBeTruthy();
});
@ -18,6 +19,7 @@ tap.test('should render text with a specific font', async () => {
const text = "Fancy Text";
const font = "Ghost";
const result = await testFiglet.renderText(text, font);
console.log(result);
expect(result).toBeTruthy();
});

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/beautyfiglet',
version: '1.0.5',
description: 'A Node.js module for creating figlet text displays.'
version: '1.0.10',
description: 'A Node.js module for creating customizable ASCII art using figlet with options for different fonts and layouts.'
}