Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ansis

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansis - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

5

CHANGELOG.md
# Change log
## 1.3.3 (2022-01-24)
- added UK spelling alias `grey` for `gray`
- update dev dependencies
- update readme
## 1.3.2 (2021-12-30)

@@ -4,0 +9,0 @@ - added bundle generation for ESM

21

package.json
{
"name": "ansis",
"version": "1.3.2",
"description": "Color styling of text for ANSI terminals using the SGR codes defined in the ECMA-48 standard.",
"version": "1.3.3",
"description": "Color styling of text for ANSI terminals.",
"keywords": [
"ansi",
"style",
"color",
"style",
"cli",

@@ -16,5 +16,4 @@ "console",

"hex",
"log",
"logging",
"bgGreen",
"truecolor",
"bgRed",
"NO_COLOR"

@@ -69,9 +68,9 @@ ],

"devDependencies": {
"@babel/core": "^7.16.5",
"@babel/preset-env": "^7.16.5",
"@types/jest": "^27.0.3",
"jest": "^27.4.5",
"@babel/core": "^7.16.12",
"@babel/preset-env": "^7.16.11",
"@types/jest": "^27.4.0",
"jest": "^27.4.7",
"prettier": "^2.5.1",
"rollup": "^2.62.0"
"rollup": "^2.66.0"
}
}

@@ -13,5 +13,6 @@ <h1 align="center">

Color styling of text for ANSI terminals using the SGR (Select Graphic Rendition) codes defined in the [ECMA-48](https://www.ecma-international.org/publications-and-standards/standards/ecma-48/) standard.\
This is improved and faster implementation for `Node.js`.
This is a Node.js library for coloring output in ANSI terminals.\
The ansis use the SGR (Select Graphic Rendition) codes defined in the [ECMA-48](https://www.ecma-international.org/publications-and-standards/standards/ecma-48/) standard.
<div align="center">

@@ -27,6 +28,6 @@ <a href="https://www.npmjs.com/package/ansis">

```bash
npm install ansis --save
npm install ansis
```
## Quick start
## Quick Start

@@ -39,68 +40,32 @@ ```js

console.log(ansis.green(`Hello ${ansis.inverse('ANSI')} World!`));
console.log(ansis.black.bgYellow(`Warning: `) + ansis.cyan(' /path/to/file.js ') + ansis.red(`not found!`) );
console.log(ansis.black.bgYellow(`Warning:`) + ansis.cyan(' /path/to/file.js ') + ansis.red(`not found!`) );
```
Output:
Output:\
![output](doc/img/quik-start-output.png?raw=true "output")
## Show ANSI demo
```bash
git clone https://github.com/webdiscus/ansis.git
cd ./ansis
npm i
npm run demo
```
## Features
- supports `ES Modules` and `CommonJS`
- supports both `ESM` and `CommonJS`
- standard API compatible with many popular ANSI libraries
- chained syntax
- nested syntax
- ANSI 256 colors and Truecolor
- detects color support
- supports the environment variables [`NO_COLOR`](https://no-color.org) `FORCE_COLOR` and flags `--no-color` `--color`
- low level access to the `open` and `close` properties for each style
- correct break of style at `end of line`
- faster than many others, [see benchmarks](#benchmark)
- no dependencies
- powerful and lightweight library is faster than many others such as `chalk` `kleur` `ansi-colors` etc.
- supports the standard de facto API of the `chalk`
- supports the environment variables [`NO_COLOR`](https://no-color.org) `FORCE_COLOR` and flags `--no-color` `--color`
- supports ANSI 256 colors and Truecolor
- supports styles like: `bold` `red` `yellowBright` `bgGreen` `bgCyanBright` ect.
- supports chained styles, e.g.:
```js
ansis.red.bold.italic.underline('text');
```
- supports nested styles like `colorette` `picocolors`, e.g.:
```js
const c = ansis;
c.red(`red ${c.italic.green('italic green')} red`);
c.red(`${c.bold(`${c.italic(`${c.underline('underline')}italic`)}bold`)}red`);
```
- supports methods for custom colors `rgb()` `hex()` `bgRgb()` `bgHex()` `ansi256()` `bgAnsi256()`:
```js
ansis.rgb(255, 80, 200)('text');
ansis.hex('#FF88AA')('text');
ansis.bgHex('#F8A')('text');
ansis.ansi256(110)('text');
```
- supports shortcut, e.g.:
```js
const theme = {
error: ansis.red.bold,
info: ansis.cyan.italic,
warning: ansis.black.bgYellowBright,
ruby: ansis.hex('#E0115F'),
bgAmber: ansis.bgHex('#FFBF00'),
};
- `String.prototype` stays virgin
theme.error('error');
theme.info('info');
theme.warning('warning');
theme.ruby('Ruby color');
theme.bgAmber('Amber background color');
```
- supports the use of `open` and `close` properties for each style, e.g.:
```js
const myStyle = ansis.bold.italic.black.bgHex('#ABCDEF');
console.log(`Hello ${ansis.green.open}ANSI${ansis.green.close} World!`);
console.log(`Hello ${myStyle.open}ANSI${myStyle.close} World!`);
```
- supports correct break of style at `end of line`, e.g.:
```js
ansis.bgGreen(`\nAnsis\nNew Line\nNext New Line\n`);
```
## Chained syntax
```js
ansis.underline.italic.bold.red('Styled text');
```
## Nested syntax
```js
const c = ansis;
c.red(`${c.bold(`${c.italic(`${c.underline('underline')}italic`)}bold`)}red`);
```
## Styles

@@ -131,3 +96,3 @@

`white`
`gray`
`gray` (alias `grey`)
`blackBright`

@@ -163,4 +128,7 @@ `redBright`

The pre-defined set of 256 colors:
Foreground: `.ansi256(code)` has aliases `.ansi(code)` and `.fg(code)`\
Background: `.bgAnsi256(code)` has aliases `.bgAnsi(code)` and `.bg(code)`
The pre-defined set of 256 colors.
| Code range | Description |

@@ -172,9 +140,5 @@ |-----------:|-------------------------------------------|

| 232 - 255 | grayscale from black to white in 24 steps |
|
See [ANSI color codes](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit).
**Foreground method:** `.ansi256(code)` has aliases `.ansi(code)` and `.fg(code)`.\
**Background method:** `.bgAnsi256(code)` has aliases `.bgAnsi(code)` and `.bg(code)`.
```js

@@ -194,2 +158,5 @@ // foreground color

Foreground: `hex` `rgb`\
Background: `bgHex` `bgRgb`
```js

@@ -207,15 +174,44 @@ // foreground color

## Shortcuts
```js
const theme = {
error: ansis.red.bold,
info: ansis.cyan.italic,
warning: ansis.black.bgYellowBright,
ruby: ansis.hex('#E0115F'),
};
theme.error('error');
theme.info('info');
theme.warning('warning');
theme.ruby('Ruby color');
```
## Low level usage
You can use the `open` and `close` properties for each style.
```js
const myStyle = ansis.bold.italic.black.bgHex('#ABCDEF');
console.log(`Hello ${myStyle.open}ANSI${myStyle.close} World!`);
```
## Correct break of style at `end of line`
```js
ansis.bgGreen(`\nAnsis\nNew Line\nNext New Line\n`);
```
![output](doc/img/break-style-nl.png?raw=true "break styles at EOL")
<a id="compare" href="#compare"></a>
## Compare most popular ANSI libraries
| Library | Standard<br>style / color<br>naming | Chain<br>styles | Nested<br>styles | New<br>Line | ANSI 256<br>colors | Truecolor<br>RGB / HEX | NO_COLOR |
|------------------------------|:-----------------------------------:|:---------------:|:----------------:|:-----------:|---------------------------------|------------------------|:------------------------------------------------------------|
| [`colors.js`][colors.js] | no, e.g.<br>`brightRed` | yes | yes | yes | - | - | only<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
| [`colorette`][colorette] | yes<br>(16 colors) | - | yes | - | - | - | yes |
| [`picocolors`][picocolors] | yes<br>(8 colors) | - | yes | - | - | - | yes |
| [`cli-color`][cli-color] | yes<br>(16 colors) | yes | yes | - | `.xterm(num)` | - | yes |
| [`color-cli`][color-cli] | no, e.g.<br>`red_bbt` | yes | _buggy_ | yes | `.x<num>` | - | only<br>`--no-color`<br>`--color` |
| [`ansi-colors`][ansi-colors] | yes<br>(16 colors) | yes | yes | yes | - | - | only<br>`FORCE_COLOR` |
| [`kleur`][kleur] | yes<br>(8 colors) | _yes_* | yes | - | - | - | yes |
| [`chalk`][chalk] | yes<br>(16 colors) | yes | yes | yes | `.ansi256(num)` | `.hex()` `.rgb()` | yes |
| [`ansis`][ansis-github] | yes<br>(16 colors) | yes | yes | yes | `.ansi256(num)`<br>`.ansi(num)` | `.hex()` `.rgb()` | yes |
| Library | Standard<br>style / color<br>naming | Chain<br>styles | Nested<br>styles | New<br>Line | ANSI 256<br>color<br>methods | Truecolor<br>RGB / HEX<br>methods | Supports<br>NO_COLOR |
|------------------------------|:-----------------------------------:|:---------------:|:----------------:|:-----------:|----------------------------------------------|-----------------------------------|:---------------------------------------------------|
| [`colors.js`][colors.js] | no, e.g.<br>`brightRed`<br>(16 colors) | yes | yes | yes | - | - | only<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
| [`colorette`][colorette] | yes<br>(16 colors) | - | yes | - | - | - | yes |
| [`picocolors`][picocolors] | yes<br>(8 colors) | - | yes | - | - | - | yes |
| [`cli-color`][cli-color] | yes<br>(16 colors) | yes | yes | - | `.xterm(num)` | - | yes |
| [`color-cli`][color-cli] | no, e.g.<br>`red_bbt`<br>(16 colors) | yes | _buggy_ | yes | `.x<num>` | - | only<br>`--no-color`<br>`--color` |
| [`ansi-colors`][ansi-colors] | yes<br>(16 colors) | yes | yes | yes | - | - | only<br>`FORCE_COLOR` |
| [`kleur`][kleur] | yes<br>(8 colors) | _yes_* | yes | - | - | - | yes |
| [`chalk`][chalk] | yes<br>(16 colors) | yes | yes | yes | `.ansi256(num)` | `.hex()` `.rgb()` | yes |
| [`ansis`][ansis-github] | yes<br>(16 colors) | yes | yes | yes | `.ansi256(num)`<br>`.ansi(num)`<br>.`fg(num)` | `.hex()` `.rgb()` | yes |

@@ -226,9 +222,20 @@ ### Column description

`kleur` use the chain of functions: `kleur.red().bold().underline('text')`.
- **Nested styles**:
- **Nested styles**: correct closing of nested escape sequences.
```js
c.red(`red ${c.green(`green ${c.underline(`underline`)} green`)} red`)
- **New Line**: correct break of escape sequences at `end of line`\
![output](doc/img/break-style-nl.png?raw=true "break styles at EOL")
- **New Line**: correct break of escape sequences at `end of line`.
```js
ansis.bgGreen(`\nAnsis\nNew Line\nNext New Line\n`);
```
- **NO_COLOR**: supports the environment variables [`NO_COLOR`](https://no-color.org) `FORCE_COLOR` and flags `--no-color` `--color`
## Show ANSI demo
```bash
git clone https://github.com/webdiscus/ansis.git
cd ./ansis
npm i
npm run demo
```
<a id="benchmark" href="#benchmark"></a>
## Benchmark

@@ -403,10 +410,10 @@

Most popular ANSI libraries for `Node.js`:
- [`colors.js`][colors.js]
- [`colorette`][colorette]
- [`picocolors`][picocolors]
- [`cli-color`][cli-color]
- [`color-cli`][color-cli]
- [`ansi-colors`][ansi-colors]
- [`kleur`][kleur]
- [`chalk`][chalk]
- [colors.js][colors.js]
- [colorette][colorette]
- [picocolors][picocolors]
- [cli-color][cli-color]
- [color-cli][color-cli]
- [ansi-colors][ansi-colors]
- [kleur][kleur]
- [chalk][chalk]

@@ -413,0 +420,0 @@ ## License

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc