@pavelkv94/colorify
v0.0.7
Published
----------
Downloads
6
Maintainers
Readme
Console Colors
A simple npm package for adding colors and styles to your console output. Easily customize the appearance of your text with background colors, text colors, and text decorations.
Installation
Install the package using npm:
npm install @pavelkv94/colorify
or
yarn add @pavelkv94/colorify
Usage
To use the package, require it in your Node.js script and apply colors to your text as needed.
Example
const { applyColor, colors } = require('@pavelkv94/colorify');
// Apply text color
console.log(applyColor('This is red text!', colors.textColor.red));
// Apply background color
console.log(applyColor('This has a yellow background!', colors.bgColor.bgYellow + colors.textColor.black));
// Apply decoration
console.log(applyColor('This is underlined text.', colors.decoration.underline));`
es6
import { applyColor, colors } from ('@pavelkv94/colorify');
API
applyColor(text, colorCode)
Applies the given color code to the text and returns the formatted string.
Parameters:
text
(string): The text to be colored.colorCode
(string): The ANSI escape code for the color or decoration.
Returns:
- (string): The text formatted with the specified color or decoration.
Color Codes
Background Colors (colors.bgColor
)
bgBlack
: Black backgroundbgRed
: Red backgroundbgGreen
: Green backgroundbgYellow
: Yellow backgroundbgBlue
: Blue backgroundbgMagenta
: Magenta backgroundbgCyan
: Cyan backgroundbgWhite
: White background
Text Colors (colors.textColor
)
black
: Black textred
: Red textgreen
: Green textyellow
: Yellow textblue
: Blue textmagenta
: Magenta textcyan
: Cyan textwhite
: White text
Decorations (colors.decoration
)
reset
: Reset all stylesbright
: Bright textdim
: Dim textitalic
: Italic text (may not be supported in all terminals)underline
: Underlined textinverse
: Inverted text and background colorshidden
: Hidden text (not visible)strikethrough
: Strikethrough text (may not be supported in all terminals)
License
This package is licensed under the Apache-2.0.