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

forkcolours

v0.0.3

Published

4x times faster than chalk and use 5x less space in node_modules

Downloads

29

Readme

Fork Colours

A brand new, not another, special and fast Node.js library to ANSI colors to terminal output.

Started as a fork of @ai's nanocolors, which is a fork of @jorgebucaran’s colorette with hacks from @lukeed’s kleur.

Key features:

  • This library was inspired by many other unique libraries
  • It is faster than alternatives
  • It is British friendly: Tiny Colours not Colors
  • It is a fork of fork
  • It is one-liner program
  • Total files: 7
  • Package size: 4.6 kB
  • Unpacked size: 14.9 kB

Also:

  • It is 4 times faster than chalk for simple use cases.
  • No dependencies. It takes 5 times less space in node_modules than chalk.
  • Auto-detects color support. You can also toggle color mode manually.
  • Tree-shakable. We use a dual [ESM]/[CJS] package.
  • Supports Node.js ≥ 6 and universal Node.js/browser projects.
import { green, bold } from 'forkcolours'

console.log(
  green(`Task ${bold('1')} was finished`)
)

Inspired by

Real-time Benchmarks

Simple

Run node test/simple-benchmark.js
  chalk 27,865,695 ops/sec
  cli-color 320,071 ops/sec
  ansi-colors 1,454,343 ops/sec
  kleur 69,030,393 ops/sec
  kleur/colors 61,530,806 ops/sec
  felt-pen 21,725,908 ops/sec
  colorette 18,321,149 ops/sec
  nanocolors 7,978,665 ops/sec
  forkcolours 18,935,821 ops/sec 🚀

Complex

Run node test/complex-benchmark.js
  chalk 7,265,255 ops/sec
  cli-color 216,698 ops/sec
  ansi-colors 610,524 ops/sec
  kleur 11,316,157 ops/sec
  kleur/colors 11,019,217 ops/sec
  felt-pen 7,388,171 ops/sec
  colorette 1,487,709 ops/sec
  nanocolors 1,463,641 ops/sec
  forkcolours 1,537,279 ops/sec 🚀

Loading

Run node test/loading.cjs
  chalk 8.838 ms
  cli-color 47.355 ms
  ansi-colors 4.199 ms
  kleur 5.217 ms
  kleur/colors 1.824 ms
  felt-pen 0.715 ms
  colorette 1.515 ms
  nanocolors 0.917 ms
  forkcolours 0.763 ms 🚀

Size

Run node test/size.js
  chalk 101 kB
  cli-color 1249 kB
  ansi-colors 25 kB
  kleur 21 kB
  felt-pen 10 kB
  colorette 16 kB
  nanocolors 16 kB
  forkcolours 16 kB 🚀

Colorette

  Run node test/colorette-benchmark.js
  chalk × 6,570,253 ops/sec
  kleur × 10,115,512 ops/sec
  ansi-colors × 202,788 ops/sec
  colorette × 459,384 ops/sec
  nanocolors × 435,993 ops/sec
  forkcolours × 469,867 ops/sec 🚀

Replacing chalk

  1. Replace import and use named exports:

    - import chalk from 'chalk'
    + import { red, bold } from 'forkcolours'
  2. Unprefix calls:

    - chalk.red(text)
    + red(text)
  3. Replace chains to nested calls:

    - chalk.red.bold(text)
    + red(bold(text))

API

Individual Colors

Fork Colours exports functions:

| Colors | Background Colors | Modifiers | | --------- | ------------------- | ----------------- | | black | bgBlack | dim | | red | bgRed | bold | | green | bgGreen | hidden | | yellow | bgYellow | italic | | blue | bgBlue | underline | | magenta | bgMagenta | ~~strikethrough~~ | | cyan | bgCyan | reset | | white | bgWhite | | | gray | | |

Functions are not chainable. You need to wrap it inside each other:

import { black, bgYellow } from 'forkcolours'

console.log(bgYellow(black(' WARN ')))

Functions will use colors only if Fork Colours auto-detect that current environment supports colors.

You can get support level in isColorSupported:

import { isColorSupported } from 'forkcolours'

if (isColorSupported) {
  console.log('With colors')
}

Conditional Support

You can manually switch colors on/off and override color support auto-detection:

import { createColors } from 'forkcolours'

const { red } = createColors(options.enableColors)

On undefined argument, createColors will use value from color support auto-detection.