- feat: add support named truecolor via
ansis.extend(). Foreground methods are created from the provided color names, and matching background methodsbg*are generated automatically. Example:This release removes the last barrier for projects migrating from Chalk v4 that used named truecolor, e.g.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"
chalk.keyword('orange')('text'). Ansis now provides this feature with a simpler, more intuitive API.
- feat: add readonly
levelproperty to get the detected color support level:- 0 - no colors,
- 1 - 16 colors,
- 2 - 256 colors,
- 3 - truecolor.
Release v4.
Ansis v4 drops legacy baggage and unused artifacts. This release brings a stable and more compact ANSI library. v4.0.0 is 12.4% smaller than v3.17.0.
- feat: drop support for Deno 1.x (EOL - 9 Oct 2024) and add support for Deno 2.0+, #37 Backported from 3.18.0-beta.0
Removed unused and rarely used aliases for gray and bgGray:
grey,bgGrey- British spelling, uncommon, redundant aliases forgrayandbgGrayblackBright,bgBlackBright- Spec-style names for "bright black", less intuitive, rarely used, and awkward in practice
Supporting 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')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 colorThis change ensures compatibility with the latest version of Ansis, where AnsiColorsExtend is no longer available.
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.
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)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 in 2021-12-29,
fg()andbg()are already being used in GitHub projects - Removing duplicates makes the API cleaner and more compact
Updating 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.
- feat: refactor .d.ts and reduce the package size
The 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>;- 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' }); console.log(ansis.pink('Hello')); // TS2339: Property 'pink' does not exist
extend<U extends string>(colors: Record<U, string | P>): Ansis & Record<U, Ansis>;- Returns a new extended instance with full type support.
- ✅ Works with both
ansisandnew 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:
assertsversion removedextend()now returns a new instance with extended types- Cleaner, safer, and fully compatible with all usage patterns
The 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 codesUse only basic colors:
import { Ansis } from 'ansis';
const custom = new Ansis(1);
console.log(custom.hex('#FFAB40')`Orange`); // Output: fallback to yellowBright- feat: reduce size of index.d.ts file
- feat: reduce the package size
- feat: slightly improve performance for hex function
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-directby default. Modern terminals, including KDE Konsole, typically useTERM=xterm-256coloralong withCOLORTERM=truecolorto indicate truecolor 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
fg(),hex()orrgb(). To explicitly enable truecolor, set the environment variableCOLORTERM=24bitorFORCE_COLOR=3.
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.
If you're using strike style, replace it with strikethrough.
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
Deprecated.
- feat: drop support for Deno 1.x (EOL - 9 Oct 2024) and add support for Deno 2.0+, #37
- test: add Deno tests on GitHub
- feat: add support for
typescript<5.6to fix TS2526 error:NOTE: If you are already using TypeScript >= 5.6, this update is not required.A 'this' type is available only in a non-static member of a class or interface.
- chore: after testing bump version to release version 3.16.0
- chore: revert the full text of ISC license from https://opensource.org/license/isc-license-txt
- refactor: micro optimisations for named exports to slight reduce the package size by ~40 bytes.
- feat: reduce the package size by ~200 bytes.
- refactor: invisible micro optimisations.
- chore: after testing in many projects bump v3.15.0-beta.2 to release v3.15.0.
- chore: update dev dependencies.
- test: add tests for
tsupbundler.
- refactor: slight reduce the package size
- feat: remove "main" from package.json, since Ansis is a dual package using "exports".
Note:- requires Node >= v12.7.0 to support "exports".
- npm does not require "main" for publishing a package.
- Node.js prioritizes "exports" over "main" when resolving modules.
- Modern bundlers and tools (like Webpack, Rollup, and TypeScript) also use "exports".
- docs: add to README the Compatibility Check for tools and browsers.
- feat: reduce the package size by ~100 bytes
- refactor: invisible micro optimisations
- feat: add support for chromium-based browsers.
Now you can use truecolor in the consoles of Chrome, Edge, Brave, and other Chromium-based browsers. Browsers that do not support ANSI codes will display black and white text. - refactor: slight reduce the package size by ~40 bytes.
Skip this version number.
- feat: add support for
\nas a newline in template literals, e.g.:green`Hello\nWorld`renders:Hello World
- feat: add support for legacy Node.js v14 (in package.json for npm was changed the
enginesto"node": ">=14") - test: add test in GitHub workflow for legacy Node.js versions: 14, 16
- chore: update dev dependencies
- feat:
ansis.reset()returns the reset escape code\e[0m - feat: micro optimisations for slight performance improvements
- chore: code cleanup
- docs: update readme
- refactor: invisible code improvements
- chore: add benchmark for long text
- docs: improve readme
- feat: revert handling of
nullandundefinedvalues to empty string as beforev3.7.0, #25
- refactor: optimize package size
-
feat: 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
-
fix: 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
-
refactor: optimize code by size
- fix: cast falsy values
false,null,undefined,NaNto a string. In previous versions, the empty string''was returned for falsy values. - fix: functions with argument
0, e.g.ansis.red(0), returning empty string'', now return colored value'0' - test: add tests for function arguments with various types
- feat: remove 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.
- chore: update license to current date
- fix: TS2339: Property 'strip' does not exist on type when the TS compiler option
moduleisnode16 - refactor: optimize index.d.ts to reduce package size from 7.3 kB to 7.0 kB
- refactor: invisible code optimisation
- refactor: optimise npm package to reduce size by 3 kB, from 10.3 kB to 7.3 kB
- feat: add support the
COLORTERMvariable for values:truecolor,24bit,ansi256,ansi(16 colors) - feat: add support the
xterm-directterminal to detect the truecolor - fix: remove detection environment variable
GPG_TTYintroduced in3.5.0-beta.0version, because it make no sense - fix: default import in TypeScript, compiled with
tsc:import ansis from 'ansis'now works so well asimport * as ansis from 'ansis'
- refactor: optimise npm package to reduce the size
- chore: update benchmarks with newest version
- test: add more use cases
- feat: detect
xterm-directterminal as supported the truecolor - feat: add support the
COLORTERMvariable for values:truecolor,24bit,ansi256,ansi(16 colors) - docs: update readme for using
COLORTERMwith examples
- docs: remove badges in readme for npm package to reduce package size
- docs: fix badge urls in readme for npm package
- refactor: optimise npm package to reduce the size by ~0.5 kB, from 8.0 kB to 7.5 kB
- test: fix swc configuration for compiling into CJS
- test: fix handling line endings on windows
- refactor: optimise npm package to reduce the size by ~1 kB, from 8.9 kB to 8.0 kB
- feat: add support environment variable
GPG_TTYto detect it asisTTY. NOTE: in release v3.5.1 was removed as needles. - fix: default import in TypeScript, compiled with
tsc:import ansis from 'ansis'now works so well asimport * as ansis from 'ansis' - refactor: optimise npm package to reduce size by ~1.3 kB, from 10.3 kB to 8.9 kB
- refactor: optimize index.d.ts, remove insignificant spaces and words, use the
typewith dynamic properties instead of theinterface - test: add integration tests to execute compiled TypeScript and compare outputs with expected strings
- test: add tests for
tsc,swcandesbuildcompilers
- refactor: optimise npm package to reduce size by ~1 KB, from 11.3 kB to 10.3 kB
- fix: url to GitHub in readme for npm package
- refactor: invisible code optimisations
- refactor: optimize readme for npm package to save ~400 bytes
- refactor: optimize index.d.ts for npm package to save ~500 bytes
- test: refactor benchmark tests
- test: add new representative benchmark tests for using 1, 2, 3 and 4 styles
- test: add picocolors complex benchmark test
- docs: update readme
- fix: correct detect TTY on Windows platform
- chore: optimize code to reduce the size by ~50 bytes
- chore: add benchmarks for
koloristpackage - test: add test matrix for windows on GitHub
- docs: add compare the size of most popular packages
- chore: optimize code to reduce the size by ~600 bytes,
- chore: minify
index.d.tsto reduce the size by ~200 bytes, - chore: increase performance, e.g. using chained styles, 70.000.000 -> 80.000.000 ops/sec
- feat(BREAKING CHANGE): remove
oldnamed import DEPRECATED inv2.0.0(2023-11-03). If you update the package fromv1.xtov3.3.0then check your code:
ESMCJS- import { red } from 'ansis/colors'; + import { red } from 'ansis';
- const { red } = require('ansis/colors'); + const { red } = require('ansis');
- chore: cleanup/optimize
package.jsonfor npm package
- chore: reduce unpacked size by ~ 1 KB
- docs: optimize README for NPM
- feat: add
ansis.isSupported()method to detect color support
- fix: interpret FORCE_COLOR=false or FORCE_COLOR=0 as force disable colors
others values, e.g., FORCE_COLOR=true or FORCE_COLOR=1 - force enable colors.
See https://force-color.org.
- feat: add detection of color support when using PM2 process manager
- chore: add rollup-plugin-cleanup to remove comments from d.ts file for dist, that save yet 3 KB
- chore: update license year
- chore: create mini version of README for NPM to minify package size
- docs: update readme
- refactor: improve code
- chore: reduce code bundle size from 3.8 KB to 3.4 KB
- chore: update benchmark
- chore: update compare tests
- test: add more tests
- docs: improve readme
- feat: add detection of color levels support: TrueColor, 256 colors, 16 colors, no color
- feat: add fallback for supported color space: truecolor —> 256 colors —> 16 colors —> no colors
- perform: improve performance for
hex()function - chore: size increased from 3.2 KB to 3.8 KB as new features were added
- test: switch from jest to vitest
- test: add tests for new features
- docs: update readme for color levels support
In the new major version 3.x are removed unused styles and methods.
⚠️ WarningBefore update, please check your code whether is used deleted styles and methods.
Drop supports for Node <= 14. Minimal supported version is 15.0.0 (Released 2020-10-20).
In the theory the v3 can works with Node12, but we can't test it.
ESM
- import { red } from 'ansis/colors';
+ import { red } from 'ansis';CJS
- const { red } = require('ansis/colors');
+ const { red } = require('ansis');The not widely supported styles are deleted:
faint(alias for dim), replace in your code withdimdoubleUnderline, replace in your code withunderlineframe, replace in your code withunderlineencircle, replace in your code withunderlineoverline, replace in your code withunderline
The methods are deleted:
ansi, replace in your code withfgbgAnsi, replace in your code withbg
The clamp (0, 255) for the ANSI 256 codes and RGB values is removed, because is unused. You should self check the function arguments.
The affected functions:
fg- expected a code in the range0 - 255bg- expected a code in the range0 - 255rgb- expected r, g, b values in the range0 - 255bgRgb- expected r, g, b values in the range0 - 255
- feat: add detection of additional terminals, thanks @dse, colors.js:issue #42
- test: add test to detect various terminals
- feat: add supports the argument as
number - test: add tests for new feature
- chore: add features compare of different libs, just run:
npm run compare - chore: add compare example on stackblitz
- docs: update readme
- feat: add
bgGreyandbgGrayaliases forbgBlackBright - refactor: optimize source code
- test: refactor tests
- docs: update readme
- fix(index.d.ts): use function overload to make the tagged template have the correct type, #16
- fix: could not find a declaration file for module 'ansis'
- fix: missing exports of ansis.strip() and ansis.export() functions (issue was introduced in v2.0.0)
- refactor: optimize code to reduce distributed size
- test: add test for generated npm package in CJS and ESM mode
- test: add test for env variables and CLI flags
- test: add test to detect Deno
- test: add test to detect Next.js runtime
- docs: update readme
- feat: add supports the Deno
- feat: add supports the Next.js
edgeruntime - feat(CHANGE): add named import for
ansis:
NEW named import:import { red } from 'ansis'.
If you useTypeScriptand your IDE show the error:TS2307: Cannot find module ansis/colors,
then you should use the new syntax, update you code:import { red } from 'ansis/colors'-->import { red } from 'ansis'. - feat(DEPRECATE): OLD named import
import { red } from 'ansis/colors'is deprecated, use the NEW named import - feat(DEPRECATE): instead of the
ansiusefg - feat(DEPRECATE): instead of the
bgAnsiusebg - feat: optimize named export
- feat: reduce the size of dist/ directory
- chore: update dev dependencies, new jest requires node.js >= 14
- feat: add supports the Deno
- feat: add supports the Next.js
edgeruntime - test: add tests for isSupported() function
- chore: update dev dependencies
- chore: update dev dependencies
- chore: add SECURITY.md
- chore: add PULL_REQUEST_TEMPLATE.md
- chore: update ISSUE_TEMPLATE
- docs: update readme
- refactor: optimize code to reduce size by 120 bytes
- test: add test for isSupported() function
- docs: update readme, add example screenshots
- fix: visible style with nested template strings
- fix: set correct aliases for bgAnsi and fg methods by named export
- chore: refactor examples
- docs: update readme
- fix: regard the value of the environment variable FORCE_COLOR=0 to force disable colors
- test: add tests for FORCE_COLOR
- docs: update readme
- fix: add missing export for CJS mode in package.json
- test: add manual tests for CJS and ESM mode
- DEPRECATE v1.5.0, because missing exports main for CJS mode, fixed in v1.5.1
- feat: add supports the nested template literal syntax:
console.log(red`red ${yellow`yellow ${green`green`} yellow`} red`)
- feat: add named export of colors with supports for chained syntax:
import { red, green, yellow } from 'ansis/colors'; console.log(red.bold.underline`text`);
- feat: add extending of base colors with named custom truecolor
import ansis from 'ansis'; ansis.extend({ orange: '#FFAB40' }); console.log(ansis.orange.bold('text'));
- fix: corrected declarations in
index.d.ts - chore: add
AnsiStyles,AnsiColorsand AnsiColorsExtend types inindex.d.ts - refactor: optimize size of distributed bundle from 3.7KB to 3.1KB
- docs: add usage in CLI
- feat: add method strip() to remove all ANSI codes from string
- build: properly generated distribution package, bump to last stable version 1.3.6
- chore: update dev packages
- DEPRECATED: this version is broken
- feat: optimize distributed code size to smaller than
4 KB
- feat: add UK spelling alias
greyforgray - chore: update dev dependencies
- docs: update readme
- feat: add bundle generation for ESM
- build: auto generate bundles for ESM and CommonJS at npm publish
- fix: usage for CommonJS:
const ansis = require('ansis').default;-->const ansis = require('ansis');
- feat: add support CommonJS (now supported ESM and CommonJS)
- feat: add aliases:
.fg()for.ansi256()and.bg()for.bgAnsi256()methods. DEPRECATED methods:ansi,ansi256,bgAnsi,bgAnsi256- usefgandbginstead. - fix: some inner param types
- chore: remove examples from NPM package (it can be cloned und run local)
- fix: the path of examples in package.json
- chore: add demo examples of all features
- docs: update readme
- feat: add supports the environment variables
NO_COLORFORCE_COLORand flags--no-color--color - feat: add aliases
ansiforansi256andbgAnsiforbgAnsi256 - docs: add to readme the compare of most popular ANSI libraries
- feat: add the class Ansis to create more independent instances to increase the performance by benchmark
- feat: improve performance
- refactor: code refactoring
- docs: update readme
- feat: add supports the use of
openandcloseproperties for each style - fix: codes for methods ansi256() and bgAnsi256()
- chore: added demo to npm package
- chore: update package.json
- docs: update readme
First release