Performance comparison: Chained vs Nested syntax
masterWhen comparing performance between libraries, it is important to use the fastest styling method supported by the library.
- Chained syntax (e.g.,
lib.red.bold('text')) is faster and more concise. - Nested syntax (e.g.,
lib.red(lib.bold('text'))) is slower and more verbose.
ansis and chalk support chained syntax, whereas libraries like picocolors, colorette, and kleur do not and require nested calls.
// Fast and short (Chained)
lib.red.bold.bgWhite(' ERROR ')
// Slower and verbose (Nested)
lib.red(lib.bold(lib.bgWhite(' ERROR ')))