From 95e6295feb1b4c55b828f9cdf9f4f3d91b6330f3 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 14 Jan 2025 17:37:45 +0100 Subject: [PATCH] fix(documentation): Update README to reflect recent changes --- changelog.md | 9 ++ npmextra.json | 15 +- package.json | 17 ++- readme.md | 301 +++++++++++++-------------------------- ts/00_commitinfo_data.ts | 4 +- 5 files changed, 129 insertions(+), 217 deletions(-) diff --git a/changelog.md b/changelog.md index 2767214..c4ea4ac 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # 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) Improve error messages in renderText and listFonts methods diff --git a/npmextra.json b/npmextra.json index 100fbb8..4130ea0 100644 --- a/npmextra.json +++ b/npmextra.json @@ -10,15 +10,20 @@ "githost": "code.foss.global", "gitscope": "push.rocks", "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", "license": "MIT", "keywords": [ + "ASCII art", "figlet", - "text display", - "Node.js", - "npm module", - "typescript" + "text rendering", + "Node.js module", + "typescript", + "font customization", + "command-line interface", + "error handling", + "web integration", + "npm package" ] } }, diff --git a/package.json b/package.json index df1dcfe..4652f8c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@push.rocks/beautyfiglet", "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": { ".": "./dist_ts/index.js" }, @@ -22,11 +22,16 @@ "url": "https://code.foss.global/push.rocks/beautyfiglet.git" }, "keywords": [ + "ASCII art", "figlet", - "text display", - "Node.js", - "npm module", - "typescript" + "text rendering", + "Node.js module", + "typescript", + "font customization", + "command-line interface", + "error handling", + "web integration", + "npm package" ], "devDependencies": { "@git.zone/tsbuild": "^2.2.0", @@ -35,4 +40,4 @@ "@git.zone/tstest": "^1.0.90", "@push.rocks/tapbundle": "^5.5.4" } -} +} \ No newline at end of file diff --git a/readme.md b/readme.md index 35385b5..135144a 100644 --- a/readme.md +++ b/readme.md @@ -1,26 +1,25 @@ -```markdown # @push.rocks/beautyfiglet -figlet display in nodejs +A Node.js module for creating figlet text displays. ## 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 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 { "dependencies": { - "@push.rocks/beautyfiglet": "^1.0.3" + "@push.rocks/beautyfiglet": "^1.0.7" } } ``` -Then run: +Then execute: ```sh npm install @@ -28,315 +27,209 @@ 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 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 -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 -Let’s 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: +Figlet is immensely popular for turning strings into ASCII banners. The following code illustrates how to convert text into a figlet display using `BeautyFiglet`. ```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 => { - 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); })(); ``` -### 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 -import figlet from 'figlet'; - -const renderFiglet = (text: string, font: string): Promise => { - 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); })(); ``` -### Available Fonts +### Fetching Available Fonts -To see the list of available fonts, you can use `figlet.fonts` method. Here’s how to get a list of all fonts: +Understanding what fonts are available can help in making aesthetic decisions for your text. ```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(', ')); +})(); ``` -### 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 import figlet from 'figlet'; -const renderFiglet = (text: string, font: string, hLayout: string, vLayout: string): Promise => { +const renderCustomLayout = (text: string, font: string, hLayout: string, vLayout: string): Promise => { 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 +// Example usage (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); } catch (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 -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); ``` -### Styling and Coloring +### Enhancing Output with Color -While `figlet` itself doesn’t support colored text directly, you can use other npm packages like `chalk` to add colors to figlet text. Here’s an example: +To add more flair to your text displays, consider integrating popular color-coordinating libraries like `chalk`. ```typescript import figlet from 'figlet'; import chalk from 'chalk'; -const renderFiglet = (text: string, font: string): Promise => { - 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)); })(); ``` -### Error Handling +### Robust Error Handling -Handling errors properly is crucial for robust applications. Here’s 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 -import figlet from 'figlet'; - -const renderFiglet = (text: string, font: string): Promise => { - 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}`); } })(); ``` -### Integration with Web Servers +### Web Server Integration -You can integrate `@push.rocks/beautyfiglet` with a Node.js web server like Express. Here’s an example: +The module can effectively serve dynamically generated ASCII text over HTTP. Here's a simple example 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 => { - 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(`
${figletText}
`); + const asciiArt = await BeautyFiglet.renderDefault(textToRender); + res.send(`
${asciiArt}
`); } catch (error) { - res.status(500).send(error.message); + res.status(500).send(`Error: ${error.message}`); } }); -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`. Here’s 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 #!/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.7'); program - .version('1.0.0') - .description('A simple Node CLI for generating Figlet text') - .option('-t, --text ', 'Text to render as Figlet') - .option('-f, --font ', 'Font to use', 'Standard'); + .option('-t, --text ', 'Text to render') + .option('-f, --font ', 'Font for rendering', 'Standard') + .action(async (cmd) => { + try { + const asciiArt = await BeautyFiglet.renderText(cmd.text, cmd.font); + console.log(asciiArt); + } catch (error) { + console.error(`Error: ${error}`); + } + }); 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`. -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. Ensure it is marked as executable: ```sh -chmod +x ./path/to/figlet-cli.ts +chmod +x ./beautyfiglet-cli.ts ``` -4. Then you can run: +3. 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. 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 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. diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 3242964..cb5a50b 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/beautyfiglet', - version: '1.0.7', - description: 'A Node.js module for creating figlet text displays.' + version: '1.0.8', + description: 'A Node.js module that facilitates the creation of ASCII art using figlet with customizable fonts and layouts.' }