source: trip-planner-front/node_modules/nanocolors/README.md@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.1 KB
Line 
1# Nano Colors
2
3<img align="right" width="64" height="60"
4 src="./img/logo.svg"
5 title="Nano Colors logo by Roman Shamin">
6
7A tiny and fast Node.js library for formatting terminal text with ANSI colors.
8
9* It is **2 times faster** than `chalk`. Both loading and calls.
10* **No dependencies.** It takes **5 times less space** in `node_modules`
11 than `chalk`.
12* **Actively maintained.** Used in many big projects
13 like PostCSS or Browserslist.
14* **Auto-detects color support.** You can also toggle color mode manually.
15* **Tree-shakable.** We use a dual [ESM]/[CJS] package.
16* Supports Node.js ≥ 6, Deno and universal Node.js/browser projects.
17
18```js
19import { green, bold } from 'nanocolors'
20
21console.log(
22 green(`Task ${bold('1')} was finished`)
23)
24```
25
26<p align="center">
27 <img src="./img/example.png" alt="Nano Colors output" width="600">
28</p>
29
30API was heavily inspired
31by [**@jorgebucaran**](https://github.com/jorgebucaran/)’s
32[`colorette`](https://github.com/jorgebucaran/colorette) with few cool hacks
33copied from [**@lukeed**](https://github.com/lukeed/)’s
34[`kleur`](https://github.com/lukeed/kleur).
35
36<a href="https://evilmartians.com/?utm_source=nanocolors">
37 <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg"
38 alt="Sponsored by Evil Martians" width="236" height="54">
39</a>
40
41[ESM]: https://github.com/ai/nanocolors/blob/main/index.js
42[CJS]: https://github.com/ai/nanocolors/blob/main/index.cjs
43
44
45## Benchmarks
46
47Function calling time:
48
49```
50$ ./test/benchmark.js
51chalk 11,608,010 ops/sec
52cli-color 752,419 ops/sec
53ansi-colors 3,601,857 ops/sec
54kleur 15,185,239 ops/sec
55kleur/colors 21,113,231 ops/sec
56colorette 19,712,884 ops/sec
57nanocolors 21,176,376 ops/sec
58```
59
60Library loading time:
61
62```
63$ ./test/loading.js
64chalk 3.465 ms
65cli-color 21.849 ms
66ansi-colors 1.101 ms
67kleur 1.628 ms
68kleur/colors 0.508 ms
69colorette 2.610 ms
70nanocolors 0.486 ms
71```
72
73The space in `node_modules` including sub-dependencies:
74
75```
76$ ./test/size.js
77Data from packagephobia.com
78chalk 101 kB
79cli-color 1249 kB
80ansi-colors 25 kB
81kleur 21 kB
82colorette 16 kB
83nanocolors 16 kB
84```
85
86Test configuration: ThinkPad X1 Carbon Gen 9, Fedora 34, Node.js 16.8.
87
88## Replacing `chalk`
89
901. Replace import and use named exports:
91
92 ```diff
93 - import chalk from 'chalk'
94 + import { red, bold } from 'nanocolors'
95 ```
96
972. Unprefix calls:
98
99 ```diff
100 - chalk.red(text)
101 + red(text)
102 ```
103
1043. Replace chains to nested calls:
105
106 ```diff
107 - chalk.red.bold(text)
108 + red(bold(text))
109 ```
110
111
112## API
113
114### Individual Colors
115
116Nano Colors exports functions:
117
118| Colors | Background Colors | Modifiers |
119| --------- | ------------------- | ----------------- |
120| `black` | `bgBlack` | dim |
121| `red` | `bgRed` | **bold** |
122| `green` | `bgGreen` | hidden |
123| `yellow` | `bgYellow` | _italic_ |
124| `blue` | `bgBlue` | <u>underline</u> |
125| `magenta` | `bgMagenta` | ~~strikethrough~~ |
126| `cyan` | `bgCyan` | reset |
127| `white` | `bgWhite` | |
128| `gray` | | |
129
130Functions are not chainable. You need to wrap it inside each other:
131
132```js
133import { black, bgYellow } from 'nanocolors'
134
135console.log(bgYellow(black(' WARN ')))
136```
137
138Functions will use colors only if Nano Colors auto-detect that current
139environment supports colors.
140
141You can get support level in `isColorSupported`:
142
143```js
144import { isColorSupported } from 'nanocolors'
145
146if (isColorSupported) {
147 console.log('With colors')
148}
149```
150
151
152### Conditional Support
153
154You can manually switch colors on/off and override color support auto-detection:
155
156```js
157import { createColors } from 'nanocolors'
158
159const { red } = createColors(options.enableColors)
160```
161
162On `undefined` argument, `createColors` will use value
163from color support auto-detection.
164
165
166### Deno
167
168Nano Colors has build-in [Deno support](https://deno.land/x/nanocolors).
169
170```js
171import { red } from 'https://deno.land/x/nanocolors/mod.ts'
172```
Note: See TracBrowser for help on using the repository browser.