- Install the module by using
npm i @hitomihiumi/colors.ts
- Enjoy!
black
red
green
yellow
blue
magenta
cyan
white
gray
grey
brightRed
brightGreen
brightYellow
brightBlue
brightMagenta
brightCyan
brightWhite
bgBlack
bgRed
bgGreen
bgYellow
bgBlue
bgMagenta
bgCyan
bgWhite
bgGray
bgGrey
bgBrightRed
bgBrightGreen
bgBrightYellow
bgBrightBlue
bgBrightMagenta
bgBrightCyan
bgBrightWhite
reset
bold
dim
italic
underline
inverse
hidden
strikethrough
rainbow
zebra
america
trap
random
import '@hitomihiumi/colors.ts';
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
console.log('OMG Rainbows!'.rainbow); // rainbow
console.log('Run the trap'.trap); // Drops the bass
Specify the bold
argument only after all style labels, otherwise you will get an error (applies to TS only)
console.log('hello'.green.bold);
The package will auto-detect whether your terminal can use colors and enable/disable accordingly. When colors are disabled, the color functions do nothing. You can override this with a command-line flag:
node myapp.js --no-color
node myapp.js --color=false
node myapp.js --color
node myapp.js --color=true
node myapp.js --color=always
FORCE_COLOR=1 node myapp.js
Or in code:
import { colors } from '@hitomihiumi/colors.ts';
colors.enable();
colors.disable();
import { colors } from '@hitomihiumi/colors.ts';
colors.setTheme({
silly: 'rainbow',
input: 'grey',
verbose: 'cyan',
prompt: 'grey',
info: 'green',
data: 'grey',
help: 'cyan',
warn: 'yellow',
debug: 'blue',
error: 'red'
});
declare global {
interface String {
silly: string;
input: string;
verbose: string;
prompt: string;
info: string;
data: string;
help: string;
warn: string;
debug: string;
error: string;
}
}
// outputs red text
console.log("this is an error".error);
// outputs yellow text
console.log("this is a warning".warn);
import { colors } from '@hitomihiumi/colors.ts';
colors.setTheme({
custom: ['red', 'underline']
});
declare global {
interface String {
custom: string;
}
}
console.log('test'.custom);