0.4.1 • Published 2 years ago

@open-tech-world/ansi-styles v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Ansi Styles

⚡ by Open Tech World

Build npm bundle size (scoped version)

Style your text using ANSI escape sequences.

Features

✔️ 24-Bit Colors (True Color)

✔️ Nested Styles

✔️ Supports browser dev tools console (Currently chrome & edge browsers only)

Supported Styles

✔️ Foreground Colors

✔️ Background Colors

✔️ Bold

✔️ Dim

✔️ Italic

✔️ Underline

✔️ Inverse

✔️ Strikethrough

Installation

Using npm

npm install @open-tech-world/ansi-styles

Using Yarn

yarn add @open-tech-world/ansi-styles

Usage

import { style } from '@open-tech-world/ansi-styles';

style('~styleName[.styleName...]{Text}');

Examples

Using foreground color name

console.log(style('I like 🍊 ~orange{oranges}'));

npm.io

Using multiple colors

console.log(
  style(
    'An ~red{apple} is red but the ~green{leaves} are green, came in a blue ~blue{box}'
  )
);

npm.io

Nested colors

console.log(
  style(
    '~blue{This is a long blue text with some ~red{red} & ~green{green} color in it}'
  )
);

npm.io

Composing different styles

console.log(style('~bold.white.bgGreen{ PASS }'));

npm.io

Inverse colors

console.log(style('~inverse.red.bgWhite{ FAILED }'));

npm.io

Faint, decreased intensity, or dim text

console.log(style('~dim{TEXT}'));

npm.io

Italic fonts

console.log(style('~italic.fuchsia.bold.bgWhite{ Beautiful Text }'));

npm.io

Underlined texts

console.log(
  style('Highlighted fruits: ~underline{Apple}, cat, ~underline{Banana}')
);

npm.io

Strikethrough text

console.log(style('~strike.red{Deleted file.ext}'));

npm.io

Custom functions

function warning(str) {
  return style(`⚠️  ~bold.black.bgYellow{${str}}`);
}

console.log(warning(' CAUTION '));

npm.io

Style names

  • Colors

    Foreground ColorsBackground Colors
    bluebgBlue
    redbgRed
    greenbgGreen
    orangebgOrange
    navybgNavy
    aquabgAqua
    tealbgTeal
    purplebgPurple
    fuchsiabgFuchsia
    maroonbgMaroon
    yellowbgYellow
    olivebgOlive
    limebgLime
    blackbgBlack
    graybgGray
    silverbgSilver
    whitebgWhite
  • rgb(red, green, blue)

  • bgRgb(red, green, blue)

  • Modifiers

    • bold
    • dim
    • italic
    • underline
    • inverse
    • strike

References

https://en.wikipedia.org/wiki/ANSI_escape_code

https://developer.chrome.com/docs/devtools/console/format-style/

License

Copyright (c) 2022, Thanga Ganapathy (MIT License).