Releases: webdiscus/ansis
v4.2.0
Feature
Added support named truecolors via ansis.extend() for both foreground and background.
Foreground methods are created from the provided color names, and matching background methods bg* are generated automatically.
Example:
import ansis from 'ansis';
import colorNames from 'css-color-names';
const color = ansis.extend(colorNames);
console.log(color.orange('Orange foreground'));
console.log(color.bgOrange('Orange background')); // auto-generated from "orange"Note
The css-color-names (~6 kB) package exports CSS color names with their hex values.
This release removes the last barrier for projects migrating from Chalk v4 that used named truecolors:
- chalk.keyword('orange')('text');
+ color.orange('text');
- chalk.bgKeyword('orange')('text');
+ color.bgOrange('text');Ansis provides this feature with a simpler, more intuitive API.
Important
Fallback for named truecolors
Ansis automatically interpolates named truecolors to the highest available color level supported by the current environment.
So you can safely use named truecolors anywhere without worrying about compatibility.
v4.1.0
Release v4.0.0
✨ Ansis v4 - Smaller package and cleaner API
Ansis v4 drops unused duplicate aliases and legacy baggage.
This release brings a stable and more compact ANSI library.
v4 is ~15.7% smaller than v3.17
Follow the migration guide to upgrade.
⚠️ BREAKING CHANGES
1) Dropped support for Deno 1.x (EOL - October 9, 2024)
This version now supports Deno 2.0 and above.
2) Removed non-standard strike alias for strikethrough style
The legacy strike alias has been removed to clean up the API and stay consistent with ANSI style conventions.
- The
strikestyle was rarely (if ever) used and added unnecessary redundancy. - No usage of
ansis.strike()was found in public GitHub repositories. - Other ANSI libraries use the standard
strikethroughname exclusively.
3) Removed redundant aliases: grey, bgGrey, blackBright and bgBlackBright - use the standard gray and bgGray instead.
Holywar: gray vs grey vs blackBright
All these color names referred the same ANSI code.
However, keeping many separate names for the same color is too much for a small library.
Why gray only, without aliases?
ANSI codes for the gray color:
-
90- officially "bright black" foreground (i.e.,gray) in terminal specs. 100- officially "bright black" background (i.e.,bgGray) in terminal specs.
Ansis prefers the more intuitive and commonly used names: gray and bgGray.
- ✅
gray,bgGray- Standard spelling, common used, and intuitive - ❌
grey,bgGrey- British spelling, uncommon, rarely used, and redundant aliases forgrayandbgGray - ❌
blackBright,bgBlackBright- Spec-style names for "bright black", less intuitive, never used, awkward for practical use
Note
Supporting both gray and grey (or even worse, verbose aliases like bgBlackBright) introduces unnecessary duplication.
Ansis v4 is focused on a clean, minimal API by intentionally avoiding redundant aliases.
4) Using 256-color functions
The following legacy method aliases have been removed:
| ❌ Removed Method | ✅ Use Instead |
|---|---|
ansi256(code) |
fg(code) |
bgAnsi256(code) |
bg(code) |
These aliases were originally added for compatibility with Chalk.
Starting with this release, Ansis focuses on a cleaner and compact API, free from duplicated methods and legacy layers.
Why fg() and bg() are better than ansi256() and bgAnsi256()
Ansis has grown beyond being a Chalk-compatible alternative - it's now a modern and compact ANSI library with its own identity.
Clean API
ansis.fg(code)andansis.bg(code)are shorter more elegant thanansis.ansi256(code)andansis.bgAnsi256(code)fgandbgclearly describe their purpose: setting foreground and background colors- These method names align with conventions used by many other color libraries
- Introduced on Dec 2021,
fg()andbg()are already being used in GitHub projects - Removing duplicates makes the API cleaner and more compact
5) Removed the unused AnsiColorsExtend type.
This type was intended to support extended theme colors, but it was never used in other projects.
If you relied on it in your own code (e.g. for typing custom styles), you can easily define it yourself.
6) Improved extend() method
The extend() method has been redesigned for better TypeScript support and flexibility.
Old behavior:
extend<U extends string>(colors: Record<U, string>): asserts this is Ansis & Record<U, Ansis>;- Modifies the current instance in-place.
- Returns
void. - ✅ Worked with default instance:
import ansis from 'ansis'; ansis.extend({ pink: '#FF75D1' }); console.log(ansis.pink('foo'));
- ❌ Limitation - Did not work with newly created instances:
import { Ansis } from 'ansis'; const ansis = new Ansis(); ansis.extend({ pink: '#FF75D1' }); // TS2775: Assertions require every name in the call target to be declared with an explicit type annotation. console.log(ansis.pink('Hello')); // TS2339: Property 'pink' does not exist
New behavior:
extend<U extends string>(colors: Record<U, string >): Ansis & Record<U, Ansis>;-
Returns an extended instance with full type support.
-
✅ Works with both
ansisandnew Ansis():import antis from 'ansis'; const colors = ansis.extend({ pink: '#FF75D1' }); console.log(colors.pink('foo'));
import { Ansis } from 'ansis'; const ansis = new Ansis().extend({ pink: '#FF75D1' }); console.log(ansis.pink('foo'));
Why this change?
TypeScript cannot widen the type of an existing variable when using asserts.
This means the old approach only worked for top-level constants like ansis, not new instances.
By returning the extended instance, the new approach enables full type inference in all scenarios.
Summary:
assertsversion removedextend()now returns an instance with extended types- Cleaner, safer, and fully compatible with all usage patterns
✨ Features
1) Support escape sequences in tagged template literals
Ansis now treats tagged template literals the same way as normal strings, returning the same result as the standard function call.
Example with \n (newline, unescaped):
red('prev\nnext')
red`prev\nnext`Output:
prev
next
Example with escaped backslash:
red('prev\\next')
red`prev\\next`Output:
prev\next
2) Manually set the color level
Ansis automatically detects color support, but you can manually set the color level.
You can create a new instance of Ansis with the desired color level.
Disable colors:
import { Ansis } from 'ansis';
const ansis = new Ansis(0);
console.log(ansis.red`foo`); // Output: plain string, no ANSI codesUse only basic 16 colors:
import { Ansis } from 'ansis';
const ansis = new Ansis(1);
console.log(ansis.hex('#FFAB40')`Orange`); // Output: fallback to yellowBright3) Simplified CI color detection
Affects: In rare CI environments, output may fallback to 16 colors or black & white.
Ansis provides basic support for standard CI environments by checking the commonly used CI environment variable. In these environments, Ansis assumes support for at least 16 colors. If your code uses 256-color or truecolor, Ansis automatically fallback to 16 colors or to black and white if no color support is detected.
Ansis focuses on the most common scenarios, as specific CI environments are rarely used in practice. This approach keeps the package lightweight without including unnecessary detection logic.
GitHub Actions is still detected as supporting truecolor, as most Ansis users rely on GitHub CI.
In general, color output in CI environments is not critical and can gracefully fallback when needed.
The xterm-direct detection logic (introduced in v3.5.0) has been removed, as it's unnecessary for identifying truecolor-capable terminals.
Note
No terminal emulator sets TERM=xterm-direct by default.
Modern terminals, including KDE Konsole, typically use TERM=xterm-256color along with COLORTERM=truecolor
to indicate truecolor support.
🛠️ Bug Fixes
Defaults to 16 colors for unknown color support
Ansis now defaults uses 16 colors if it cannot detect support for 256 colors or truecolor.
- Old behavior: Unknown terminal → used truecolor (could result in incorrect colors)
- New behavior: Unknown terminal → uses only 16 colors (ensures broad compatibility)
Note
This is not a breaking change. Ansis gracefully interpolates higher color depths (truecolor and 256 colors)
down to 16 colors when using, e.g., fg(), hex() or rgb().
To explicitly enable truecolor, set the environment variable COLORTERM=24bit or FORCE_COLOR=3.
🔄 Migrating to Ansis v4
Note
There is extremely low likelihood that you'll need to migrate, as these changes are related to very very rare use cases.
But to be sure, please check your code for these changes.
1) Upgrade to Deno v2 (if used)
This version supports Deno 2.0 and newer.
2) Replace strike with strikethrough
- ansis.strike('text')
+ ansis.strikethrough('text')3) Replace grey and blackBright with gray
- ansis.grey('text')
- ansis.blackBright('text')
+ ansis.gray('text')4) Replace bgGrey and bgBlackBright with bgGray
- ansis.bgGrey('text')
- ansis.bgBlackBright('text')
+ ansis.bgGray('text')5) Replace ansi256() with fg()
- ansis.ansi256(196)('Error')
+ ansis.fg(196)('Error')6) Replace bgAnsi256() with bg()
- ansis.bgAnsi256(21)('Info')
+ ansis.bg(21)('Info')7) Update the extend() method
The new extend() method now returns an extended instance instead of modifying the original instance in-place.
To migrate, assign the result of extend() to a new variable (avoid reassigning the original instance):
import ansis from 'ansis';
- ansis.extend({ pink: '#FF75D1' });
+ const colors = ansis.extend({ pink: '#FF75D1' });
- console.log(ansis.pink.bold('foo'));
+ console.log(colors.pink.bold('foo'));Alternatively:
- import ansis from 'ansis';
+ import { Ansis } from 'ansis';
- ansis.extend({ pink: '#FF75D1' });
+ const ansis = new Ansis().extend({ pink: '#FF75D1' });
console.log(ansis.pink.bold('foo'));...
v3.18.0-beta.0
BREAKING CHANGES
- Dropped support for Deno 1.x (end-of-life on October 9, 2024)
Features
- Added support for Deno 2.0 and newer
Note
The switch to Deno 2.0+ support is a breaking change and will be officially included in the next major release.
For v3.x users, it's available as an unofficial v3.18.0-beta.0 and will not be released as v3.18.0.
v4.0.0-beta
✨ Ansis v4 - Smaller package and cleaner API
Ansis v4 drops legacy baggage and unused artifacts.
This release brings a stable and more compact ANSI library.
See notes by release v4.0.0.
v3.17.0
v3.16.0
v3.14.0
v3.14.0
Cumulative Release v3.6.0 - v3.14.0
Features
-
Added support for chromium-based browsers.
Now you can use truecolor in the consoles of Chrome, Edge, Opera, Brave, Vivaldi and other Chromium-based browsers.
Browsers that do not support ANSI codes will display black and white text. -
Added support for
\nas a newline in template literals, e.g.:green`Hello\nWorld`renders:Hello World -
Function
ansis.reset()returns the reset escape code\e[0m. -
Enforce a specific color support by a
FORCE_COLORvalue:- false - Disables colors
- 0 - Disables colors
- true (or unset) - Auto detects the supported colors (if no color detected, enforce truecolor)
- 1 - Enables 16 colors
- 2 - Enables 256 colors
- 3 - Enables truecolor
-
Removed undocumented pointless dummy function
ansis(any).
Warning
This is not a BREAKING CHANGE because it was never officially documented!
import ansis from 'ansis';
ansis('text'); // <= now will occur the ERROR TS2349: This expression is not callable.This warning applies only to projects where Chalk was replaced with Ansis and something like chalk('text') was used.
Just replace ansis('text') with 'text'.
The ansis('text') function was a dummy and did nothing except return the same input string.
- Added support for legacy Node.js v14 (in package.json for npm was changed the
enginesto"node": ">=14"). - Micro optimisations for slight performance improvements.
Bug Fixes
- If the function argument is an empty string should be returned an empty string w/o escape codes:
ansis.red('') => '', // returns empty string w/o escape codes
- Cast falsy values
falseandNaNto a string.
In previous versions, the empty string''was returned for falsy values. - Functions with argument
0, e.g.ansis.red(0), returning empty string'', now return colored value'0'
v3.5.2
v3.5.2
Features
- Optimised the npm package size from
10.3kB to7.0 kB.Now, Ansis is the
smallestyet most powerful library withrich functionality.
A slightly smaller ispicocolors(6.4 kB), but it offers onlybasic functionality. - Added detection of the
xterm-directterminal as supportingtruecolor. - Added support for the
COLORTERMenvironment variable with the following values:truecolor,24bit,ansi256,ansi(16 colors).
Bug Fixes (TypeScript)
- Fixed default import in
TypeScriptcompiled withtsc:
import ansis from 'ansis'now works so well asimport * as ansis from 'ansis'. - Fixed the TS2339: Property 'strip' does not exist on type when the
tscoptionmoduleisnode16.
v3.4.0
v3.4.0
Cumulative Release v3.3.2 - v3.4.0
Bug Fixes
- Correct detect TTY on Windows platform.
Chore
- Optimised the npm package to reduce size by ~1.1 kB, from 11.4 kB to 10.3 kB.
- Added benchmarks for
koloristpackage. - Added new representative benchmarks by using combination of 1, 2, 3 and 4 styles.
- Refactor: invisible code optimisations.
