Colors.ts
Get colors and style in your node.js console
Installation
npm install colorts
colors and styles!
text colors
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
- gray
- grey
background colors
- bgBlack
- bgRed
- bgGreen
- bgYellow
- bgBlue
- bgMagenta
- bgCyan
- bgWhite
styles
- reset
- bold
- dim
- italic
- underline
- inverse
- hidden
- strikethrough
Usage methods
1. TypeScript
i. Normal String extension.
import 'colorts/lib/string';
console.log('hello'.green);
console.log('i like cake and pies'.underline.red)
console.log('inverse the color'.inverse);
ii. Direct color method
import color from 'colorts';
import {echo} from 'colorts';
console.log(colors('hello').green + "");
console.log(colors('i like cake and pies').red.underline.toString)
echo(colors('inverse the color').inverse);
2. JavaScript
i. Normal String extension.
require('colorts/lib/string');
console.log('hello'.green);
console.log('i like cake and pies'.underline.red)
console.log('inverse the color'.inverse);
ii. Direct color method
let color = require('colorts');
let echo = require('colorts').echo;
console.log(colors('hello').green + "");
console.log(colors('i like cake and pies').red.underline.toString)
echo(colors('inverse the color').inverse);
I prefer the first way. Some people seem to be afraid of extending String.prototype
and prefer the second way.
If you are writing good code you will never have an issue with the first approach. If you really don't want to
touch String.prototype
, the second usage will not touch String
native object.
Disabling Colors
To disable colors you can pass the following arguments in the command line to your application:
node myapp.js --no-color
Bonus String Letter case Methods
"james is a nice guy.".capitalize
" no one home.".capitalize
"typescript".capitalize
"1st january 2018".capitalize
"james is a nice guy.".titleCase
" no one home.".titleCase
"tYpe scrIpt".titleCase
"1st january".titleCase
"james is a nice guy.".camelCase
" no one home.".camelCase
"type script".camelCase
"james is a nice guy.".upperCamelCase
" no one home.".upperCamelCase
"type script".upperCamelCase
"james is a nice guy.".lowerCamelCase
" no one home.".lowerCamelCase
"type script".lowerCamelCase
"james is a nice guy.".snakeCase
" no one home.".snakeCase
"super type script".snakeCase
"James is a nice guy.".kebabCase
" no one home.".kebabCase
"super type script".kebabCase
"james is a nice guy.".studlyCaps
" no one home.".studlyCaps
"super type script".studlyCaps