npm install picocolors
A tinier and faster alternative to nanocolors. Andrey, are you even trying?
import { green, italic } from "picocolors";
console.log(green(`How are ${italic(`you`)} doing?`));
- Up to 2x faster and 2x smaller than alternatives
- 3x faster and 10x smaller than
chalk
- TypeScript & Flowtype support
NO_COLOR
friendly- Node.js v6+ & browsers support
- The same API, but faster, much faster
- No
String.prototype
modifications (anyone still doing it?) - No dependencies and the smallest
node_modules
footprint - Tree-shakeable (in case a Node.js package needs it?)
Credits go to the following projects:
- Nanocolors by @ai
- Colorette by @jorgebucaran
- Kleur by @lukeed
- Colors.js by @Marak
- Chalk by @sindresorhus
nanocolors
benchmark:
./test/size.js
Data from packagephobia.com
chalk 101 kB
cli-color 1249 kB
ansi-colors 25 kB
kleur 21 kB
colorette 16 kB
nanocolors 16 kB
+picocolors 8 kB
$ ./test/complex-benchmark.js
chalk 2,618,824 ops/sec
cli-color 326,445 ops/sec
ansi-colors 1,057,188 ops/sec
kleur 2,543,659 ops/sec
kleur/colors 2,841,679 ops/sec
colorette 3,219,038 ops/sec
nanocolors 3,672,600 ops/sec
+picocolors 6,079,950 ops/sec
colorette
benchmark:
$ npm start
+picocolors × 1,203,773 ops/sec
chalk × 474,359 ops/sec
kleur × 482,915 ops/sec
colors × 233,138 ops/sec
colorette × 657,896 ops/sec
nanocolors × 660,817 ops/sec
ansi-colors × 290,986 ops/sec
Just replace imports
-import { green, italic } from 'nanocolors';
+import { green, italic } from 'picocolors';