Skip to content

rabbxdev/colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@rabbx/colors

Fast, zero-dependency ANSI colors for Node.js,Bun,Deno. Drop-in picocolors compatible with chaining, RGB, HEX, and 256 color support.

bun install @rabbx/colors
npm i @rabbx/colors

Usage

import c from '@rabbx/colors'

console.log('--- Basic Colors ---')
console.log(c.black('black'))
console.log(c.red('red'))
console.log(c.green('green'))
console.log(c.yellow('yellow'))
console.log(c.blue('blue'))
console.log(c.magenta('magenta'))
console.log(c.cyan('cyan'))
console.log(c.white('white'))
console.log(c.gray('gray'))

console.log('\n--- Bright Colors ---')
console.log(c.blackBright('blackBright'))
console.log(c.redBright('redBright'))
console.log(c.bold.italic.greenBright('greenBright'))
console.log(c.yellowBright('yellowBright'))
console.log(c.blueBright('blueBright'))
console.log(c.magentaBright('magentaBright'))
console.log(c.cyanBright('cyanBright'))
console.log(c.whiteBright('whiteBright'))

console.log('\n--- Background Colors ---')
console.log(c.bgBlack('bgBlack'))
console.log(c.bgRed('bgRed'))
console.log(c.bgGreen('bgGreen'))
console.log(c.bgYellow('bgYellow'))
console.log(c.bgBlue('bgBlue'))
console.log(c.bgMagenta('bgMagenta'))
console.log(c.bgCyan('bgCyan'))
console.log(c.bgWhite('bgWhite'))

console.log('\n--- Bright Backgrounds ---')
console.log(c.bgBlackBright('bgBlackBright'))
console.log(c.bgRedBright('bgRedBright'))
console.log(c.bgGreenBright('bgGreenBright'))
console.log(c.bgYellowBright('bgYellowBright'))
console.log(c.bgBlueBright('bgBlueBright'))
console.log(c.bgMagentaBright('bgMagentaBright'))
console.log(c.bgCyanBright('bgCyanBright'))
console.log(c.bgWhiteBright('bgWhiteBright'))

console.log('\n--- Styles ---')
console.log(c.reset('reset'))
console.log(c.bold('bold'))
console.log(c.dim('dim'))
console.log(c.italic('italic'))
console.log(c.underline('underline'))
console.log(c.inverse('inverse'))
console.log(c.hidden('hidden'))
console.log(c.strikethrough('strikethrough'))

console.log('\n--- Chaining ---')
console.log(c.bold.red('bold red'))
console.log(c.bold.red.underline('bold red underline'))
console.log(c.italic.cyan('italic cyan'))
console.log(c.dim.yellow.bgBlue('dim yellow on blue'))
console.log(c.inverse.white('inverse white'))



console.log('\n--- RGB ---')
console.log(c.rgb(255, 100, 50)('orange'))
console.log(c.rgb(100, 255, 150).bold('mint bold'))
console.log(c.bgRgb(30, 30, 80).white('dark blue bg'))

console.log('\n--- HEX ---')
console.log(c.hex('#ff6347')('tomato'))
console.log(c.hex('#00d4aa').bold('teal bold'))
console.log(c.bgHex('#1e1e3f').white('dark bg'))

console.log('\n--- 256 Color ---')
console.log(c.ansi256(201)('pink'))
console.log(c.bgAnsi256(52).white('dark red bg'))

console.log('\n--- Nested Styles ---')
console.log(c.bold(`bold and ${c.red('red inside')} back to bold`))
console.log(c.red(`red and ${c.bold('bold inside')} back to red`))
console.log(c.underline(`underline ${c.italic('italic inside')} underline`))

console.log('\n--- Check Support ---')
console.log('Color supported:', c.isColorSupported)

Features

  • Tiny: < 700 bytes gzipped
  • Fast: No regex, minimal allocations
  • Chaining: c.bold.red.underline('text')
  • Callable chaining: c.bold().red('text')
  • RGB/HEX/256: Truecolor and 256 color support
  • Auto color detection: Respects NO_COLOR, FORCE_COLOR, TTY, CI
  • Safe nesting: Handles nested styles correctly

API

Basic colors
c.black, c.red, c.green, c.yellow, c.blue, c.magenta, c.cyan, c.white, c.gray
c.blackBright, c.redBright, c.greenBright, c.yellowBright, c.blueBright, c.magentaBright, c.cyanBright, c.whiteBright
Background colors
c.bgBlack, c.bgRed, c.bgGreen, c.bgYellow, c.bgBlue, c.bgMagenta, c.bgCyan, c.bgWhite
c.bgBlackBright, c.bgRedBright, c.bgGreenBright, c.bgYellowBright, c.bgBlueBright, c.bgMagentaBright, c.bgCyanBright, c.bgWhiteBright
Styles
c.reset, c.bold, c.dim, c.italic, c.underline, c.inverse, c.hidden, c.strikethrough
Truecolor
c.rgb(r, g, b)('text')
c.bgRgb(r, g, b)('text')
c.hex('#ff6347')('text')
c.bgHex('#ff6347')('text')
256 Colors
c.ansi256(201)('text')
c.bgAnsi256(52)('text')
Utilities
c.isColorSupported // boolean
Manual control
import { createColors } from '@rabbx/colors'
const noColor = createColors(false)
console.log(noColor.red('no color output'))

Chaining Rules

All methods are chainable in any order:

c.bold.red.underline('text')
c.red.bold.underline('text')
c.underline.red.bold('text')

You can also call functions before chaining:

c.bold().red().underline('text')

Nested styles work correctly:

console.log(c.bold(`outer ${c.red('inner')} outer`))

// Resets properly, no color bleeding Color Detection

Colors are enabled automatically when:

  • stdout is a TTY and TERM !== 'dumb'
  • FORCE_COLOR env var is set
  • --color flag is passed
  • Platform is Windows
  • CI env var is set

Disable with NO_COLOR=1 or --no-color flag.

Example

import c from '@rabbx/colors'

const log = {
  info: msg => console.log(c.blue('[INFO]'), msg),
  warn: msg => console.log(c.yellow('[WARN]'), msg),
  error: msg => console.log(c.bold.red('[ERROR]'), msg),
  success: msg => console.log(c.green('✓'), c.bold(msg))
}

log.info('Server starting...')
log.success('Server ready on port 3000')
log.warn('Deprecated API used')
log.error('Connection failed')

License

MIT


Why @rabbx/colors?

Same API as picocolors, faster, with built-in RGB/HEX/256 support and ESM-first design.

About

Fast, zero-dependency ANSI colors for Node.js,Bun,Deno. Drop-in picocolors compatible with chaining, RGB, HEX, and 256 color support.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors