Skip to content
/ colors Public

🎨 The tiniest and the fastest library for terminal output formatting with ANSI colors

License

Notifications You must be signed in to change notification settings

esmkit/colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@esmkit/colors

The tiniest and the fastest library for terminal output formatting with ANSI colors

  • No dependencies.
  • Node.js v6+ & browsers support. Support for both CJS and ESM projects.
  • TypeScript type declarations included.

Installation

bun add @esmkit/colors

Usage

import colors from "@esmkit/colors"
console.log(
  colors.green(`How are ${colors.italic(`you`)} doing?`)
)

The object also includes following background color modifier functions: bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite and bright variants bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright.

import colors from "@esmkit/colors"
console.log(
  colors.bgBlack(
    colors.white(`Tom appeared on the sidewalk with a bucket of whitewash and a long-handled brush.`)
  )
)

Besides colors, the object includes following formatting functions: dim, bold, hidden, italic, underline, strikethrough, reset, inverse and bright variants blackBright, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright.

import colors from "@esmkit/colors"
for (let task of tasks) {
  console.log(`${colors.bold(task.name)} ${colors.dim(task.durationMs + "ms")}`)
}

The library provides additional utilities to ensure the best results for the task:

  • isColorSupported — boolean, explicitly tells whether or not the colors or formatting appear on the screen

    import colors from "@esmkit/colors"
    
    if (colors.isColorSupported) {
      console.log("Yay! This script can use colors and formatters")
    }

createColors(enabled) — a function that returns a new API object with manually defined color support configuration

import colors from "@esmkit/colors"

let { red, bgWhite } = colors.createColors(options.enableColors)

Motivation

With @esmkit/colors we are trying to draw attention to the node_modules size problem and promote performance-first culture.

License

MIT © BILLGO. See LICENSE for details.

About

🎨 The tiniest and the fastest library for terminal output formatting with ANSI colors

Resources

License

Stars

Watchers

Forks

Sponsor this project