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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@braebo/ansi

v0.2.0

Published

ANSI code helpers for colorful logging in node.js and chrome.

Readme

@braebo/ansi

ANSI code helpers for colorful logging in node.js and chrome.

  • Hex -> True Color
  • Dynamic colorization
  • Gradients
  • TypeScript / ESM
  • Dependency-free
  • Lightweight
  • Tree shakable

Install

# npm
pnpm i -D @braebo/ansi

# jsr
pnpm dlx jsr add @braebo/ansi

Usage

Hex

Create colors from hex values:

import { ansiHex } from '@braebo/ansi'

const coral = ansiHex('#FF7F50')
console.log(coral('This text will be coral colored'))

Style

Create styles from the ansiStyle function:

import { ansiStyle } from '@braebo/ansi'

const bold = ansiStyle('bold')
console.log(bold('This text will be bold'))

Gradient

Interpolate gradients with any number of colors:

import { ansiGradient } from '@braebo/ansi'

// Create a gradient function.
const g = ansiGradient('#38b2db', '#5959b5', '#e84067')

Now that we have a gradient function, we can pass it a string:

console.log(g('Simple gradient text.'))

Or pass it a number to get a color stop:

const fade = `
${g(0.5)}■■■■■■■■■■■■
${g(0.0)}■■■■■■■■■■■■
${g(0.9)}■■■■■■■■■■■■
${CLEAR}`

console.log(fade)

Mini Methods

Colored logging can quickly become unweildy, so I like to use the mini methods for common colors and styles:

import { l } from '@braebo/ansi' // console.log

import { r, g, b } from '@braebo/ansi' // Colors
import { d, bd, em } from '@braebo/ansi' // Styles

// Colors
l(r('red'))
l(g('green'))
l(b('blue'))

// Styles
l(d('dimmed'))
l(bd('bold'))
l(em('italic'))

If no arguments are provided, the mini methods will return the ANSI code:

console.log(r() + 'red', y() + 'yellow', g() + 'green')

[!NOTE] When no string is provided to a mini method, it won't be wrapped in a corresponding reset code. Use the clear method (clr()) to reset the styles yourself.

logger

The logger function used by the mini methods is somewhat involved, so I decided to expose / document it. It can be used to create your own custom logging functions that colorize input dynamically.

const err = logger({
	prefix: r('| '),
	printWidth: 20,
	fn: (...args: any[]) => {
		console.log(r('>'), r(bd('ERROR')))
		console.log(...args)
	},
})

err('Something went wrong:', { ok: false, cause: '¯\\_(ツ)_/¯' })

LogOptions

The logger function accepts the following options:

printWidth

Controls the expansion of objects and arrays into multiline output.

@default 60

const l = logger({ printWidth: 50 })
l({ foo: true, bar: [1, 'two', { three: () => 3 }] })

[!NOTE] Internally, printWidth is calculated somewhat roughly, so this option is generally a ballpark estimate.

inline

Forces inputs into either inline or multiline output.

@default undefined

const l = logger({ inline: true })
l({ foo: true, bar: [1, 'two', { three: () => 3 }] })

Add __inline__ to an object for a granular overrides.

l({
	one: 1,
	two: 2,
	nested: { __inline__: true, one: 1, two: 2, three: 3 },
})

For array overrides, use the strings __inline__ and __multiline__ to force inline or multiline output.

l([true, 1, 'two', () => 3, '__multiline__'])

delimiter

The delimiter used between rest args.

@default ' '

const l = logger({ delimiter: c(' · ') })
l(true, 1, 'two', () => 3)

prefix

A prefix to prepend to each line (works with multiline output).

@default ''

const l = logger({ prefix: c('⌇ '), delimiter: '' })
l('# ', bd('Header'))
l()
l(d('<p>'), em('Hello, world!'), d('</p>'))

fn

A custom logger function.

@default console.log

const l = logger({ fn: console.warn })
l('E-gad!')

paint()

The paint function used by logger can be used directly to colorize arbitrary input:

console.log(
	paint(
		{
			num: 123,
			bool: true,
			str: 'foo',
			fn: () => 'bar',
		},
		{ inline: false },
	),
)

Why

NIH syndrome / copy-paste fatigue.

License

MIT © braebo