Coder Social home page Coder Social logo

colorette's Introduction

Colorette

Easily set your terminal text color & styles.

  • No wonky prototype method-chain API.
  • Automatic color support detection.
  • Up to 2x faster than alternatives.
  • NO_COLOR friendly. โœ…

๐Ÿ‘‹ Upgrading from Colorette 1.x?

Quickstart

Here's the first example to get you started.

import { blue, bold, underline } from "colorette"

console.log(
  blue("I'm blue"),
  bold(blue("da ba dee")),
  underline(bold(blue("da ba daa")))
)

Here's an example using template literals.

console.log(`
  There's a ${underline(blue("house"))},
  With a ${bold(blue("window"))},
  And a ${blue("corvette")}
  And everything is blue
`)

Of course, you can nest styles without breaking existing color sequences.

console.log(bold(`I'm ${blue(`da ba ${underline("dee")} da ba`)} daa`))

Need to override automatic color detection? You can do that too.

import { createColors } from "colorette"

const { blue } = createColors({ useColor: false })

console.log(blue("Blue? Nope, nah"))

Installation

npm install colorette

API

blue(text)

See all supported colors.

blue("I'm blue") //=> \x1b[34mI'm blue\x1b[39m

isColorSupported

true if your terminal supports color, false otherwise. Used internally and handled for you, but exposed for convenience.

createColors({ useColor })

Create a reusable instance of Colorette. Color support is automatically detected, but you can override it by setting the useColor boolean property.

import { createColors } from "colorette"

const { blue } = createColors({ useColor: false })

Environment

You can override color detection from the CLI by setting the --no-color or --color flags.

$ ./example.js --no-color | ./consumer.js

Or if you can't use CLI flags, by setting the NO_COLOR= or FORCE_COLOR= environment variables.

$ NO_COLOR= ./example.js | ./consumer.js

Supported colors

Colors Background Colors Bright Colors Bright Background Colors Modifiers
black bgBlack blackBright bgBlackBright dim
red bgRed redBright bgRedBright bold
green bgGreen greenBright bgGreenBright hidden
yellow bgYellow yellowBright bgYellowBright italic
blue bgBlue blueBright bgBlueBright underline
magenta bgMagenta magentaBright bgMagentaBright strikethrough
cyan bgCyan cyanBright bgCyanBright reset
white bgWhite whiteBright bgWhiteBright
gray
npm --prefix bench start

License

MIT

colorette's People

Contributors

ai avatar alexkuz avatar barissenkal avatar chocolateboy avatar danielruf avatar flurmbo-wevote-browserstack avatar jorgebucaran avatar kibertoad avatar kytta avatar netopwibby avatar pioug avatar prantlf avatar styfle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.