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

vitest-ansi-serializer

v0.4.0

Published

A vitest snapshot serializer which converts ANSI escapes to readable strings.

Readme

vitest-ansi-serializer

This package provides a snapshot serializer to be used with vitest.

It will serialize ANSI escape sequences into human-readable code in strings, to allow for easier reading and diffing of snapshots.

Install

npm i -D vitest-ansi-serializer

Usage

As per the vitest docs, you can use the serializer like so:

import {expect} from 'vitest';
import ansiSerializer from 'vitest-ansi-serializer';

expect.addSnapshotSerializer(ansiSerializer);

Serializing programmatically

This package also exports a serialization utility for use in other testing frameworks:

import test from 'node:test';
import assert from 'node:assert';
import {replaceAnsiCodes} from 'vitest-ansi-serializer';

test('serializes', () => {
  assert.equal(replaceAnsiCodes('\x1B[1mfoo\x1B[22m'), '<bold>foo</bold>');
});

Supported ANSI codes

Escape sequences will be made human readable in snapshots in the form of XML-like tags:

<!-- \x1B[1B -->
<cursor.down count=1>

<!-- \x1B[34mfoo\x1B[39m -->
<blue>foo</fg>

The following ANSI codes are supported:

| Code | Description | Serialization | | ------ | ----------------------- | --------------------- | | ?25l | Cursor hide | <cursor.hide> | | ?25h | Cursor show | <cursor.show> | | 7 | Cursor save position | <cursor.save> | | 8 | Cursor restore position | <cursor.restore> | | A | Cursor up | <cursor.up> | | B | Cursor down | <cursor.down> | | C | Cursor forward | <cursor.forward> | | D | Cursor backward | <cursor.backward> | | E | Cursor next line | <cursor.nextLine> | | F | Cursor previous line | <cursor.prevLine> | | G | Cursor left | <cursor.left> | | H | Cursor to line/column | <cursor.moveTo> | | S | Scroll up | <cursor.scrollUp> | | T | Scroll down | <cursor.scrollDown> |

| Code | Description | Serialization | | --------- | ---------------------- | ------------------- | | 2J | Erase screen | <erase.screen> | | J, 0J | Erase down | <erase.down> | | 1J | Erase up | <erase.up> | | K, 0K | Erase to line end | <erase.lineEnd> | | 1K | Erase to line start | <erase.lineStart> | | 2K | Erase line | <erase.line> | | c | Reset to initial state | <erase.reset> |

Style codes will be serialized as <style> and </style> tags:

<!-- \x1B[1mfoo\x1B[22m and \x1B[4mbar\x1B[24m -->
<bold>foo</bold> and <underline>bar</underline>

Foreground and background colors will be serialized as <color> and <bg:color>. Resets are </fg> and </bg>:

<!-- \x1B[34mfoo\x1B[39m and \x1B[41mbar\x1B[49m -->
<blue>foo</fg> and <bg:red>bar</bg>

The list of all supported colors can be found in codes.ts.

ST- and BEL-terminated links are supported:

<!-- ST: \x1B]8;;https://example.com\x1B\\foo\x1B]8;;\x1B\\ -->
<link url=https://example.com>foo</link>

<!-- BEL: \x1B]8;id=1:foo=bar;file://path/to/file.txt\x07baz\x1B]8;;\x07 -->
<link url=file://path/to/file.txt>baz</link>

See main.test.ts.snap for more examples of what this looks like.

License

MIT