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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kristoferbaxter/kleur

v4.0.2

Published

The fastest Node.js library for formatting terminal text with ANSI colors~!

Downloads

1,742

Readme

Features


As of v3.0 the Chalk-style syntax (magical getter) is no longer used.If you need or require that syntax, consider using ansi-colors, which maintains chalk parity.


Install

$ npm install --save kleur

Usage

import { red, white, blue, bold } from 'kleur';

// basic usage
red('red text');

// chained methods
blue().bold().underline('howdy partner');

// nested methods
bold(`${ white().bgRed('[ERROR]') } ${ red().italic('Something happened')}`);

Chained Methods

console.log(bold().red('this is a bold red message'));
console.log(bold().italic('this is a bold italicized message'));
console.log(bold().yellow().bgRed().italic('this is a bold yellow italicized message'));
console.log(green().bold().underline('this is a bold green underlined message'));

Nested Methods

import { yellow, red, cyan } from 'kleur';

console.log(yellow(`foo ${red().bold('red')} bar ${cyan('cyan')} baz`));
console.log(yellow('foo ' + red().bold('red') + ' bar ' + cyan('cyan') + ' baz'));

Conditional Support

Toggle color support as needed; kleur includes simple auto-detection which may not cover all cases.

import kleur from 'kleur';

// disable with boolean result of right side assignment.
kleur.enabled = false;

console.log(kleur.red('I will only be colored red if the terminal supports colors'));

API

Any kleur method returns a String when invoked with input; otherwise chaining is expected.

It's up to the developer to pass the output to destinations like console.log, process.stdout.write, etc.

The methods below are grouped by type for legibility purposes only. They each can be chained or nested with one another.

Colors:

black — red — green — yellow — blue — magenta — cyan — white — gray — grey

Backgrounds:

bgBlack — bgRed — bgGreen — bgYellow — bgBlue — bgMagenta — bgCyan — bgWhite

Modifiers:

reset — bold — dim — italic* — underline — inverse — hidden — strikethrough*

* Not widely supported

Benchmarks

Using Node v10.13.0

Load time

chalk       ::  4.858ms
kleur       ::  0.482ms
ansi-colors ::  1.738ms

Performance

# All Colors
  ansi-colors  x 182,395 ops/sec ±0.51% (96 runs sampled)
  chalk        x 656,387 ops/sec ±0.80% (93 runs sampled)
  kleur        x 711,729 ops/sec ±0.33% (94 runs sampled)

# Stacked colors
  ansi-colors  x  23,900 ops/sec ±0.34% (92 runs sampled)
  chalk        x 306,865 ops/sec ±0.32% (97 runs sampled)
  kleur        x  76,154 ops/sec ±0.29% (95 runs sampled)

# Nested colors
  ansi-colors  x  69,508 ops/sec ±0.29% (95 runs sampled)
  chalk        x 124,142 ops/sec ±0.43% (91 runs sampled)
  kleur        x 138,659 ops/sec ±0.32% (98 runs sampled)

Credits

This project originally forked Brian Woodward's awesome ansi-colors library.

Beginning with [email protected], the Chalk-style syntax (magical getter) has been replaced with function calls per key:

// Old:
c.red.bold.underline('old');

// New:
c.red().bold().underline('new');

As I work more with Rust, the newer syntax feels so much better & more natural!

If you prefer the old syntax, you may migrate to ansi-colors. Versions below [email protected] have been deprecated.

License

MIT © Luke Edwards