Changelog
4.0.0-beta.21 (2025-04-24)
Changelog
3.18.0-beta.0 (2025-04-22)
Changelog
4.0.0-beta.20 (2025-04-21)
Removed unused and rarely used aliases for gray
and bgGray
:
grey
, bgGrey
- British spelling, uncommon, redundant aliases for gray
and bgGray
blackBright
, bgBlackBright
- Spec-style names for "bright black", less intuitive, rarely used, and awkward in practiceSupporting three separate names for the same color is too much and introduces ambiguity into the API.
Replace deprecated aliases with the preferred standard names:
- ansis.grey('text')
- ansis.blackBright('text')
+ ansis.gray('text')
- ansis.bgGrey('text')
- ansis.bgBlackBright('text')
+ ansis.bgGray('text')
Changelog
4.0.0-beta.19 (2025-04-20)
The unused AnsiColorsExtend
type has been removed.
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.
If you previously used the AnsiColorsExtend
type, you’ll now need to define a custom utility type.
Here's an example how to update your code:
- import ansis, { AnsiColorsExtend } from 'ansis';
+ import ansis, { AnsiColors } from 'ansis';
+ type AnsiColorsExtend<T extends string> = AnsiColors | (T & Record<never, never>);
const myTheme = {
orange: '#FFAB40',
};
// Extend ansis with custom colors
const colors = ansis.extend(myTheme);
// Custom logger supporting both built-in and extended styles
const log = (style: AnsiColorsExtend<keyof typeof myTheme>, message: string) => {
console.log(colors[style](message));
}
log('orange', 'message'); // extended color
This change ensures compatibility with the latest version of Ansis, where AnsiColorsExtend
is no longer available.
Changelog
4.0.0-beta.18 (2025-04-18)
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.
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.
Clear and expressive API
ansis.fg(code)
and ansis.bg(code)
are shorter more elegant than ansis.ansi256(code)
and ansis.bgAnsi256(code)
fg
and bg
clearly describe their purpose: setting foreground and background colorsfg()
and bg()
are already being used in GitHub projectsUpdating from a previous version is simple:
import ansis from 'ansis';
- ansis.ansi256(196)('Error')
+ ansis.fg(196)('Error')
- ansis.bgAnsi256(21)('Info')
+ ansis.bg(21)('Info')
Alternatively, to keep compatibility with existing code:
- import { ansi256, bgAnsi256 } from 'ansis';
+ import { fg as ansi256, bg as bgAnsi256 } from 'ansis';
ansi256(196)('Error')
bgAnsi256(21)('Info')
No other changes are required - everything else remains fully compatible.
Changelog
4.0.0-beta.17 (2025-04-18)
Changelog
4.0.0-beta.16 (2025-04-16)
extend()
methodThe extend()
method has been redesigned for better TypeScript support and flexibility.
extend<U extends string>(colors: Record<U, string | P>): asserts this is Ansis & Record<U, Ansis>;
void
.import ansis from 'ansis';
ansis.extend({ pink: '#FF75D1' });
console.log(ansis.pink('foo'));
import { Ansis } from 'ansis';
const ansis = new Ansis();
ansis.extend({ pink: '#FF75D1' });
console.log(ansis.pink('Hello')); // TS2339: Property 'pink' does not exist
extend<U extends string>(colors: Record<U, string | P>): Ansis & Record<U, Ansis>;
ansis
and new Ansis()
:
import ansis, { Ansis } from 'ansis';
const colors = ansis.extend({ pink: '#FF75D1' });
console.log(colors.pink('foo'));
const custom = new Ansis().extend({ apple: '#4FA83D' });
console.log(custom.apple('bar'));
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:
asserts
version removedextend()
now returns a new instance with extended typesThe new extend()
method now returns an extended instance instead of modifying the original 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 theme = ansis.extend({ pink: '#FF75D1' });
- console.log(ansis.pink('foo'));
+ console.log(theme.pink('foo'));
Or
import { Ansis } from 'ansis';
- ansis.extend({ pink: '#FF75D1' });
+ const ansis = new Ansis().extend({ pink: '#FF75D1' });
console.log(ansis.pink('foo'));
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 custom = new Ansis(0);
console.log(custom.red`foo`); // Output: plain string, no ANSI codes
Use only basic colors:
import { Ansis } from 'ansis';
const custom = new Ansis(1);
console.log(custom.hex('#FFAB40')`Orange`); // Output: fallback to yellowBright
Changelog
4.0.0-beta.14 (2025-04-13)