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

@ramstack/chromalog

v1.1.0

Published

A small and simple library for log highlighting before printing text to the terminal

Readme

@ramstack/chromalog

NPM MIT

A small and simple library for log highlighting before printing text to the terminal.

screenshot

Installation

npm install @ramstack/chromalog

Basic usage

The simplest case is using the built-in rules.

import { highlight } from "@ramstack/chromalog";

console.log(
  highlight("INFO 2024-01-31 12:45:10 User logged in")
);

By default, @ramstack/chromalog highlights:

  • dates and times
  • ISO date-time strings
  • numbers
  • strings (single and double quoted)
  • IPv4 addresses
  • GUID / UUID values
  • common keywords (log levels, HTTP methods, booleans)
  • Unix and Windows paths
  • Unix process names

Using custom rules

You can fully control what gets highlighted by passing your own rules.

import {
  createNumberHighlighter,
  createStringHighlighter,
  highlight
} from "@ramstack/chromalog";

const rules = [
  createNumberHighlighter(),
  createStringHighlighter()
];

console.log(
  highlight("value=42 name='test'", rules)
);

If rules are provided, the default rules are not used.

Customizing colors

Each highlighter accepts an optional apply function. It receives the matched text and must return a string.

Example with picocolors:

import pc from "picocolors";
import {
  highlight,
  createNumberHighlighter
} from "@ramstack/chromalog";

const rules = [
  createNumberHighlighter(value => pc.bgYellow(pc.black(value)))
];

console.log(highlight("price=199", rules));

You can use any coloring library or return plain text if needed.

Writing your own highlighter

A highlighter is just an object with three fields:

  • regex — global regular expression
  • apply — function that transforms the match
  • order (optional) — conflict priority

Simple example

import pc from "picocolors";
import { highlight } from "@ramstack/chromalog";

const errorCodeHighlighter = {
  regex: /E\d{3}/g,
  apply: (value: string) => pc.red(value)
};

console.log(
  highlight("Error E404 occurred", [errorCodeHighlighter])
);

Rule priority (order)

Sometimes multiple rules can match the same fragment of text.

In such cases:

  1. Matches earlier in the string win
  2. Longer matches win over shorter ones
  3. If both are equal, order is used

Lower order values have higher priority.

Example:

const ruleA = { regex: /abc/g, apply: () => "A", order: 0 };
const ruleB = { regex: /abc/g, apply: () => "B", order: 5 };

ruleA will be applied.

Color support

@ramstack/chromalog respects terminal color support automatically.

Colors are disabled when:

  • the terminal does not support colors
  • Node.js is started with --no-color
  • NO_COLOR environment variable is set

In these cases, the original text is returned without any modifications.

Colors can be forced when:

  • Node.js is started with --color
  • FORCE_COLOR=true environment variable is set

This behavior follows standard Node.js and ecosystem conventions.

Notes

[!NOTE]

  • This package is Node.js only.
  • Regular expressions must use the global (/g) flag.
  • For performance reasons, built-in highlighters do not validate values. They only match patterns and intentionally use simple regular expressions.

Contributions

Bug reports and contributions are welcome.

License

This package is released as open source under the MIT License. See the LICENSE file for more details.