Socket
Socket
Sign inDemoInstall

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 3.0.0 to 3.0.1

2

index.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const{round:e,floor:t,max:r}=Math,n=(e,t,r)=>{if(""===t)return e;let n,i=t.length,o=0,l="";for(;~(n=e.indexOf(t,o));)l+=e.slice(o,n)+r,o=n+i;return o?l+e.slice(o):e},i=e=>{let[,t]=/([a-f\d]{3,6})/i.exec(e)||[],r=t?t.length:0;if(3===r)t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2];else if(6!==r)return[0,0,0];let n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n]},o=(t,r,n)=>t===r&&r===n?t<8?16:t>248?231:e((t-8)/247*24)+232:16+36*e(t/51)+6*e(r/51)+e(n/51),l=n=>{let i,o,l;if(n<8)return 30+n;if(n<16)return n-8+90;if(n>=232)i=o=l=(10*(n-232)+8)/255;else{const e=(n-=16)%36;i=t(n/36)/5,o=t(e/6)/5,l=e%6/5}const s=2*r(i,o,l);if(0===s)return 30;let g=30+(e(l)<<2|e(o)<<1|e(i));return 2===s?g+60:g},s=(e,t,r)=>l(o(e,t,r)),g=(e=>{const t=e=>!!g.find((t=>e.test(t))),r=globalThis,n=r.Deno,i=null!=n,o=r.process||n||{},l=o.stdout,s="win32"===(i?n.build.os:o.platform),g=o.argv||o.args||[];let c,a=o.env||{};if(i)try{a=a.toObject()}catch(e){c=0}const u="FORCE_COLOR",b=u in a,p=a[u],h="true"===p||parseInt(p,10)>0,f="NO_COLOR"in a||b&&!h||t(/^-{1,2}(no-color|color=(false|never))$/),d=b&&h||t(/^-{1,2}color=?(true|always)?$/),B=(a.NEXT_RUNTIME||"").indexOf("edge")>-1||(i?n.isatty(1):l&&"isTTY"in l);return f?0:(null==c&&(c=s?3:((e,t)=>{const{TERM:r,COLORTERM:n}=e;return"TF_BUILD"in e?1:"TEAMCITY_VERSION"in e?2:"CI"in e?["GITHUB_ACTIONS","GITEA_ACTIONS"].some((t=>t in e))?3:1:!t||/-mono|dumb/i.test(r)?0:"truecolor"===n||"24bit"===n||"xterm-kitty"===r?3:/-256(colou?r)?$/i.test(r)?2:/^screen|^tmux|^xterm|^vt[1-5][0-9]([0-9])?|^ansi|color|cygwin|linux|mintty|rxvt/i.test(r)?1:3})(a,B)),d&&0===c?3:c)})(),c={open:"",close:""},a=g>0?(e,t)=>({open:`[${e}m`,close:`[${t}m`}):()=>c,u=39,b=49;let p=e=>a(`38;5;${e}`,u),h=e=>a(`48;5;${e}`,b),f=(e,t,r)=>a(`38;2;${e};${t};${r}`,u),d=(e,t,r)=>a(`48;2;${e};${t};${r}`,b);const B=e=>(t,r,n)=>e(o(t,r,n));1===g?(p=e=>a(l(e),u),h=e=>a(l(e)+10,b),f=(e,t,r)=>a(s(e,t,r),u),d=(e,t,r)=>a(s(e,t,r)+10,b)):2===g&&(f=B(p),d=B(h));const y={visible:c,reset:a(0,0),inverse:a(7,27),hidden:a(8,28),bold:a(1,22),dim:a(2,22),italic:a(3,23),underline:a(4,24),strikethrough:a(9,29),strike:a(9,29),black:a(30,u),red:a(31,u),green:a(32,u),yellow:a(33,u),blue:a(34,u),magenta:a(35,u),cyan:a(36,u),white:a(37,u),grey:a(90,u),gray:a(90,u),blackBright:a(90,u),redBright:a(91,u),greenBright:a(92,u),yellowBright:a(93,u),blueBright:a(94,u),magentaBright:a(95,u),cyanBright:a(96,u),whiteBright:a(97,u),bgBlack:a(40,b),bgRed:a(41,b),bgGreen:a(42,b),bgYellow:a(43,b),bgBlue:a(44,b),bgMagenta:a(45,b),bgCyan:a(46,b),bgWhite:a(47,b),bgGrey:a(100,b),bgGray:a(100,b),bgBlackBright:a(100,b),bgRedBright:a(101,b),bgGreenBright:a(102,b),bgYellowBright:a(103,b),bgBlueBright:a(104,b),bgMagentaBright:a(105,b),bgCyanBright:a(106,b),bgWhiteBright:a(107,b)},O=e=>t=>{let[r,n,o]=i(t);return e(r,n,o)},x={fg:p,bg:h,rgb:f,bgRgb:d,hex:O(f),bgHex:O(d)},m=f,{defineProperty:T,defineProperties:$,setPrototypeOf:k}=Object,w=/[›][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,R=/(\r*\n)/g,I={},C=({props:e},{open:t,close:r})=>{const i=(e,...t)=>((e,t,r)=>{if(!e)return"";const{openStack:i,closeStack:o}=r;let l=null!=e.raw?String.raw(e,...t):e+"";if(~l.indexOf(""))for(;null!=r;)l=n(l,r.close,r.open),r=r.props;return~l.indexOf("\n")&&(l=l.replace(R,o+"$1"+i)),i+l+o})(e,t,i.props);let o=t,l=r;return null!=e&&(o=e.openStack+t,l=r+e.closeStack),k(i,v),i.props={open:t,close:r,openStack:o,closeStack:l,props:e},i.open=o,i.close=l,i},S=function(){const e=e=>e+"";return e.strip=e=>e.replace(w,""),e.extend=t=>{for(let e in t){let r=t[e],n=null!=r.open?r:m(...i(r));I[e]={get(){const t=C(this,n);return T(this,e,{value:t}),t}}}v=$({},I),k(e,v)},e.extend(y),e};for(let e in x)I[e]={get(){return(...t)=>C(this,x[e](...t))}};let v;I.ansi256=I.fg,I.bgAnsi256=I.bg;const _=new S;module.exports=_,module.exports.Ansis=S;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const{round:e,floor:t,max:n}=Math,r=(e,t,n)=>{if(""===t)return e;let r,o=t.length,l=0,i="";for(;~(r=e.indexOf(t,l));)i+=e.slice(l,r)+n,l=r+o;return l?i+e.slice(l):e},o=e=>{let[,t]=/([a-f\d]{3,6})/i.exec(e)||[],n=t?t.length:0;if(3===n)t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2];else if(6!==n)return[0,0,0];let r=parseInt(t,16);return[r>>16&255,r>>8&255,255&r]},l=(t,n,r)=>t===n&&n===r?t<8?16:t>248?231:e((t-8)/247*24)+232:16+36*e(t/51)+6*e(n/51)+e(r/51),i=r=>{let o,l,i;if(r<8)return 30+r;if(r<16)return r-8+90;if(r>=232)o=l=i=(10*(r-232)+8)/255;else{const e=(r-=16)%36;o=t(r/36)/5,l=t(e/6)/5,i=e%6/5}const s=2*n(o,l,i);if(0===s)return 30;let c=30+(e(i)<<2|e(l)<<1|e(o));return 2===s?c+60:c},s=(e,t,n)=>i(l(e,t,n)),c=(e=>{const t=e=>!!c.find((t=>e.test(t))),n=globalThis,r=n.Deno,o=null!=r,l=n.process||r||{},i=l.stdout,s="win32"===(o?r.build.os:l.platform),c=l.argv||l.args||[];let u,a=l.env||{};if(o)try{a=a.toObject()}catch(e){u=0}const f="FORCE_COLOR",g=f in a,p=a[f],d="true"===p||parseInt(p,10)>0,b="NO_COLOR"in a||g&&!d||t(/^-{1,2}(no-color|color=(false|never))$/),_=g&&d||t(/^-{1,2}color=?(true|always)?$/),O=(a.NEXT_RUNTIME||"").indexOf("edge")>-1||(o?r.isatty(1):i&&"isTTY"in i);return b?0:(null==u&&(u=s?3:((e,t)=>{const{TERM:n,COLORTERM:r}=e;return"TF_BUILD"in e?1:"TEAMCITY_VERSION"in e?2:"CI"in e?["GITHUB_ACTIONS","GITEA_ACTIONS"].some((t=>t in e))?3:1:!t||/-mono|dumb/i.test(n)?0:"truecolor"===r||"24bit"===r||"xterm-kitty"===n?3:/-256(colou?r)?$/i.test(n)?2:/^screen|^tmux|^xterm|^vt[1-5][0-9]([0-9])?|^ansi|color|cygwin|linux|mintty|rxvt/i.test(n)?1:3})(a,O)),_&&0===u?3:u)})(),u={open:"",close:""},a=c>0?(e,t)=>({open:`[${e}m`,close:`[${t}m`}):()=>u,f=39,g=49;let p=e=>a(`38;5;${e}`,f),d=e=>a(`48;5;${e}`,g),b=(e,t,n)=>a(`38;2;${e};${t};${n}`,f),_=(e,t,n)=>a(`48;2;${e};${t};${n}`,g);const O=e=>(t,n,r)=>e(l(t,n,r)),x=e=>t=>{let[n,r,l]=o(t);return e(n,r,l)};1===c?(p=e=>a(i(e),f),d=e=>a(i(e)+10,g),b=(e,t,n)=>a(s(e,t,n),f),_=(e,t,n)=>a(s(e,t,n)+10,g)):2===c&&(b=O(p),_=O(d));const y={visible:u,reset:a(0,0),inverse:a(7,27),hidden:a(8,28),bold:a(1,22),dim:a(2,22),italic:a(3,23),underline:a(4,24),strikethrough:a(9,29),strike:a(9,29),grey:a(90,f),gray:a(90,f),bgGrey:a(100,g),bgGray:a(100,g)};let m,h,T=["black","red","green","yellow","blue","magenta","cyan","white"],$="Bright",I=30;for(m of T)h="bg"+m[0].toUpperCase()+m.slice(1),y[m]=a(I,f),y[m+$]=a(I+60,f),y[h]=a(I+10,g),y[h+$]=a(I+70,g),I++;const R={fg:p,bg:d,rgb:b,bgRgb:_,hex:x(b),bgHex:x(_)},v=b,{defineProperty:C,defineProperties:w,setPrototypeOf:E}=Object,A=/[›][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,M=/(\r?\n)/g,N={},k=({_p:e},{open:t,close:n})=>{const o=(e,...t)=>((e,t,n)=>{if(!e)return"";const{_a:o,_b:l}=n;let i=null!=e.raw?String.raw(e,...t):e+"";if(i.includes(""))for(;null!=n;)i=r(i,n.close,n.open),n=n._p;return i.includes("\n")&&(i=i.replace(M,l+"$1"+o)),o+i+l})(e,t,o._p);let l=t,i=n;return null!=e&&(l=e._a+t,i=n+e._b),E(o,L),o._p={open:t,close:n,_a:l,_b:i,_p:e},o.open=l,o.close=i,o},G=function(){const e=e=>e+"";return e.strip=e=>e.replace(A,""),e.extend=t=>{for(let e in t){let n=t[e],r=null!=n.open?n:v(...o(n));N[e]={get(){const t=k(this,r);return C(this,e,{value:t}),t}}}L=w({},N),E(e,L)},e.extend(y),e};for(let e in R)N[e]={get(){return(...t)=>k(this,R[e](...t))}};let L;N.ansi256=N.fg,N.bgAnsi256=N.bg;const P=new G;module.exports=P,module.exports.Ansis=G;
{
"name": "ansis",
"version": "3.0.0",
"version": "3.0.1",
"description": "Colorize text in terminal and console output with ANSI colors & styles",

@@ -5,0 +5,0 @@ "keywords": [

@@ -28,6 +28,18 @@ <div align="center">

**Why yet one lib?**\
See the features [comparison](https://github.com/webdiscus/ansis#compare) and [benchmarks](https://github.com/webdiscus/ansis#benchmark) of most popular Node.js libraries:\
[`chalk`][chalk], [`colors.js`][colors.js], [`colorette`][colorette], [`picocolors`][picocolors], [`kleur`][kleur], [`ansi-colors`][ansi-colors], [`cli-color`][cli-color], [`colors-cli`][colors-cli].
🚀 [Install and Quick Start](#install)
<a id="top" name="top"></a>
## 👀 Why yet one lib?
- Quality is first, test coverage 100%.
- Ansis has a lot of useful [features](#features), compare with [other libraries](#compare).
- Ansis is one of the smallest, 3.4 KB only.
- Ansis is one of the [fastest](#benchmark).
- Ansis is stable, continuously developing and improving.
- Ansis is open for your [feature requests](https://github.com/webdiscus/ansis/issues).
See the features [comparison](#compare) and [benchmarks](#benchmark) of most popular Node.js libraries:\
[chalk][chalk], [colors.js][colors.js], [colorette][colorette], [picocolors][picocolors], [kleur][kleur], [kolorist][kolorist], [ansi-colors][ansi-colors], [cli-color][cli-color], [colors-cli][colors-cli].
<div align="center">

@@ -41,3 +53,3 @@ <a href="https://www.npmjs.com/package/ansis">

<a id="top" name="top"></a>
<a id="features" name="features"></a>

@@ -54,3 +66,3 @@ ## 💡 Highlights

chalk.red.bold('Error!'); // <- the Chalk like syntax works fine with Ansis
chalk.red.bold('Error!'); // <- Chalk like syntax works fine with Ansis
red.bold('Error!'); // <- the same result with Ansis

@@ -67,3 +79,7 @@ red.bold`Error!`; // <- the same result with Ansis

- [Nested **template strings**](#nested-syntax) ``` green`GREEN text ${red`RED text`} GREEN text` ```
- [ANSI 256 colors](#256-colors) and [TrueColor](#truecolor) (**RGB**, **HEX**) ``` rgb(224, 17, 95)`Ruby` ```, ``` hex('#96C')`Amethyst` ```
- [Base ANSI styles](#base-colors) `dim` **`bold`** _`italic`_ <u>`underline`</u> <s>`strikethrough`</s>
- [Base ANSI 16 colors](#base-colors) ``` red`Error!` ``` ``` redBright`Error!` ``` ``` bgRed`Error!` ``` ``` bgRedBright`Error!` ```
- [ANSI 256 colors](#256-colors) ``` fg(56)`violet` ``` ``` bg(208)`orange` ```
- [TrueColor](#truecolor) (**RGB**, **HEX**) ``` rgb(224, 17, 95)`Ruby` ```, ``` hex('#96C')`Amethyst` ```
- [Fallback](#fallback) to supported [color space](#color-support): TrueColor —> 256 colors —> 16 colors —> no colors
- [Extending of base colors](#extend-colors) with named **True Colors**

@@ -74,5 +90,4 @@ - [ANSI codes](#escape-codes) as `open` and `close` properties ``` `Hello ${red.open}World${red.close}!` ```

- Supports [environment variables](#cli-vars) `NO_COLOR` `FORCE_COLOR` and flags `--no-color` `--color`
- **Auto detects** [color spaces support](#color-support): TrueColor, 256 colors, 16 colors, no color (black & white)
- [Fallback](#fallback) to supported color space: TrueColor —> 256 colors —> 16 colors —> no colors
- Up to **x3 faster** than **Chalk**, [see benchmarks](#benchmark) and code bundle size is only **3.8 KB**
- Up to **x3 faster** than **Chalk**, [see benchmarks](#benchmark)
- Code bundle is only **3.4 KB**
- Doesn't extend `String.prototype`

@@ -98,3 +113,3 @@ - Zero dependencies

## Install
## Install and Quick Start

@@ -105,4 +120,2 @@ ```bash

## Usage
You can import default module or named colors with ESM or CommonJS syntax.

@@ -126,2 +139,4 @@

See the list of the [ANSI colors and styles](#base-colors).
```js

@@ -295,3 +310,3 @@ console.log(ansis.green('Success!'));

## Base colors and styles
## Base ANSI 16 colors and styles

@@ -301,21 +316,20 @@ Colors and styles have standard names used by many popular libraries, such

| Foreground colors | Background colors | Styles |
|:----------------------|:--------------------------|-----------------------------------------|
| `black` | `bgBlack` | `dim` |
| `red` | `bgRed` | **`bold`** |
| `green` | `bgGreen` | _`italic`_ |
| `yellow` | `bgYellow` | <u>`underline`</u> |
| `blue` | `bgBlue` | <s>`strikethrough`</s> (alias `strike`) |
| `magenta` | `bgMagenta` | `inverse` |
| `cyan` | `bgCyan` | `visible` |
| `white` | `bgWhite` | `hidden` |
| `gray` (alias `grey`) | `bgGray` (alias `bgGrey`) | `reset` |
| `blackBright` | `bgBlackBright` | |
| `redBright` | `bgRedBright` | |
| `greenBright` | `bgGreenBright` | |
| `yellowBright` | `bgYellowBright` | |
| `blueBright` | `bgBlueBright` | |
| `magentaBright` | `bgMagentaBright` | |
| `cyanBright` | `bgCyanBright` | |
| `whiteBright` | `bgWhiteBright` | |
| Foreground colors | Background colors | Styles |
|:----------------------------------------------------------|:----------------------------------------------------------------|-----------------------------------------|
| `black` | `bgBlack` | `dim` |
| `red` | `bgRed` | **`bold`** |
| `green` | `bgGreen` | _`italic`_ |
| `yellow` | `bgYellow` | <u>`underline`</u> |
| `blue` | `bgBlue` | <s>`strikethrough`</s> (alias `strike`) |
| `magenta` | `bgMagenta` | `inverse` |
| `cyan` | `bgCyan` | `visible` |
| `white` | `bgWhite` | `hidden` |
| `blackBright`<br>aliases:<br>`grey`<br>`gray` US spelling | `bgBlackBright`<br>aliases:<br>`bgGrey`<br>`bgGray` US spelling | `reset` |
| `redBright` | `bgRedBright` | |
| `greenBright` | `bgGreenBright` | |
| `yellowBright` | `bgYellowBright` | |
| `blueBright` | `bgBlueBright` | |
| `magentaBright` | `bgMagentaBright` | |
| `cyanBright` | `bgCyanBright` | |
| `whiteBright` | `bgWhiteBright` | |

@@ -602,2 +616,9 @@ <a id="extend-colors" name="extend-colors"></a>

Ansis automatically detects the supported color space:
- TrueColor
- ANSI 256 colors
- ANSI 16 colors
- black & white (no color)
There is no standard way to detect which color space is supported.

@@ -608,17 +629,17 @@ The most common way to detect color support is to check the `TERM` and `COLORTERM` environment variables.

| Name | ANSI 16<br>colors | ANSI 256<br>colors | True<br>Color | $TERM | $COLORTERM | specifically ENV variable |
|:---------------------------------|-------------------|:-------------------|:--------------|:---------------|:----------:|:----------------------------------------|
| Azure CI | ✅ | ❌ | ❌ | dumb | | $TF_BUILD<br>$AGENT_NAME |
| GitHub CI | ✅ | ✅ | ✅ | dumb | | $CI<br>$GITHUB_ACTIONS |
| GitTea CI | ✅ | ✅ | ✅ | dumb | | $CI<br>$GITEA_ACTIONS |
| GitLab CI | ✅ | ❌ | ❌ | dumb | | $CI<br>$GITLAB_CI |
| Travis CI | ✅ | ❌ | ❌ | dumb | | $TRAVIS |
| JetBrains TeamCity<br>>=2020.1.1 | ✅ | ✅ | ❌ | | | $TEAMCITY_VERSION |
| JetBrains IDEA | ✅ | ✅ | ✅ | xterm-256color | | $TERMINAL_EMULATOR='JetBrains-JediTerm' |
| VS Code | ✅ | ✅ | ✅ | xterm-256color | truecolor | |
| Windows<br>Terminal | ✅ | ✅ | ✅* | | | |
| Windows<br>PowerShell | ✅ | ✅ | ✅* | | | |
| macOS Terminal | ✅ | ✅ | ❌ | xterm-256color | | |
| iTerm | ✅ | ✅ | ✅ | xterm-256color | truecolor | |
| Terminal emulator Kitty | ✅ | ✅ | ✅ | xterm-kitty | | |
| Terminal | ANSI 16<br>colors | ANSI 256<br>colors | True<br>Color | env.<br>TERM | env.<br>COLORTERM | Specifically ENV variables |
|:---------------------------------|-------------------|:-------------------|:--------------|:--------------:|:-----------------:|:---------------------------------------|
| Azure CI | ✅ | ❌ | ❌ | dumb | | TF_BUILD<br>AGENT_NAME |
| GitHub CI | ✅ | ✅ | ✅ | dumb | | CI<br>GITHUB_ACTIONS |
| GitTea CI | ✅ | ✅ | ✅ | dumb | | CI<br>GITEA_ACTIONS |
| GitLab CI | ✅ | ❌ | ❌ | dumb | | CI<br>GITLAB_CI |
| Travis CI | ✅ | ❌ | ❌ | dumb | | TRAVIS |
| JetBrains TeamCity<br>>=2020.1.1 | ✅ | ✅ | ❌ | | | TEAMCITY_VERSION |
| JetBrains IDEA | ✅ | ✅ | ✅ | xterm-256color | | TERMINAL_EMULATOR='JetBrains-JediTerm' |
| VS Code | ✅ | ✅ | ✅ | xterm-256color | truecolor | |
| Windows<br>Terminal | ✅ | ✅ | ✅* | | | |
| Windows<br>PowerShell | ✅ | ✅ | ✅* | | | |
| macOS Terminal | ✅ | ✅ | ❌ | xterm-256color | | |
| iTerm | ✅ | ✅ | ✅ | xterm-256color | truecolor | |
| Terminal emulator Kitty | ✅ | ✅ | ✅ | xterm-kitty | | |

@@ -643,13 +664,14 @@ *The Windows terminal supports true color since Windows 10 revision 14931 (2016-09-21).

| Library<br>______________<br> - name<br> - code size<br> - named import | Naming<br>base colors | ANSI 256<br>colors | True<br>Color | Chained<br>syntax | Nested<br>template strings | New<br>Line | Supports<br>CLI params |
|:---------------------------------------------------------------------------|:------------------------------------------:|:------------------:|:-------------:|:-----------------:|:--------------------------:|:-----------:|:---------------------------------------------------------|
| [`colors.js`][colors.js]<br>**18.1KB**<br><nobr>`❌ named import`</nobr> | <nobr>_non-standard_</nobr><br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
| [`colors-cli`][colors-cli]<br>**8.6KB**<br><nobr>`❌ named import`</nobr> | <nobr>_non-standard_</nobr><br>`16` colors | ✅ | ❌ | ✅ | ❌ | ✅ | only<br>`--no-color`<br>`--color` |
| [`cli-color`][cli-color]<br><nobr>`❌ named import`</nobr> | **standard**<br>`16` colors | ✅ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR` |
| [`ansi-colors`][ansi-colors]<br>**5.8KB**<br><nobr>`❌ named import`</nobr> | **standard**<br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR` |
| [`colorette`][colorette]<br>**3.3KB**<br><nobr>`✅ named import`</nobr> | **standard**<br>`16` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
| [`picocolors`][picocolors]<br>**2.6KB**<br><nobr>`❌ named import`</nobr> | **standard**<br>`8` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
| [`kleur`][kleur]<br>**2.7KB**<br><nobr>`✅ named import`</nobr> | **standard**<br>`8` colors | ❌ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR`<br>`FORCE_COLOR` |
| [`chalk`][chalk]<br>**15KB**<br><nobr>`❌ named import`</nobr> | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ❌ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
| [`ansis`][ansis]<br>**3.8KB**<br><nobr>`✅ named import`</nobr> | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ✅ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
| Library<br><nobr>________________</nobr><br> - name<br> - bundle size<br> - named import<br>- naming colors | ANSI base colors | ANSI 256<br>colors | True<br>Color | Chained<br>syntax | Nested<br>template strings | New<br>Line | Fallbacks | Supports<br>ENV vars<br>CLI flags |
|:------------------------------------------------------------------------------------------------------------|:----------------:|:------------------:|:-------------:|:-----------------:|:--------------------------:|:-----------:|------------------------------------|:---------------------------------------------------------|
| [`colors.js`][colors.js]<br>**18.1KB**<br><nobr>`❌ named import`</nobr><br>`❌ standard` | `16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | no color | `FORCE_COLOR`<br>`--no-color`<br>`--color` |
| [`colors-cli`][colors-cli]<br>**8.6KB**<br><nobr>`❌ named import`</nobr><br>`❌ standard` | `16` colors | ✅ | ❌ | ✅ | ❌ | ✅ | no color | `--no-color`<br>`--color` |
| [`cli-color`][cli-color]<br><nobr>`❌ named import`</nobr><br>`✅ standard` | `16` colors | ✅ | ❌ | ✅ | ❌ | ❌ | 16 colors<br>no color | `NO_COLOR` |
| [`ansi-colors`][ansi-colors]<br>**5.8KB**<br><nobr>`❌ named import`</nobr><br>`✅ standard` | `16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | ❌ | `FORCE_COLOR` |
| [`colorette`][colorette]<br>**3.3KB**<br><nobr>`✅ named import`</nobr><br>`✅ standard` | `16` colors | ❌ | ❌ | ❌ | ❌ | ❌ | no color | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
| [`picocolors`][picocolors]<br>**2.6KB**<br><nobr>`❌ named import`</nobr><br>`✅ standard` | `8` colors | ❌ | ❌ | ❌ | ❌ | ❌ | no color | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
| [`kleur`][kleur]<br>**2.7KB**<br><nobr>`✅ named import`</nobr><br>`✅ standard` | `8` colors | ❌ | ❌ | ✅ | ❌ | ❌ | no color | `NO_COLOR`<br>`FORCE_COLOR` |
| [`kolorist`][kolorist]<br>**6.8KB**<br><nobr>`✅ named import`</nobr><br>`❌ standard` | `16` colors | ✅ | ✅ | ❌ | ❌ | ❌ | 256 color<br>❌<br>no color | `NO_COLOR`<br>`FORCE_COLOR` |
| [`chalk`][chalk]<br>**15KB**<br><nobr>`❌ named import`</nobr><br>`✅ standard` | `16` colors | ✅ | ✅ | ✅ | ❌ | ✅ | 256 color<br>16 colors<br>no color | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
| [`ansis`][ansis]<br>**3.4KB**<br><nobr>`✅ named import`</nobr><br>`✅ standard` | `16` colors | ✅ | ✅ | ✅ | ✅ | ✅ | 256 color<br>16 colors<br>no color | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |

@@ -710,4 +732,21 @@ > **Note**

## Run benchmark
## Benchmark
To measure performance is used [benchmark.js](https://github.com/bestiejs/benchmark.js).
> ‼️ **Warning**
>
> **Don't trust** other test results using [vitest benchmark](https://vitest.dev/config/#benchmark).
>
> The `vitest benchmark` generate FALSE/**unreal** results.\
> For example, the results of the simple bench:
> ```
> chalk.red('foo') - 7.000.000 ops/sec
> ansis.red('foo') - 23.000.000 ops/sec (x3 faster is WRONG result)
> ```
>
> The real performance results of `chalk` and `ansis` in this test are very close.
### Run benchmark
```bash

@@ -926,4 +965,6 @@ git clone https://github.com/webdiscus/ansis.git

[kolorist]: https://github.com/marvinhagemeister/kolorist
[chalk]: https://github.com/chalk/chalk
[ansis]: https://github.com/webdiscus/ansis
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