0.0.5 • Published 5 years ago

tiny-ansi-colors v0.0.5

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

tiny-ansi-colors

npm version Build Status Coverage Status Dependency Status devDependency Status

yet another ansi color module

But why?

Not interested in pulling in > 5kb into a library to get coloured terminal output.

This library is as bare-bones as it gets.

There is no:

  • fancy api (pojo is where it is at)
  • mutation of string prototype (wtf colors?!)
  • checking for color support (do it yourself!)
  • truecolor / ansi256 ("16 colors should be enough for anyone!")

Exports

  • ./dist/tiny-ansi-colors.js - cjs bundle, transpiled to node4. referenced in package.json's main entry
  • ./dist/tiny-ansi-colors.mjs - es6 exports. transpiled to node4. referenced in package.json's module entry
  • ./dist/tiny-ansi-colors.umd.js - browser bundle, transpiled to ie8.
  • ./dist/tiny-ansi-colors.umd.min.js - browser bundle minified

Usage

const {colors} = require('tiny-ansi-colors')
// or import {colors} from 'tiny-ansi-colors/es'

colors('hello!', {color: 'red', background: 'green', bold: true, underline: true})
// \u001b[31m\u001b[42m\u001b[1m\u001b[4mhello!\u001b[24m\u001b[22m\u001b[49m\u001b[39m

API

colors(text: string, options: *?)

Supported options:

  • color {string} color to use for foreground
  • background {string} color to use for background
  • bold {boolean} pass true to get a bold color
  • dim {boolean} pass true to get a dim color
  • underline {boolean} pass true to underline text
  • reverse {boolean} pass true to reverse the codes.

Supported Colors

  • Black
  • Red
  • Green
  • Yellow
  • Blue
  • Magenta
  • Cyan
  • White

Colors are case-insensitive. You can include bright, _bright, -bright, bright- or bright_ to use the bright variant.

Hex codes (e.g., '#fff', '#fffff'), or rgb strings (e.g., rgba(100%, 100%, 100%), rgb(255, 255, 255); note that alpha is ignored) can be passed. These will be converted to the approximate ansi code. Any rgb value <= 64 is coerced to black.

If an invalid color is provided, this module with throw an error.