Package Exports
- @prostojs/dye
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@prostojs/dye) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Got sick of chalk or other coloring libraries?
Here's easy and light console styling tool. 🔥🔥🔥 Create your styles and reuse them easily. 💙💚💛💗
Supports plain colors, modifiers, 256 color mode and true color mode (16m colors)
Install
npm install @prostojs/dye
Usage
import { dye } from '@prostojs/dye'
const bold = dye('BOLD')
console.log(bold('Text In Bold'))
// Text in Bold
Colors and modifiers
Function dye returns a style function based on input arguments.
You can pass arguments in any order.
Supported arguments (IDE will help as it's all well typed with TS):
- Plain colors:
BLACK,RED,GREEN,YELLOW,BLUE,MAGENTA,CYAN,WHITE; - Prefix
BG_turns color to background color (BG_RED); - Suffix
_BRIGHTmakes color brighter (RED_BRIGHT,BG_RED_BRIGHT); - Grayscale colors:
[BG_]GRAY<01..22>(GRAY01,GRAY02, ...,GRAY22,BG_GRAY01,BG_GRAY02, ...,BG_GRAY22); - Modifiers:
BOLD,DIM,ITALIC,UNDERSCORE,INVERSE,HIDDEN,CROSSED; - RGB 256 mode
_5,0,0,BG_5,0,0; - RGB True Color mode
255,0,0,BG255,0,0.
256 RGB version:
dye('_5,0,0') // red 256
dye('BG_5,0,0') // red 256 backgroundTrue Color RGB:
dye('255,0,0') // red True Color
dye('BG255,0,0') // red True Color backgroundSimple example
const bold = dye('BOLD')
console.log(bold('Text In Bold'))Advanced example
const myStyle = dye('ITALIC', 'BG_RED', '0,0,255')
console.log(myStyle('Styled italic blue text with red BG'))Super advanced example 😀
const { dye } = require('../dist/dye.cjs.prod')
const myStyle = dye('ITALIC', 'BG_RED', '0,0,255')
console.log(myStyle.open)
console.log('Italic blue text with red background')
console.log(myStyle.close)Strip the styles away
const { dye } = require('../dist/dye.cjs.prod')
const myStyle = dye('ITALIC', 'BG_RED', '0,0,255')
const styledText = myStyle('Styled text')
console.log(styledText) // styles applied
console.log(dye.strip(styledText)) // styles removed