- Full 16M+ color support across all capable consoles.
- Smart color-degrading to seamlessly support 256 and 16-color consoles.
- A single and minimal API - same coloration code for a windows WebStorm terminal as an Apple laptop console.
- Super-fast performance... 5x faster than colors.js and 10x faster than chalk!!!
- 256 standard named colors for easy usage - both CSS4 Named Colors as well as standard ANSI.
- Clean, vanilla JS implementation - safe by default. A drop-in module that plays nicely with other code.
Tinter supports both the new lowercased CSS4 Named Colors as well as the standard and older camel-cased ANSI color naming schemes.
CSS4 Named Color Set
ANSI Named Color Set
RGB colors (...and using the 16M+ color palette)
If your console supports TrueColor then Tinter can give you access to it's full 16M+ RGB color palette.
npm install tinter
Ok to start coloring - we just import it at the top of the script with whatever name seems most useful to you. For example,
const Tinter = ; // In a 'Pure and correct' manner...const color = ; // Or as a 'compatible' drop-in... :)const tint = ; // Or just short and 'pragmatic'...
Single style or color:-
Tinter allows you to compose multi-colored text in a number of ways:-
As simple concatenation of self-contained colored 'blocks':-
let composed = "I'm " + color + " and " + color + " together.";console;let composed = `I'm and together.`;console;
Or as a 'stream'-style coloration - that is even more efficient! - but requires a manual 'reset' when you wish to return text to default coloration.:-
let streamed = `I'm first green then with underline too and then red to the end.`;console;
Limited to the core eight console colors (black, red, yellow, blue, green, magenta, cyan and white) - but often much more convenient to use - you can also stack colors and style with syntax: color.colorBg.style
Injecting Tinter directly into JS's String.
A lot of developers like the colors.js approach of directly extending the built-in string - to facilitate simpler, shorter coding.
Although Tinter's default API uses a safe approach that doesn't extend built-ins like this... you can!... if you really want. ;)
To do this just import the alternative version:
const Tinter = ; // This will not load standard Tinter.// but extend String instead.
And from now on you can use coloration directly on any string using the shortened notation:-
let myString = "hi there";console;console;console;console;console;console;
Tinter has been benchmarked on Node versions upwards of v6.10. Running on a recent Apple laptop - results for simple coloration were:-
chalk - single color x 1,909,640 ops/sec ±0.78% (89 runs sampled) colors - single color x 3,740,251 ops/sec ±1.33% (85 runs sampled) colors (unsafe) - single color x 5,656,336 ops/sec ±0.89% (88 runs sampled) tinter - single color x 17,613,603 ops/sec ±0.94% (88 runs sampled) Fastest is: 'tinter - single color'.
For stacked composition (e.g. tinter.red.blueBg.underline("hi there!"); ):-
chalk - stacked color/styles x 470,192 ops/sec ±1.00% (89 runs sampled) colors - stacked color/styles x 733,671 ops/sec ±1.04% (89 runs sampled) tinter - stacked color/styles x 8,176,748 ops/sec ±1.20% (83 runs sampled) Fastest is: 'tinter - stacked color/styles'.
Unsafe (build-in extending versions)
Colors.js also offers an unsafe version of its library with a shorter syntax and better performance.
What makes it 'unsafe' is the fact that it directly extends the built-in string prototype and that can cause problems with other modules' usage of strings.
Tinter offers an unsafe equivalent too - but only for code compatibility reasons. We strongly recommend against you using either unsafe library!
However, if you wish to upgrade your codebase to use Tinter but unfortunately have large amounts of legacy 'colors' code that's currently impractical to rewrite - Tinter/Inject's your solution.
Anyway, just for completeness and to demonstrate the poor performance of this approach... benchmarks for the unsafe versions are:-
colors (unsafe) - single color x 5,679,025 ops/sec ±1.35% (87 runs sampled) tinter (unsafe) - single color x 5,825,590 ops/sec ±0.78% (87 runs sampled)
Finally, to summarize, it seems clear that both in terms of its range of usable colors and in terms of sheer string-crunching performance - Tinter rocks!
We hope you will like it too!
Tinter was written by Kyle Alexis Sargeant and is shared under the LGPL-3.0 license.
So basically you can use it freely in anything - both open-source or commercial - without any need to disclose your own code.