@hitomihiumi/colors.ts
v1.0.3
Published
remake of colors.js on TS
Readme
Get Started
- Install the module by using
npm i @hitomihiumi/colors.ts - Enjoy!
Colors
text colors
blackredgreenyellowbluemagentacyanwhitegraygrey
bright text colors
brightRedbrightGreenbrightYellowbrightBluebrightMagentabrightCyanbrightWhite
background colors
bgBlackbgRedbgGreenbgYellowbgBluebgMagentabgCyanbgWhitebgGraybgGrey
bright background colors
bgBrightRedbgBrightGreenbgBrightYellowbgBrightBluebgBrightMagentabgBrightCyanbgBrightWhite
styles
resetbolddimitalicunderlineinversehiddenstrikethrough
extras
rainbowzebraamericatraprandom
Usage
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 bassImportant Notes
Specify the bold argument only after all style labels, otherwise you will get an error (applies to TS only)
console.log('hello'.green.bold);Enabling/Disabling Colors
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.jsOr in code:
import { colors } from '@hitomihiumi/colors.ts';
colors.enable();
colors.disable();Custom themes
Using standard API
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);Combining Colors
import { colors } from '@hitomihiumi/colors.ts';
colors.setTheme({
custom: ['red', 'underline']
});
declare global {
interface String {
custom: string;
}
}
console.log('test'.custom);