@comodinx/colors
This is a simple proof of concept. An exercise.
We were inspired by and strongly recommend using colors
Installation
npm i @comodinx/colors
colors and styles!
text and bright text colors
color | bright |
---|---|
black | |
red | brightRed |
green | brightGreen |
yellow | brightYellow |
blue | brightBlue |
magenta | brightMagenta |
cyan | brightCyan |
white | brightWhite |
grey |
background and bright background colors
color | bright |
---|---|
bgBlack | |
bgRed | bgBrightRed |
bgGreen | bgBrightGreen |
bgYellow | bgBrightYellow |
bgBlue | bgBrightBlue |
bgMagenta | bgBrightMagenta |
bgCyan | bgBrightCyan |
bgWhite | bgBrightWhite |
bgGrey |
styles
style |
---|
reset |
bold |
dim |
italic |
underline |
inverse |
hidden |
strikethrough |
Usage
The super nifty way
require('@comodinx/colors');
console.log('hello'.green);
console.log('i like cake and pies'.underline.red);
console.log('inverse the color'.inverse);
or a slightly less nifty way which doesn't extend String.prototype
const colors = require('@comodinx/colors/safe');
console.log(colors.green('hello'));
console.log(colors.red(colors.underline('i like cake and pies')));
console.log(colors.inverse('inverse the color'));
String.prototype
Prevent extend COLORS_ON_STRING_PROTO=0 node myapp.js
string substitution
Console.logconst name = 'Marak';
console.log(colors.green('Hello %s'), name);
// outputs -> 'Hello Marak'
Alias
const colors = require('@comodinx/colors');
colors.setAlias({
title: 'bold',
success: 'green',
error: 'red',
warn: 'yellow',
info: 'cyan'
});
console.log('🟢 Congratulations'.success);
console.log('🔴 ERROR'.error);
console.log('🟡 ¡¡¡WARNING!!!'.warn);
console.log('🔵 This is an information message'.info);
console.log('This is a title for success message'.title.success);