2.10.2 • Published 2 months ago

@sp-packages/printer v2.10.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Printer

✨ Features

  • šŸŽØ Rich formatting for messages (success, error, warning, info, headers)
  • šŸ”„ Verbose mode for detailed logging
  • šŸ”‡ Quiet mode to suppress non-essential output
  • šŸŒ€ Spinner for showing progress during async operations
  • šŸš€ Usable via CLI or programmatically in Node.js
  • šŸ“œ Structured output for better readability
  • šŸ›  Ideal for CI/CD, automation scripts, and development tools

šŸ“¦ Installation

Global Installation (For system-wide CLI use)

npm install -g @sp-packages/printer

This allows you to use printer globally in your terminal.

Local Installation (For project-specific use)

npm install @sp-packages/printer --save-dev

Then, run it via:

npx printer success "Setup completed!"

šŸš€ CLI Usage

Basic Usage

printer <type> <message>

Message Types:

  • āœ… success - Green message for success output
  • āŒ error - Red message for errors (supports error objects)
  • ⚠ warning - Yellow message for warnings
  • ℹ info - Blue message for general information
  • šŸ“ message - Plain text message (no formatting)

Examples:

printer success "Operation completed successfully!"
printer error "Something went wrong"
printer warning "This is a warning message"
printer info "Starting process..."
printer message "Simple message without formatting"

šŸ“œ Programmatic Usage (Inside Node.js)

You can also use printer inside your JavaScript/TypeScript projects.

Import and Use in Your Project

import { Printer } from '@sp-packages/printer';

Printer.success('Setup completed successfully!');
Printer.error('An error occurred', new Error('Database connection failed'));
Printer.warning('This is a warning message');
Printer.info('Fetching data...');
Printer.message('Regular message');

Using Spinner

The spinner feature is perfect for displaying progress during asynchronous operations. It shows an animated loading indicator that can be updated with success or error states.

import { Printer } from '@sp-packages/printer';

const spinner = Printer.spinner('Loading data...');

// During async operations
try {
  await someAsyncOperation();
  spinner.succeed('Data loaded successfully!');
} catch (error) {
  spinner.fail('Failed to load data!');
}

Spinner Methods:

  • spinner.start() - Start or restart the spinner
  • spinner.stop() - Stop and clear the spinner
  • spinner.succeed(text?) - Stop the spinner and show success state
  • spinner.fail(text?) - Stop the spinner and show failure state
  • spinner.warn(text?) - Stop the spinner and show warning state
  • spinner.info(text?) - Stop the spinner and show info state

Verbose Mode

Verbose mode provides detailed logging, which can be extremely helpful for debugging and development purposes. When enabled, it outputs additional information that can help you trace the execution flow and identify issues more easily.

Enable Verbose Mode:

Printer.enableVerbose();
Printer.log('This will display only in verbose mode.');

Disable Verbose Mode:

Printer.disableVerbose();

Example (Verbose Mode ON):

Printer.enableVerbose();
Printer.success('Process completed');
Printer.log('Detailed execution log...');

Output:

āœ… [SUCCESS] Process completed
Detailed execution log...

Example (Verbose Mode OFF):

Printer.disableVerbose();
Printer.success('Process completed');
Printer.log('Detailed execution log...');

Output:

āœ… [SUCCESS] Process completed

Benefits of Verbose Mode in npm Modules:

  • Enhanced Debugging: Verbose mode provides more context and detailed logs, making it easier to pinpoint where things might be going wrong in your code.
  • Better Traceability: With more information being logged, you can trace the execution path and understand the sequence of operations.
  • Improved Development Experience: Developers can get insights into the internal workings of the module, which can be particularly useful during development and testing phases.
  • Efficient Troubleshooting: Detailed logs can help in quickly identifying and resolving issues, reducing the time spent on debugging.
  • Single Control Point: Verbose mode can be enabled or disabled with a single flag, providing a centralized way to control the verbosity of logs.

Verbose mode is particularly useful in CI/CD pipelines, automation scripts, and during the development of complex Node.js applications where understanding the flow of execution is crucial.

Quiet Mode

Quiet mode suppresses all output, including errors. This can be useful when you need to ensure that no messages clutter the console output in production or automated environments.

Enable Quiet Mode:

Printer.enableQuiet();

Disable Quiet Mode:

Printer.disableQuiet();

Example (Quiet Mode ON):

Printer.enableQuiet();
Printer.success('Process completed');
Printer.warning('This warning will NOT be displayed');
Printer.error('Critical error!');

Output:

Note: When quiet mode is enabled, no messages will be printed, including errors.

Example (Quiet Mode OFF):

Printer.disableQuiet();
Printer.success('Process completed');
Printer.warning('This warning WILL be displayed');

Output:

āœ… [SUCCESS] Process completed
⚠ [WARNING] This warning WILL be displayed

šŸŽÆ Example Outputs

āœ… [SUCCESS] Operation completed successfully!
āŒ [ERROR] An error occurred: Database connection failed
⚠ [WARNING] Be cautious! Proceeding with default values.
ℹ [INFO] Fetching data...
šŸ“ [MESSAGE] Process initiated.

šŸ’” Use Cases

  • CI/CD Pipelines – Enhance logs in automation scripts
  • Node.js CLI Tools – Format console outputs for better readability
  • Development Debugging – Enable verbose mode for debugging
  • Project Setup Scripts – Display status messages during installations

šŸ¤ Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.


šŸ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.

2.10.2

2 months ago

2.10.1

2 months ago

2.10.0

3 months ago

2.9.0

3 months ago

2.8.0

4 months ago

2.7.0

4 months ago

2.6.0

4 months ago

2.5.0

4 months ago

2.4.0

4 months ago

2.3.0

4 months ago

2.2.0

4 months ago

2.1.0

4 months ago

2.0.0

4 months ago

1.0.0

4 months ago