JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 38
  • Score
    100M100P100Q49396F
  • License GPL-3.0

Apply ANSI colors to strings!

Package Exports

  • colorix
  • colorix/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (colorix) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Colorix

Colorix helps you recognize and track ansi escape sequences in your code, and provides a simple way to define and layer color presets.

import cx from 'colorix'

const goblinInk = cx('bgGreen', 'black', 'bold')

console.log(goblinInk('hello goblin', '!'))

goblin-example

With TypeScript, you'll see how the color sequences are applied to your strings.

declare const goblinMessage: Colorix<['bgGreen', 'black', 'bold'], ['hello goblin', '!']>
// => `\u001B[42;30;1mhello goblin!\u001B[0m`

This is useful with primitive strings as well.

declare const goblinMessage: Colorix<['bgGreen', 'black', 'bold'], [string, ...string[]]>
// => `\u001B[42;30;1m${string}\u001B[0m`

Installation

Add colorix to your project using your favorite package manager.

NPM

npm install colorix

PNPM

pnpm add colorix

Yarn

yarn add colorix

Exports

colorix / cx / default

Colorix Description
default create presets for colorizing Stringifiable values.
colorix alias for cx
cx named export
// create a theme by passing colors to the first function.
declare const cx: <Colors extends Color[]>(...colors: Colors) =>
  // then pass stringifiable values to the second function to colorize them.
  <Strings extends Stringifiable[]>(...strings: Strings) =>
    // the returned value is an ansified string.
    Colorix<Colors, Strings>

Constants

Name Description
CSI control sequence introducer ("\x1b[")
SGRT select graphic rendition terminator ("m")
FOREGROUND readonly foreground lookup object
BACKGROUND readonly background lookup object
MODIFIER readonly modifier lookup object
COLORS readonly color lookup object (foreground, background, and modifiers)
hasBasicColors boolean indicating if the terminal supports basic colors
has256Colors boolean indicating if the terminal supports 256 colors
has16mColors boolean indicating if the terminal supports 16 million colors
supportsColor boolean indicating if the terminal supports any color

Types

Generic Description
Colorix utility for creating literals wrapped in ANSI sequences
ColorSequence utility for creating literal ANSI sequences
Alias Description
ResetSequence literal reset sequence that is always appended to the end of a color sequence
ColorTable readonly record of color aliases and color codes
Color a foreground, background, or modifier color (keyof ColorTable)
ColorCode an SGR color code
Foreground a foreground color
Background a background color
Modifier a modifier color

Color Tables

Foreground Code Foreground Bright Code
"black" 30 "gray" 90
"red" 31 "redBright" 91
"green" 32 "greenBright" 92
"yellow" 33 "yellowBright" 93
"blue" 34 "blueBright" 94
"magenta" 35 "magentaBright" 95
"cyan" 36 "cyanBright" 96
"white" 37 "whiteBright" 97
Background Code Background Bright Code
"bgBlack" 40 "bgGray" 100
"bgRed" 41 "bgRedBright" 101
"bgGreen" 42 "bgGreenBright" 102
"bgYellow" 43 "bgYellowBright" 103
"bgBlue" 44 "bgBlueBright" 104
"bgMagenta" 45 "bgMagentaBright" 105
"bgCyan" 46 "bgCyanBright" 106
"bgWhite" 47 "bgWhiteBright" 107
Modifier Code
"reset" 0
"bold" 1
"dim" 2
"italic" 3
"underline" 4
"inverse" 7
"hidden" 8
"strikethrough" 9