1 | # Colorette
|
---|
2 |
|
---|
3 | > Easily set the text color and style in the terminal.
|
---|
4 |
|
---|
5 | - No wonky prototype method-chain API.
|
---|
6 | - Automatic color support detection.
|
---|
7 | - Up to [2x faster](#benchmarks) than alternatives.
|
---|
8 | - [`NO_COLOR`](https://no-color.org) friendly. 👌
|
---|
9 |
|
---|
10 | Here's the first example to get you started.
|
---|
11 |
|
---|
12 | ```js
|
---|
13 | import { blue, bold, underline } from "colorette"
|
---|
14 |
|
---|
15 | console.log(
|
---|
16 | blue("I'm blue"),
|
---|
17 | bold(blue("da ba dee")),
|
---|
18 | underline(bold(blue("da ba daa")))
|
---|
19 | )
|
---|
20 | ```
|
---|
21 |
|
---|
22 | Here's an example using [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals).
|
---|
23 |
|
---|
24 | ```js
|
---|
25 | console.log(`
|
---|
26 | There's a ${underline(blue("house"))},
|
---|
27 | With a ${bold(blue("window"))},
|
---|
28 | And a ${blue("corvette")}
|
---|
29 | And everything is blue
|
---|
30 | `)
|
---|
31 | ```
|
---|
32 |
|
---|
33 | Of course, you can nest styles without breaking existing color sequences.
|
---|
34 |
|
---|
35 | ```js
|
---|
36 | console.log(bold(`I'm ${blue(`da ba ${underline("dee")} da ba`)} daa`))
|
---|
37 | ```
|
---|
38 |
|
---|
39 | Feeling adventurous? Try the [pipeline operator](https://github.com/tc39/proposal-pipeline-operator).
|
---|
40 |
|
---|
41 | ```js
|
---|
42 | console.log("Da ba dee da ba daa" |> blue |> bold)
|
---|
43 | ```
|
---|
44 |
|
---|
45 | ## Installation
|
---|
46 |
|
---|
47 | ```console
|
---|
48 | npm install colorette
|
---|
49 | ```
|
---|
50 |
|
---|
51 | ## API
|
---|
52 |
|
---|
53 | ### `<style>(string)`
|
---|
54 |
|
---|
55 | See [supported styles](#supported-styles).
|
---|
56 |
|
---|
57 | ```js
|
---|
58 | import { blue } from "colorette"
|
---|
59 |
|
---|
60 | blue("I'm blue") //=> \x1b[34mI'm blue\x1b[39m
|
---|
61 | ```
|
---|
62 |
|
---|
63 | ### `options.enabled`
|
---|
64 |
|
---|
65 | Colorette automatically detects if your terminal can display color, but you can toggle color as needed.
|
---|
66 |
|
---|
67 | ```js
|
---|
68 | import { options } from "colorette"
|
---|
69 |
|
---|
70 | options.enabled = false
|
---|
71 | ```
|
---|
72 |
|
---|
73 | You can also force the use of color globally by setting `FORCE_COLOR=` or `NO_COLOR=` from the CLI.
|
---|
74 |
|
---|
75 | ```console
|
---|
76 | $ FORCE_COLOR= node example.js >log
|
---|
77 | $ NO_COLOR= node example.js
|
---|
78 | ```
|
---|
79 |
|
---|
80 | ## Supported styles
|
---|
81 |
|
---|
82 | | Colors | Background Colors | Bright Colors | Bright Background Colors | Modifiers |
|
---|
83 | | ------- | ----------------- | ------------- | ------------------------ | ----------------- |
|
---|
84 | | black | bgBlack | blackBright | bgBlackBright | dim |
|
---|
85 | | red | bgRed | redBright | bgRedBright | **bold** |
|
---|
86 | | green | bgGreen | greenBright | bgGreenBright | hidden |
|
---|
87 | | yellow | bgYellow | yellowBright | bgYellowBright | _italic_ |
|
---|
88 | | blue | bgBlue | blueBright | bgBlueBright | <u>underline</u> |
|
---|
89 | | magenta | bgMagenta | magentaBright | bgMagentaBright | ~~strikethrough~~ |
|
---|
90 | | cyan | bgCyan | cyanBright | bgCyanBright | reset |
|
---|
91 | | white | bgWhite | whiteBright | bgWhiteBright | |
|
---|
92 | | gray | | | | |
|
---|
93 |
|
---|
94 | ## Benchmarks
|
---|
95 |
|
---|
96 | ```console
|
---|
97 | npm --prefix bench start
|
---|
98 | ```
|
---|
99 |
|
---|
100 | ## License
|
---|
101 |
|
---|
102 | [MIT](LICENSE.md)
|
---|