You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-Reliable [CLI testing](#cli-testing)by forcing specific [color levels](#color-levels): no color, 16, 256 or truecolor
50
+
-Enables reliable [CLI testing](#cli-testing)with forced [color levels](#color-levels): no color, 16, 256 or Truecolor
51
51
- Replacement for [`chalk`](#replacing-chalk)[`ansi-colors`](#replacing-ansi-colors)[`colorette`](#replacing-colorette)[`picocolors`](#replacing-picocolors) and others [alternatives](#alternatives)
52
52
53
53
<aid="install"name="install"></a>
@@ -97,7 +97,7 @@ The most popular ANSI libraries, similar to Ansis:
97
97
## ✨ [Why use Ansis](#switch-to-ansis)
98
98
99
99
As of 2025, two of the [smallest](#compare-size) and [fastest](#benchmark) ANSI libraries are **Ansis** and **Picocolors**.
100
-
Both are [recommended](https://github.com/es-tooling/module-replacements/blob/main/docs/modules/chalk.md) by the [ES Tooling](https://github.com/es-tooling) community as modern replacements for older, larger libraries.
100
+
Both are [recommended](https://github.com/es-tooling/module-replacements/blob/main/docs/modules/chalk.md) by the e18e community as modern replacements for older, larger libraries.
101
101
102
102
103
103
### 📦 Unpacked size
@@ -108,24 +108,25 @@ The package size in `node_modules` directory:
108
108
-`аnsis`: [5.7 kB][npm-ansis] (minimized) - A powerful library with a rich set of features.
109
109
-`chalk`: [44.2 kB][npm-chalk] (not minimized) - Provides similar functionality to Ansis.
110
110
111
+
See [Compare package sizes](#compare-size).
112
+
111
113
### ⚡ Performance
112
114
113
115
-`picocolors`: The [fastest](#bench-simple) when applying a single style (e.g., `red`) only.
114
116
-`аnsis`: The [fastest](#bench-2-styles) when applying two or more styles (e.g., `red` + `bgWhite`).
115
117
-`chalk`: Slower than both **Ansis** and **Picocolors** in all use cases.
116
118
119
+
See [Benchmarks](#benchmark).
120
+
117
121
> [!CAUTION]
118
-
> **Picocolors** doesn't handle important **edge cases**, so it is the fastest.
119
-
>
120
-
> **Picocolors** is faster only in a [simple](#bench-simple) micro-benchmark, which does not reflect real world usage.\
121
-
> In a more complex benchmark, **Ansis** is much [closer](#bench-picocolors-complex) to **Picocolors** results or even [faster](#bench-3-styles).
122
+
> **Picocolors** is the fastest in a [simple micro-benchmark](#bench-simple) because it doesn't handle important edge cases.
123
+
> However, that benchmark doesn't reflect real-world usage.
124
+
> In more complex and realistic benchmarks, Ansis performance is [comparable to Picocolors](#bench-picocolors-complex), or even [faster](#bench-3-styles).
122
125
123
126
<aid="edge-cases"name="edge-cases"></a>
124
127
### 🧩 Edge cases
125
128
126
-
#### Absent, `undefined` or `null` arguments
127
-
128
-
**Ansis** handles these cases correctly.
129
+
#### Handling falsy arguments
129
130
130
131
```js
131
132
ansis.red() // ✅ ''
@@ -140,24 +141,17 @@ ansis.red(null) // ✅ ''
140
141
chalk.red(null) // ❌ \e[31mnull\e[39m
141
142
pico.red(null) // ❌ \e[31mnull\e[39m
142
143
144
+
ansis.red('') // ✅ ''
145
+
chalk.red('') // ✅ ''
146
+
pico.red('') // ❌ \e[31m\e[39m
147
+
143
148
ansis.reset() // ✅ \e[0m
144
149
chalk.reset() // ❌ ''
145
150
pico.reset() // ❌ \e[0mundefined\e[0m
146
151
```
147
152
148
153
See more details about [handling input arguments](#handling-input-arguments) in various libraries.
149
154
150
-
#### Empty string
151
-
152
-
**Ansis** and **Chalk** handle this case and return an empty string without ANSI codes as expected.\
153
-
However, **Picocolors** doesn't handle this case.
154
-
155
-
```js
156
-
ansis.red('') // ✅ ''
157
-
chalk.red('') // ✅ ''
158
-
pico.red('') // ❌ \e[31m\e[39m
159
-
```
160
-
161
155
#### Break style at New Line
162
156
163
157
**Ansis** and **Chalk** add a style break at each `new line` to correctly display multi-line text.\
@@ -203,8 +197,7 @@ As of 2025, only **Ansis**, **Chalk**, and **Picocolors** are actively maintaine
203
197
- If you only use a single style, e.g., `red('foo')`, **Picocolors** is the best solution.
204
198
205
199
- However, if you need more, like combining multiple styles (e.g., `red` + `bold` + `bgWhite`),\
0 commit comments