You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 18, 2023. It is now read-only.
Colorix provides a simple way to define and layer color presets, and helps you recognize and track ANSI escape sequences in your code. Each module uses template literals (and a bit of magic πͺ) to construct a type representation of the color sequences applied to your strings.
// create a theme by passing colors to the first function.declareconstcx: <ColorsextendsColor[]>(
...colors: Colors)=>// then pass stringifiable values to the second function to colorize them.<StringsextendsStringifiable[]>(
...strings: Strings)=>// the returned value is an ansified string.Colorix<Colors,Strings>
Installation
Add colorix to your project using your favorite package manager.
NPM
npm install colorix
PNPM
pnpm add colorix
Yarn
yarn add colorix
How to support terminals without color
safe, colorixSafe, cxs
You can use safe to check if the terminal supports color before applying a preset.
Alternatively, use colorixSafe / cxs for an Ink preset that only applies colors if the terminal supports it.
import{cxs,colorixSafe}from'colorix'constsafeErrorInk=cxs('bold','red')// or colorixSafe('bold', 'red')console.log(safeErrorInk('That tasted purple...'))
Bonus Features
ColorixError
Fun way to colorize error messages without worrying about the terminal supporting color, or importing colorix / cx / safe into many files.
import{ColorixError}from'colorix'constBasicError=newColorixError('simple message that is always safe to display')constPrettyError=newColorixError((cx)=>cx('white','bgBlue','dim','bold')('Pretty Message',cx('reset')(' '),cx('underline','green')('npmjs.com/package/colorix',cx('reset','italic')(' '),'(this message will always be stripped of color if supportsColor is false)')))throwPrettyError
PrettyError
For an "out-of-the-box" solution, use PrettyError. It provides the same naming and fallback message behavior as Colorix without an api for customizing the rest of the error.