consolecolor/readme.md

99 lines
4.8 KiB
Markdown
Raw Permalink Normal View History

2024-04-14 11:34:25 +00:00
# @push.rocks/consolecolor
2017-01-21 14:49:00 +00:00
colors for beautylog
2024-04-14 11:34:25 +00:00
## Install
2024-04-14 11:34:25 +00:00
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:
2017-01-21 14:49:00 +00:00
2024-04-14 11:34:25 +00:00
```bash
npm install @push.rocks/consolecolor --save
```
2024-04-14 11:34:25 +00:00
This command will install `@push.rocks/consolecolor` and add it to your project's `package.json` file.
2017-01-21 14:49:00 +00:00
## Usage
2024-04-14 11:34:25 +00:00
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:
```typescript
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:
```typescript
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:
```typescript
let redTextOnGreen = consolecolor.coloredString("Red text on a green background.", "red", "green");
console.log(redTextOnGreen);
```
### Combining Colors
2017-01-21 14:49:00 +00:00
2024-04-14 11:34:25 +00:00
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:
2017-01-21 17:13:44 +00:00
2024-04-14 11:34:25 +00:00
```typescript
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;
}
}
2017-01-21 17:13:44 +00:00
2024-04-14 11:34:25 +00:00
logMessage('An informational message', 'info');
logMessage('A warning message', 'warning');
logMessage('An error message', 'error');
2017-01-21 17:13:44 +00:00
```
2024-04-14 11:34:25 +00:00
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.
## 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.
**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
2017-08-16 08:42:48 +00:00
2024-04-14 11:34:25 +00:00
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
2017-08-16 08:42:48 +00:00
2024-04-14 11:34:25 +00:00
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.