npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@munesoft/ansix

v1.204.11

Published

The modern ANSI and terminal toolkit for Node.js and browser.

Readme

@munesoft/ansix

version tests dependencies license node types

The modern ANSI and terminal toolkit for Node.js and browser.
Replace multiple CLI dependencies with one fast, unified library.

npm install @munesoft/ansix

Why ansix?

Most CLI tools depend on a chain of small packages:

  • ansi-regex — detect/match ANSI sequences
  • strip-ansi — remove ANSI codes
  • supports-color — detect terminal color support
  • string-width — measure display width
  • cli-truncate — truncate to width
  • wrap-ansi — word-wrap to columns

ansix replaces all of them with a single, modern, zero-dependency package.


Features

| Feature | ansix | |---|---| | ANSI detection & stripping | ✅ | | Terminal capability detection | ✅ | | Named, 256-palette, RGB, and HEX colors | ✅ | | Text styles (bold, italic, underline, …) | ✅ | | ANSI-safe width calculation | ✅ | | Wide character & emoji support | ✅ | | Text truncation (ANSI-aware) | ✅ | | Text wrapping (ANSI-aware) | ✅ | | Cursor control sequences | ✅ | | Safe output (auto-strip when unsupported) | ✅ | | OSC 8 terminal hyperlinks | ✅ | | Token-based parser | ✅ | | Transform pipelines | ✅ | | TypeScript types | ✅ | | ESM + CommonJS dual package | ✅ | | Browser compatible | ✅ | | Zero dependencies | ✅ |


Quick Start

// ESM
import ansix from '@munesoft/ansix';

// CommonJS
const ansix = require('@munesoft/ansix');

ansix.strip('\x1b[31mHello\x1b[0m');
// => 'Hello'

Named imports also work:

import { strip, color, width, truncate } from '@munesoft/ansix';

API

ANSI Detection & Stripping

ansix.has('\x1b[31mHello\x1b[0m')  // => true
ansix.has('plain text')             // => false

ansix.strip('\x1b[1m\x1b[32mBold Green\x1b[0m')  // => 'Bold Green'

Terminal Capability Detection

const cap = ansix.supports();
// {
//   level: 'truecolor' | '256' | 'basic' | 'none',
//   hasBasic: true,
//   has256: true,
//   hasTruecolor: true,
//   isBrowser: false
// }

ansix.supportsColor()  // => true / false

Respects NO_COLOR, FORCE_COLOR, COLORTERM, TERM_PROGRAM, and CI environment variables.

Color Formatting

Named colors:

ansix.color('red', 'Error!')
ansix.color('green', 'Success')
ansix.color('cyan', 'Info')
ansix.bgColor('blue', 'highlighted')

Available names: black, red, green, yellow, blue, magenta, cyan, white, gray, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite

Text styles:

ansix.style('bold', 'Title')
ansix.style('italic', 'note')
ansix.style('underline', 'link')
ansix.style('strikethrough', 'deleted')

256-palette:

ansix.color256(200, 'pink text')
ansix.bgColor256(100, 'colored background')

Truecolor RGB:

ansix.rgb(255, 100, 0, 'orange text')
ansix.bgRgb(0, 0, 128, 'navy background')

HEX:

ansix.hex('#ff6600', 'link text')
ansix.bgHex('#1a1a2e', 'dark background')

Width Calculation

ANSI-safe, handles CJK wide characters and emoji:

ansix.width('Hello')                         // => 5
ansix.width('\x1b[31mHello\x1b[0m')          // => 5 (ignores ANSI)
ansix.width('你好')                           // => 4 (wide chars = 2 each)
ansix.width('🚀')                             // => 2

Truncation

ansix.truncate('Hello World', 8)
// => 'Hello W…'

ansix.truncate('\x1b[31mHello World\x1b[0m', 8)
// => '\x1b[31mHello W\x1b[0m…'  (ANSI codes preserved)

ansix.truncate('Hello World', 8, { ellipsis: '...' })
// => 'Hello...'

Wrapping

ansix.wrap('Hello World Foo Bar Baz', 10)
// => 'Hello\nWorld Foo\nBar Baz'

ansix.wrap(text, 40, { hard: true })   // break mid-word if needed
ansix.wrap(text, 40, { trim: false })  // keep leading whitespace

Cursor Control

All cursor functions return escape strings — write them to process.stdout:

process.stdout.write(ansix.cursor.hide())
process.stdout.write(ansix.cursor.show())
process.stdout.write(ansix.cursor.up(2))
process.stdout.write(ansix.cursor.moveTo(5, 1))
process.stdout.write(ansix.cursor.clearLine())
process.stdout.write(ansix.cursor.enterAltScreen())
process.stdout.write(ansix.cursor.exitAltScreen())

// Or use the convenience writer (Node.js only):
ansix.cursor.write(ansix.cursor.hide())

Full list: hide, show, up, down, forward, backward, nextLine, prevLine, column, moveTo, save, restore, clearScreen, clearScreenDown, clearScreenUp, clearLine, clearLineRight, clearLineLeft, scrollUp, scrollDown, enterAltScreen, exitAltScreen

Safe Output

Automatically strips ANSI codes when the terminal or environment doesn't support them:

process.stdout.write(ansix.safe(ansix.color('green', 'text')))
// In color terminals: outputs colored text
// In dumb terminals / NO_COLOR / browser: outputs plain 'text'

Hyperlinks

OSC 8 terminal hyperlinks (iTerm2, Kitty, WezTerm, VTE, etc.):

ansix.link('Click here', 'https://example.com')
// In supporting terminals: clickable hyperlink
// In others: falls back to plain text

ansix.link('Click here', 'https://example.com', { force: true })
// Always emit the OSC 8 sequence

Token Parser & Transform Pipelines

Parse a string into text and ANSI tokens:

const tokens = ansix.parse('\x1b[31mHello\x1b[0m World');
// [
//   { type: 'ansi', value: '\x1b[31m', kind: 'sgr' },
//   { type: 'text', value: 'Hello' },
//   { type: 'ansi', value: '\x1b[0m', kind: 'sgr' },
//   { type: 'text', value: ' World' }
// ]

ansix.stringify(tokens)  // reconstruct original string

Build transform pipelines:

// Strip all ANSI
const stripAll = ansix.pipeline(ansix.stripTransform);
stripAll('\x1b[31mHello\x1b[0m')  // => 'Hello'

// Strip colors only, keep cursor sequences
const stripColors = ansix.pipeline(ansix.stripColorsTransform);

// Uppercase text content, preserve ANSI codes
const upper = ansix.pipeline(ansix.mapText(t => t.toUpperCase()));
upper('\x1b[31mhello\x1b[0m')  // => '\x1b[31mHELLO\x1b[0m'

// Chain transforms
const process = ansix.pipeline(
  ansix.mapText(t => t.toUpperCase()),
  ansix.stripColorsTransform
);

Regex Utilities

ansix.ansiRegex()       // /[all ANSI sequences]/g
ansix.sgrRegex()        // /\x1b\[[\d;]*m/g  (colors/styles only)
ansix.hyperlinkRegex()  // OSC 8 hyperlink sequences

Browser Support

ansix is fully browser compatible. supports() detects browser environments and returns { level: 'basic', isBrowser: true }. safe() and strip() work as expected for stripping ANSI from strings in non-terminal contexts.


License

MIT