Installing and using Colorts is a breeze; in both a TypeScript and JavaScript.
npm install colorts
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
- gray
- grey
- bgBlack
- bgRed
- bgGreen
- bgYellow
- bgBlue
- bgMagenta
- bgCyan
- bgWhite
- reset
- bold
- dim
- italic
- underline
- inverse
- hidden
- strikethrough
import 'colorts/lib/string';
console.log('hello'.green); // outputs green text
console.log('i like cake and pies'.underline.red) // outputs red underlined text
console.log('inverse the color'.inverse); // inverses the color
import color from 'colorts';
import {echo} from 'colorts';
console.log(colors('hello').green + ""); // outputs green text
console.log(colors('i like cake and pies').red.underline.toString) // outputs red underlined text
echo(colors('inverse the color').inverse); // you can use echo to console.log safe colorts
require('colorts/lib/string');
console.log('hello'.green); // outputs green text
console.log('i like cake and pies'.underline.red) // outputs red underlined text
console.log('inverse the color'.inverse); // inverses the color
let color = require('colorts');
let echo = require('colorts').echo;
console.log(colors('hello').green + ""); // outputs green text
console.log(colors('i like cake and pies').red.underline.toString) // outputs red underlined text
echo(colors('inverse the color').inverse); // you can use echo to console.log safe colorts
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.
To disable colors you can pass the following arguments in the command line to your application:
node myapp.js --no-color
- capitalize
"james is a nice guy.".capitalize // James is nice guy.
" no one home.".capitalize // No one home.
"typescript".capitalize // Typescript
"1st january 2018".capitalize // 1st january 2018
- titleCase
"james is a nice guy.".titleCase // James Is Nice Guy.
" no one home.".titleCase // No One Home.
"tYpe scrIpt".titleCase // Type Script
"1st january".titleCase // 1st January 2018
- camelCase
"james is a nice guy.".camelCase // jamesIsANiceGuy.
" no one home.".camelCase // nOneHome.
"type script".camelCase // typeScript
- upperCamelCase
"james is a nice guy.".upperCamelCase // JamesIsANiceGuy.
" no one home.".upperCamelCase // NOneHome.
"type script".upperCamelCase // TypeScript
- lowerCamelCase
"james is a nice guy.".lowerCamelCase // jamesIsANiceGuy.
" no one home.".lowerCamelCase // nOneHome.
"type script".lowerCamelCase // typeScript
- snakeCase
"james is a nice guy.".snakeCase // james_is_nice_guy.
" no one home.".snakeCase // no_one_home.
"super type script".snakeCase // super_type_script
- kebabCase
"James is a nice guy.".kebabCase // james-is-nice-guy.
" no one home.".kebabCase // no-one-home.
"super type script".kebabCase // super-type-script
- studlyCaps
"james is a nice guy.".studlyCaps // JaMeSiSnIcEgUy.
" no one home.".studlyCaps // NoOnEhOmE.
"super type script".studlyCaps // SuPeRtYpEsCrIpT