Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
ansi-colors
Advanced tools
The ansi-colors npm package is a utility for styling strings in the terminal with ANSI escape codes. It allows developers to add color and style to text output in command-line applications.
Text Colors
Apply text color to strings. The example shows how to make text red.
"const colors = require('ansi-colors');\nconsole.log(colors.red('This is red text'));"
Background Colors
Apply background color to strings. The example shows how to give text a red background.
"const colors = require('ansi-colors');\nconsole.log(colors.bgRed('This has a red background'));"
Text Styles
Apply text styles like bold, italic, underline, etc. The example shows how to make text bold.
"const colors = require('ansi-colors');\nconsole.log(colors.bold('This is bold text'));"
Chaining Styles
Chain multiple styles together. The example shows text that is blue, bold, and underlined.
"const colors = require('ansi-colors');\nconsole.log(colors.blue.bold.underline('This is blue, bold, and underlined'));"
Custom Themes
Create custom themes by combining styles. The example defines a custom theme with styles for error and warning messages.
"const colors = require('ansi-colors');\nconst customTheme = {\n error: colors.red.bold,\n warning: colors.yellow.italic\n};\nconsole.log(customTheme.error('Error message'));\nconsole.log(customTheme.warning('Warning message'));"
Chalk is a popular package similar to ansi-colors that provides a chainable API for styling strings. It offers a more extensive API and additional features like template literal support.
Kleur is a lightweight alternative to ansi-colors, focusing on performance. It has a similar API but does not support older versions of Node.js.
Colorette is another lightweight package for coloring terminal text. It aims to be fast and simple, with a minimalistic API compared to ansi-colors.
Collection of ansi colors and styles.
Install with npm
$ npm i ansi-colors --save
var colors = require('ansi-colors');
Wrap a string with ansi codes to create a black background.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.bgblack('some string'));
Wrap a string with ansi codes to create a blue background.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.bgblue('some string'));
Wrap a string with ansi codes to create a cyan background.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.bgcyan('some string'));
Wrap a string with ansi codes to create a green background.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.bggreen('some string'));
Wrap a string with ansi codes to create a magenta background.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.bgmagenta('some string'));
Wrap a string with ansi codes to create a red background.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.bgred('some string'));
Wrap a string with ansi codes to create a white background.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.bgwhite('some string'));
Wrap a string with ansi codes to create a yellow background.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.bgyellow('some string'));
Wrap a string with ansi codes to create black text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.black('some string'));
Wrap a string with ansi codes to create blue text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.blue('some string'));
Wrap a string with ansi codes to create bold text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.bold('some string'));
Wrap a string with ansi codes to create cyan text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.cyan('some string'));
Wrap a string with ansi codes to create dim text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.dim('some string'));
Wrap a string with ansi codes to create gray text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.gray('some string'));
Wrap a string with ansi codes to create green text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.green('some string'));
Wrap a string with ansi codes to create grey text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.grey('some string'));
Wrap a string with ansi codes to create hidden text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.hidden('some string'));
Wrap a string with ansi codes to create inverse text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.inverse('some string'));
Wrap a string with ansi codes to create italic text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.italic('some string'));
Wrap a string with ansi codes to create magenta text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.magenta('some string'));
Wrap a string with ansi codes to create red text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.red('some string'));
Wrap a string with ansi codes to reset ansi colors currently on the string.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.reset('some string'));
Wrap a string with ansi codes to add a strikethrough to the text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.strikethrough('some string'));
Wrap a string with ansi codes to underline the text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.underline('some string'));
Wrap a string with ansi codes to create white text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.white('some string'));
Wrap a string with ansi codes to create yellow text.
Params
str
{String}: String to wrap with ansi codes.returns
{String}: Wrapped stringExample
console.log(colors.yellow('some string'));
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Brian Woodward
Copyright © 2015 Brian Woodward Released under the MIT license.
This file was generated by verb-cli on November 30, 2015.
FAQs
Easily add ANSI colors to your text and symbols in the terminal. A faster drop-in replacement for chalk, kleur and turbocolor (without the dependencies and rendering bugs).
We found that ansi-colors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.