String styling helpers inspired by Chalk.
Installation
With NPM:
$ npm install @njakob/rainbow
With Yarn:
$ yarn add @njakob/rainbow
Usage
Rainbow relies on tagged template literals in order to generate style nodes. Theses nodes can then be formatted through a specific function and generate a styled string.
import { Rainbow, ansiStyleFormatter } from '@njakob/Rainbow';
const styles = new Rainbow(ansiStyleFormatter);
const styleNode = styles.parse`Stuff to ${styles.red`log`} with some ${styles.bold.blue`colors`}`;
const styledString = styles.format(styleNode);
console.log(styledString.value);
process.stdout.write(`${styledString.value}\n`);
Colors
styles.parse`${styles.black`black`}`
styles.parse`${styles.red`red`}`
styles.parse`${styles.green`green`}`
styles.parse`${styles.yellow`yellow`}`
styles.parse`${styles.blue`blue`}`
styles.parse`${styles.cyan`cyan`}`
styles.parse`${styles.magenta`magenta`}`
styles.parse`${styles.white`white`}`
styles.parse`${styles.gray`gray`}`
Backgrounds
styles.parse`${styles.bgBlack`black`}`
styles.parse`${styles.bgRed`red`}`
styles.parse`${styles.bgGreen`green`}`
styles.parse`${styles.bgYellow`yellow`}`
styles.parse`${styles.bgBlue`blue`}`
styles.parse`${styles.bgCyan`cyan`}`
styles.parse`${styles.bgMagenta`magenta`}`
styles.parse`${styles.bgWhite`white`}`
Modifiers
styles.parse`${styles.bold`bold`}`
styles.parse`${styles.dim`dim`}`
styles.parse`${styles.italic`italic`}`
styles.parse`${styles.inverse`inverse`}`
styles.parse`${styles.hidden`hidden`}`
styles.parse`${styles.strikethrough`strikethrough`}`
styles.parse`${styles.underline`underline`}`
Flowtype
In order for Flowtype to correctly parse the definition, the following option
must be added to your .flowconfig
.
[options]
unsafe.enable_getters_and_setters=true
Changelog
See changelog.
Licences
njakob/rainbow
is licensed under the MIT License.