fix(documentation): Update README to reflect recent changes

This commit is contained in:
Philipp Kunz 2025-01-14 17:37:45 +01:00
parent e294710a0f
commit 95e6295feb
5 changed files with 129 additions and 217 deletions

View File

@ -1,5 +1,14 @@
# Changelog # Changelog
## 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) ## 2025-01-14 - 1.0.7 - fix(core)
Improve error messages in renderText and listFonts methods Improve error messages in renderText and listFonts methods

View File

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

View File

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

299
readme.md
View File

@ -1,26 +1,25 @@
```markdown
# @push.rocks/beautyfiglet # @push.rocks/beautyfiglet
figlet display in nodejs A Node.js module for creating figlet text displays.
## Install ## 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`, you should have Node.js and npm installed on your machine. Once you have these prerequisites, you can install the package via npm by running the following command in your terminal:
```sh ```sh
npm install @push.rocks/beautyfiglet npm install @push.rocks/beautyfiglet
``` ```
Alternatively, you can add it as a dependency in your `package.json`: Alternatively, you can include it as a dependency in your `package.json` file:
```json ```json
{ {
"dependencies": { "dependencies": {
"@push.rocks/beautyfiglet": "^1.0.3" "@push.rocks/beautyfiglet": "^1.0.7"
} }
} }
``` ```
Then run: Then execute:
```sh ```sh
npm install npm install
@ -28,315 +27,209 @@ npm install
## Usage ## 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 versatile Node.js module that lets you generate figlet-style ASCII art easily. Below, we will explore its functionalities with detailed examples, encompassing various scenarios to showcase how you can leverage this module in your projects.
### Basic Usage ### Basic Initialization
First, you'll need to import the package. Here's an example of basic usage: Begin by importing the `BeautyFiglet` class into your TypeScript file. You can access its methods to create ASCII art from text strings.
```typescript ```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 // A simple demonstration of using the standard export
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: Figlet is immensely popular for turning strings into ASCII banners. The following code illustrates how to convert text into a figlet display using `BeautyFiglet`.
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:
```typescript ```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 () => { (async () => {
try { const figletText = await BeautyFiglet.renderDefault('Hello, World!');
const figletText = await renderFiglet('Hello World'); console.log(figletText);
console.log(figletText);
} catch (error) {
console.error(error);
}
})(); })();
``` ```
### Customizing Fonts ### Customizing Font
Figlet allows for a variety of fonts to customize the output text. Here is how you can specify a font: `BeautyFiglet` not only supports different versions of text layouts, but it also allows you to specify fonts, making your output unique.
```typescript ```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 () => { (async () => {
try { const customFiglet = await BeautyFiglet.renderText('Beautiful Text', 'Ghost');
const figletText = await renderFiglet('Hello World', 'Ghost'); console.log(customFiglet);
console.log(figletText);
} catch (error) {
console.error(error);
}
})(); })();
``` ```
### Available Fonts ### Fetching Available Fonts
To see the list of available fonts, you can use `figlet.fonts` method. Heres how to get a list of all fonts: Understanding what fonts are available can help in making aesthetic decisions for your text.
```typescript ```typescript
import figlet from 'figlet'; (async () => {
const fontsList = await BeautyFiglet.listFonts();
figlet.fonts((err, fonts) => { console.log('Available Fonts:');
if (err) { console.log(fontsList.join(', '));
console.error(err); })();
return;
}
console.log(fonts);
});
``` ```
### Text Layout Options ### Using Custom Layouts
You can also customize text layout with `horizontalLayout` and `verticalLayout` options: In addition to fonts, the layout of the text can be altered. You can specify both horizontal and vertical layouts.
```typescript ```typescript
import figlet from 'figlet'; 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) => { return new Promise((resolve, reject) => {
figlet.text(text, { font, horizontalLayout: hLayout, verticalLayout: vLayout }, (err, data) => { figlet.text(text, { font, horizontalLayout: hLayout, verticalLayout: vLayout }, (err, data) => {
if (err) { if (err) reject(`Error: ${err.message}`);
reject(err); else resolve(data);
} else {
resolve(data);
}
}); });
}); });
}; };
// Usage example // Example usage
(async () => { (async () => {
try { try {
const figletText = await renderFiglet('Hello World', 'Ghost', 'full', 'default'); const customLayoutText = await renderCustomLayout('Creative Layout', 'Ghost', 'full', 'full');
console.log(figletText); console.log(customLayoutText);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
})(); })();
``` ```
### Synchronous Usage ### Synchronous Text Rendering
To generate Figlet text synchronously, use `figlet.textSync` method: For situations requiring synchronous execution such as small scripts and testing scenarios, `textSync` comes in handy.
```typescript ```typescript
import figlet from 'figlet'; import { figlet } from '@push.rocks/beautyfiglet.plugins';
const figletText = figlet.textSync('Hello World', { const artwork = figlet.textSync('Synchronicity!', {
font: 'Ghost', font: 'Standard',
horizontalLayout: 'default', horizontalLayout: 'default',
verticalLayout: 'default' verticalLayout: 'default'
}); });
console.log(figletText); console.log(artwork);
``` ```
### Styling and Coloring ### Enhancing Output with Color
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 add more flair to your text displays, consider integrating popular color-coordinating libraries like `chalk`.
```typescript ```typescript
import figlet from 'figlet'; import figlet from 'figlet';
import chalk from 'chalk'; 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 () => { (async () => {
try { const colorizedText = await BeautyFiglet.renderText('Color Me Beautiful', 'Standard');
const figletText = await renderFiglet('Hello World', 'Ghost'); console.log(chalk.magentaBright(colorizedText));
console.log(chalk.blue(figletText));
} catch (error) {
console.error(error);
}
})(); })();
``` ```
### Error Handling ### Robust Error Handling
Handling errors properly is crucial for robust applications. Heres an example of how you can handle errors comprehensively: Error handling is paramount in any application. This becomes even more pronounced when fonts or integrations might fail.
```typescript ```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 () => { (async () => {
try { try {
const figletText = await renderFiglet('Hello World', 'InvalidFontName'); const result = await BeautyFiglet.renderText('Error Test', 'NonExistentFont');
console.log(figletText); console.log(result);
} catch (error) { } catch (error) {
console.error(error.message); // Output: Error generating figlet text: Font not found console.error(`Caught an error: ${error}`);
} }
})(); })();
``` ```
### 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 module can effectively serve dynamically generated ASCII text over HTTP. Here's a simple example using Express:
```typescript ```typescript
import express from 'express'; import express from 'express';
import figlet from 'figlet'; import { BeautyFiglet } from '@push.rocks/beautyfiglet';
const app = express(); const app = express();
const renderFiglet = (text: string, font: string): Promise<string> => { app.get('/api/art/:text', async (req, res) => {
return new Promise((resolve, reject) => { const textToRender = req.params.text;
figlet.text(text, { font }, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
};
app.get('/figlet/:text', async (req, res) => {
const { text } = req.params;
try { try {
const figletText = await renderFiglet(text, 'Standard'); const asciiArt = await BeautyFiglet.renderDefault(textToRender);
res.send(`<pre>${figletText}</pre>`); res.send(`<pre>${asciiArt}</pre>`);
} catch (error) { } catch (error) {
res.status(500).send(error.message); res.status(500).send(`Error: ${error.message}`);
} }
}); });
app.listen(3000, () => { app.listen(4000, () => {
console.log('Server started on port 3000'); 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: Expand the utility of `BeautyFiglet` by creating a CLI tool for generating ASCII art directly from the command line.
```typescript ```typescript
#!/usr/bin/env node #!/usr/bin/env node
import figlet from 'figlet'; import { BeautyFiglet } from '@push.rocks/beautyfiglet';
import { program } from 'commander'; import { Command } from 'commander';
const program = new Command();
program.version('1.0.7');
program program
.version('1.0.0') .option('-t, --text <text>', 'Text to render')
.description('A simple Node CLI for generating Figlet text') .option('-f, --font <font>', 'Font for rendering', 'Standard')
.option('-t, --text <text>', 'Text to render as Figlet') .action(async (cmd) => {
.option('-f, --font <font>', 'Font to use', 'Standard'); try {
const asciiArt = await BeautyFiglet.renderText(cmd.text, cmd.font);
console.log(asciiArt);
} catch (error) {
console.error(`Error: ${error}`);
}
});
program.parse(process.argv); 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: Running this tool involves these steps:
1. Save the script as `figlet-cli.ts`. 1. Save the script as `beautyfiglet-cli.ts`.
2. Add a line to your `package.json` to register this as a bin command: 2. Ensure it is marked as executable:
```json
"bin": {
"figlet-cli": "./path/to/figlet-cli.ts"
}
```
3. Make sure `figlet-cli.ts` is executable:
```sh ```sh
chmod +x ./path/to/figlet-cli.ts chmod +x ./beautyfiglet-cli.ts
``` ```
4. Then you can run: 3. Link via npm:
```sh ```sh
npm link 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. Execute with:
```sh
beautyfiglet-cli --text "Hello World" --font "Ghost"
``` ```
This command-line example showcases flexibility and enhanced usability for developers integrating the module seamlessly into their workflow.
### Summary of Best Practices
The extensive usage of `@push.rocks/beautyfiglet` demonstrates the importance of proper setup and thorough understanding of available options. From simple implementations to elaborate, colorful arrangements, this module empowers developers to unleash creativity with text in aesthetic and programmable ways.
Delve deeper into font choices and optional configurations to fully capitalize on this versatile tool for crafting meaningful ASCII text displays, all the while ensuring continuous learning of new patterns and module updates. With vigilant error management and the integration of expressive styles, your applications can achieve a blend of functionality and flair unmatched by basic textual representation.
This concludes the elaborate coverage of the `@push.rocks/beautyfiglet` module and its extensive capabilities within Node.js projects.
## License and Legal Information ## 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. 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

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/beautyfiglet', name: '@push.rocks/beautyfiglet',
version: '1.0.7', version: '1.0.8',
description: 'A Node.js module for creating figlet text displays.' description: 'A Node.js module that facilitates the creation of ASCII art using figlet with customizable fonts and layouts.'
} }