https://github.com/mathieu2301/console
Easy console colors
https://github.com/mathieu2301/console
colors console console-log formatting log logging logging-and-metrics timestamp
Last synced: over 1 year ago
JSON representation
Easy console colors
- Host: GitHub
- URL: https://github.com/mathieu2301/console
- Owner: Mathieu2301
- License: mit
- Created: 2021-04-10T14:33:37.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-12T23:13:33.000Z (about 5 years ago)
- Last Synced: 2025-02-16T08:46:07.680Z (over 1 year ago)
- Topics: colors, console, console-log, formatting, log, logging, logging-and-metrics, timestamp
- Language: JavaScript
- Homepage:
- Size: 354 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Console
Better console :
- Easy colors
- Auto timestamp

## Installation
```
npm i @mathieuc/console
```
Then:
```javascript
require('@mathieuc/console')( // Just import the lib
'§', // Character you want to use (defaut: '§')
true, // Active timestamp (defaut: false)
CORR, // Custom timestamp correction in milliseconds (defaut: 0)
'94', // Custom timestamp color (defaut: '94' => Light blue)
);
// Then you can use
console.log(...);
console.info(...);
console.warn(...);
console.error(...);
// Bonus: To calculate the necessary CORR, you can use 'Date().getTimezoneOffset()'
// CORR = parseInt(new Date().getTimezoneOffset() * 60 + 7200, 10) * 1000
```
## Console colors
This lib allows you to use any character as an alias to `\x1b[Xm`.
### Example
If you use '§' as alias,
```javascript
console.log('\x1b[31mRed \x1b[32mGreen \x1b[33mYellow');
```
becomes
```javascript
console.log('§31Red $32Green §33Yellow');
```
There are two parameters (digits) :
- First is type: it can be 3, 4, 9, 10 or nothing
- Second is color, between 0 and 7
### Types :
- **`X`**: Formatting
- **`0`**: Reset
- **`1`**: **Bold**
- **`3`**: *Italic*
- **`7`**: Reverse
- **`8`**: Hidden
- **`3X`**: Colors
- **`4X`**: Background
- **`9X`** : Colors (light)
- **`10X`**: Background (light)
### Colors : (*3X, 4X, 9X, 10X*)
- **`0`**:  Black
- **`1`**:  Red
- **`2`**:  Green
- **`3`**:  Yellow
- **`4`**:  Blue
- **`5`**:  Magenta
- **`6`**:  Cyan
- **`7`**:  White
### Combinations
If you use `§` as alias, you can combine formatting with font color and background color.
- `§3§44§30` => Italic (`§3`) + Black font (`§30`) + Blue background (`§44`)
- `§3§104§30` => Italic (`§3`) + Black font (`§30`) + Light blue background (`§104`)

## Problems
If you have errors in console or unwanted behavior, just reload the page.
If the problem persists, please create an issue [here](https://github.com/Mathieu2301/Console/issues).