🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

ansis

Package Overview
Dependencies
Maintainers
1
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansis - npm Package Versions

1345
11

4.0.0-beta.21

Diff
webdiscus
published 4.0.0-beta.21 •

Changelog

Source

4.0.0-beta.21 (2025-04-24)

⚠️ BREAKING CHANGE

  • 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
webdiscus
published 3.18.0-beta.0 •

Changelog

Source

3.18.0-beta.0 (2025-04-22)

  • feat: drop support for Deno 1.x (EOL) and add support for Deno 2.0+, #37
  • test: add Deno tests on GitHub
webdiscus
published 4.0.0-beta.20 •

Changelog

Source

4.0.0-beta.20 (2025-04-21)

⚠️ BREAKING CHANGE

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 practice

Supporting three separate names for the same color is too much and introduces ambiguity into the API.

Migrating

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')
webdiscus
published 4.0.0-beta.19 •

Changelog

Source

4.0.0-beta.19 (2025-04-20)

⚠️ BREAKING CHANGE

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.

Migrating

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.

webdiscus
published 4.0.0-beta.18 •

Changelog

Source

4.0.0-beta.18 (2025-04-18)

⚠️ BREAKING CHANGE (if 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.

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 colors
  • These method names align with conventions used by many other color libraries
  • Introduced in 2021-12-29, fg() and bg() are already being used in GitHub projects
  • Removing duplicates makes the API cleaner and more compact

Migrating

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.

webdiscus
published 4.0.0-beta.17 •

Changelog

Source

4.0.0-beta.17 (2025-04-18)

  • feat: refactor .d.ts and reduce the package size
webdiscus
published 4.0.0-beta.16 •

Changelog

Source

4.0.0-beta.16 (2025-04-16)

⚠️ BREAKING CHANGE: 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 | 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
    

New behavior:

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 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'));
    

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:

  • asserts version removed
  • extend() now returns a new instance with extended types
  • Cleaner, safer, and fully compatible with all usage patterns

Migrating

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'));

Features

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 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
webdiscus
published 4.0.0-beta.15 •
webdiscus
published 4.0.0-beta.14 •

Changelog

Source

4.0.0-beta.14 (2025-04-13)

  • feat: reduce size of index.d.ts file
webdiscus
published 4.0.0-beta.13 •

Changelog

Source

4.0.0-beta.13 (2025-04-12)

  • feat: reduce the package size