ansis
4.5.0 · 1 Nov 2026ISC56.7M / weekRepositoryHomepagenpmAtom feed
4.5.0 is the newest release of 4.x.
Release note
Bug fixes
1. reset no longer appends a closing sequence
Important
reset is now a single SGR command, not a paired open/close style. ansis.reset(value) prepends \x1b[0m and no longer appends a closing reset. If your code or snapshot tests relied on the trailing \x1b[0m, update them or add the reset explicitly (see below).
Before, reset was treated like any other style with an open and a close code, so it wrapped the value on both sides. That produced extra reset sequences in chained, nested, template literal, and multiline compositions, and the output did not match what a single reset should do.
Before:
ansis.reset('foo');
// "\x1b[0mfoo\x1b[0m"Now:
ansis.reset('foo');
// "\x1b[0mfoo"If you need a trailing reset, add it explicitly:
ansis.reset`foo ${ansis.red('bar')} baz` + ansis.reset();
// "\x1b[0mfoo \x1b[31mbar\x1b[39m baz\x1b[0m"ansis.reset() without argument returns just the reset code \x1b[0m, which makes appending it easy.
2. strip() removes OSC 8 hyperlink sequences
strip() did not clear the OSC 8 sequences produced by link().
It now removes them and returns plain text:
ansis.strip(ansis.link('https://example.com', 'text'));
// "text"3. No style leakage between instances with different color levels
Styles created on one Ansis instance could appear on another instance that was created with a different color level. That could give output rendered at the wrong color level.
Now, instances are isolated, so each one keeps its own styles and level.
import { Ansis } from 'ansis';
const noColor = new Ansis(0);
const color = new Ansis(1);
// Fixed: chained styles on `noColor` stay unstyled.
noColor.red.bold('foo');
// -> 'foo'
// Reference: a colored instance still renders the same chain with ANSI styles.
color.red.bold('foo');
// -> '\x1b[31m\x1b[1mfoo\x1b[22m\x1b[39m'4. .extend() no longer affects other instances
Calling .extend() on one instance could override styles on other instances that use a different color level.
Now, the .extend() method stays local to the instance on which it is called.
import { Ansis } from 'ansis';
const trueColor = new Ansis(3);
const noColor = new Ansis(0);
trueColor.extend({
pink: '#ff69b4',
});
// Fixed: `extend()` stays local to `trueColor`.
trueColor.red('foo');
// -> '\x1b[31mfoo\x1b[39m'
// Fixed: extending `trueColor` does not leak styles or color level into `noColor`.
noColor.red('foo');
// -> 'foo'