2.0.20 • Published 1 year ago

colorette v2.0.20

Weekly downloads
11,331,762
License
MIT
Repository
github
Last release
1 year ago

🌈Colorette

Easily set your terminal text color & styles.

  • No dependecies
  • Automatic color support detection
  • Up to 2x faster than alternatives
  • TypeScript support
  • NO_COLOR friendly
  • Node >= 10

Upgrading from Colorette 1.x?

Quickstart

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
`)

You can also nest styles without breaking existing color sequences.

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

Need to override terminal 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

\<color>()

See all supported colors.

import { blue } from "colorette"

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

createColors()

Override terminal color detection via createColors({ useColor }).

import { createColors } from "colorette"

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

isColorSupported

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

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

ColorsBackground ColorsBright ColorsBright Background ColorsModifiers
blackbgBlackblackBrightbgBlackBrightdim
redbgRedredBrightbgRedBrightbold
greenbgGreengreenBrightbgGreenBrighthidden
yellowbgYellowyellowBrightbgYellowBrightitalic
bluebgBlueblueBrightbgBlueBrightunderline
magentabgMagentamagentaBrightbgMagentaBrightstrikethrough
cyanbgCyancyanBrightbgCyanBrightreset
whitebgWhitewhiteBrightbgWhiteBright
gray

Benchmarks

npm --prefix bench start
  chalk         1,786,703 ops/sec
  kleur         1,618,960 ops/sec
  colors          646,823 ops/sec
  ansi-colors     786,149 ops/sec
  picocolors    2,871,758 ops/sec
+ colorette     3,002,751 ops/sec

Acknowledgments

Colorette started out in 2015 by @jorgebucaran as a lightweight alternative to Chalk and was introduced originally as Clor. Our terminal color detection logic borrows heavily from @sindresorhus and @Qix- work on Chalk. The idea of slicing strings to clear bleeding sequences was adapted from a similar technique used by @alexeyraspopov in picocolors. Thank you to all our contributors! <3

License

MIT

webpack-dev-middlewarewebpack-dev-serverwebpack-clilistr2free-min@rygent/logger@nmixjs/cli@grafikr/create-boilerplatecomponennenttchewit@inc/loggereasy-select-rnvuedragdropuploadimagesreact-native-bluetooth2killi8n-react-native-fast-imagewindy-plugin-hktidecreate-sparkleandresfmj-cardreact-native-template-rfbaseairscanairscan-example@yamashiro/loggerreact-native-esc-pos-sahaab@borisovart/atol-kkt-module@frxf/frxfdeneme323112react-native-webpack-toolkit@texttree/demo-bsa-reference-rclandresfmj@fundefund/funde_ckrollup-preset-vue@ntt_app/react-native-custom-notificationreact-native-custom-text-hwjamesreact-native-covid-sdkgql_din_modpara.jsextension-reloader-watch-1@jttechnic/interpreter@wearerequired/wordpress-plugin-boilerplate@zengchaowu/vite-plugin-componentsgit-hey@avid-ui/clidiscord-neuraquick-repositoryreact-native-printer-brothersrn-pdf-reader-offlineworklio-clicbmis-ai-toolboxreact-native-shekhar-bridge-testcogoportutilsuncoded-connect@tnotifier/cli@tnotifier/devonlevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29wilscanner@caviajs/http-contract@oyed/devon@oiti/documentoscopy-react-nativejs4cytoscapequoc-testwindy-plugin-disturbance-trackerwindy-plugin-meteoireact-native-slider-kfunblock-block-save-variables@aora/aora@aora/common@aora/utils@toes/logger@infinitebrahmanuniverse/nolb-colore@ppprisma/logger@redocly/christicclibyarntest@saaspe/components@nyxb/changelog@overwolfdev/plugin-loggerhyperpass-sdktinkle-nuxt-toolsrescript-stdlib-clifirebase-tools-angelopwnlibluminos-ui-corehebe-frameworksklif-ui-kitsklif-api@everything-registry/sub-chunk-1356jawwy-sdkjawwy_gamification_releasetiger-plugin-html@314oner_npm/universal-components-librarysimple-ddosreact-native-sphereuitechev-tool
2.0.20

1 year ago

2.0.19

2 years ago

2.0.17

2 years ago

2.0.18

2 years ago

2.0.15

3 years ago

2.0.16

3 years ago

2.0.14

3 years ago

2.0.13

3 years ago

2.0.11

3 years ago

2.0.12

3 years ago

2.0.9

3 years ago

2.0.10

3 years ago

2.0.8

3 years ago

2.0.5

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.3

3 years ago

2.0.4

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.0

6 years ago