A module for applying color styles to console output.
Go to file
2024-05-29 13:55:36 +02:00
.gitea/workflows fix(core): update 2024-03-13 20:02:12 +01:00
.vscode fix(core): update 2024-03-13 20:02:12 +01:00
test fix(core): update 2024-03-13 20:02:12 +01:00
ts fix(core): update 2024-03-13 20:02:12 +01:00
.gitignore fix(core): update 2024-03-13 20:02:12 +01:00
.gitlab-ci.yml BREAKING CHANGE(package): change scope and name 2018-07-18 00:12:40 +02:00
npmextra.json update tsconfig 2024-04-14 13:34:25 +02:00
package.json update description 2024-05-29 13:55:36 +02:00
pnpm-lock.yaml fix(core): update 2024-03-13 20:02:12 +01:00
readme.hints.md update tsconfig 2024-04-14 13:34:25 +02:00
readme.md update tsconfig 2024-04-14 13:34:25 +02:00
tsconfig.json fix(core): update 2024-03-13 20:02:12 +01:00

@push.rocks/consolecolor

colors for beautylog

Install

To install @push.rocks/consolecolor, you need Node.js installed on your system. If you have Node.js installed, you can add @push.rocks/consolecolor to your project by running:

npm install @push.rocks/consolecolor --save

This command will install @push.rocks/consolecolor and add it to your project's package.json file.

Usage

In this guide, we'll explore how to use @push.rocks/consolecolor to colorize your console output in a Node.js application. We'll cover the basics, including coloring text, backgrounds, and combining both for striking effects. This package utilizes TypeScript and ESM syntax for modern, type-safe code examples.

Getting Started

First, ensure you have imported the library in your TypeScript file:

import * as consolecolor from '@push.rocks/consolecolor';

Coloring Text

The foundation of using @push.rocks/consolecolor is to change the color of the text output. You can choose from a variety of colors including blue, red, green, and more. Here's how to color a string blue:

let blueString = consolecolor.coloredString("This text is blue.", "blue");
console.log(blueString);

Adding Background Color

In addition to coloring text, you can also set the background color of your text for greater emphasis:

let redTextOnGreen = consolecolor.coloredString("Red text on a green background.", "red", "green");
console.log(redTextOnGreen);

Combining Colors

You can easily mix and match text and background colors to suit your needs. Here's an example of a more detailed usage, where we add a function to create and log messages of different severities with appropriate coloring:

function logMessage(message: string, type: 'info' | 'warning' | 'error') {
  switch (type) {
    case 'info':
      console.log(consolecolor.coloredString(message, 'cyan'));
      break;
    case 'warning':
      console.log(consolecolor.coloredString(message, 'orange', 'black'));
      break;
    case 'error':
      console.log(consolecolor.coloredString(message, 'red', 'white'));
      break;
  }
}

logMessage('An informational message', 'info');
logMessage('A warning message', 'warning');
logMessage('An error message', 'error');

This example defines a logMessage function that accepts a message and a message type. It uses @push.rocks/consolecolor to color the message according to its severity.

Advanced Usage

Beyond basic coloring, @push.rocks/consolecolor allows for intricate customization. For instance, you can create utilities that dynamically select colors based on conditions, enhance logging mechanisms, or implement theme-based console outputs in your Node.js applications.

Considering the capabilities of @push.rocks/consolecolor alongside Node.js's console object, you can create highly readable, colorful console applications that are easier to debug and pleasant to interact with.

Conclusion

@push.rocks/consolecolor offers a simple yet powerful API for adding color to Node.js console applications. By following the examples provided, you can enhance the visual appeal and readability of your console output, making development and debugging a more enjoyable experience. For a comprehensive list of all available colors and more advanced features, refer to the official documentation and explore the module's possibilities.

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 file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.