|
| 1 | +[![Build Status][TravisLogo]][Travis] |
| 2 | +  |
| 3 | + |
| 4 | +[](https://www.npmjs.org/package/clor) |
| 5 | + |
| 6 | + |
| 7 | +<a name="clor"></a> |
| 8 | + |
| 9 | +<p align="center"> |
| 10 | + |
| 11 | +<b><a href="#synopsis">Synopsis</a></b> |
| 12 | +| |
| 13 | +<b><a href="#examples">Examples</a></b> |
| 14 | +| |
| 15 | +<b><a href="#install">Install</a></b> |
| 16 | +| |
| 17 | +<b><a href="#usage">Usage</a></b> |
| 18 | +| |
| 19 | +<b><a href="#styles">Styles</a></b> |
| 20 | +| |
| 21 | +<b><a href="#license">License</a></b> |
| 22 | + |
| 23 | +</p> |
| 24 | + |
| 25 | +<p align="center"> |
| 26 | +<a href="https://github.com/bucaran/clor/blob/master/clor"> |
| 27 | +<img width=44% src="https://cloud.githubusercontent.com/assets/8317250/7343629/9bfe2a46-ecfe-11e4-8878-fcb9bac8b9f9.png"> |
| 28 | +</a> |
| 29 | +</p> |
| 30 | + |
| 31 | + |
| 32 | +# Synopsis |
| 33 | + |
| 34 | +_Clor_ is a __30__ some LOC _original_ alternative to [colors.js](https://github.com/Marak/colors.js) and [Chalk](https://github.com/sindresorhus/chalk). |
| 35 | + |
| 36 | + |
| 37 | +<p align="center"> |
| 38 | +<a href="https://github.com/bucaran/clor/blob/master/clor"> |
| 39 | +<img src="https://cloud.githubusercontent.com/assets/8317250/7427256/5470b678-f012-11e4-9c46-dbfa0c958fe7.png"> |
| 40 | +</a> |
| 41 | +</p> |
| 42 | + |
| 43 | +## Compare |
| 44 | + |
| 45 | +In [Chalk](https://github.com/sindresorhus/chalk) you concatenate strings to compose your output: |
| 46 | + |
| 47 | +```js |
| 48 | +console.log( |
| 49 | + chalk.red.bold("fee") + "\n" + chalk.inverse("fi") + "\n" + chalk.underline("fo") |
| 50 | +) |
| 51 | +``` |
| 52 | + |
| 53 | +In _Clor_ you concatenate or use each style property as a function: |
| 54 | + |
| 55 | +```js |
| 56 | +console.log(String( |
| 57 | + clor.red.bold("fee").line.inverse("fi").line.underline("fo") |
| 58 | +)) |
| 59 | +``` |
| 60 | + |
| 61 | +You can get the composed string using `string` |
| 62 | + |
| 63 | +```js |
| 64 | +console.log( |
| 65 | + clor.red.bold("fee").line.inverse("fi").line.underline("fo").string |
| 66 | +) |
| 67 | +``` |
| 68 | + |
| 69 | +Or provide your own logger function: |
| 70 | + |
| 71 | +```js |
| 72 | +clor.red.bold("hi").log(function (args) { |
| 73 | + process.stdout.write("[" + this + "]") |
| 74 | +}/*, ... */) |
| 75 | +``` |
| 76 | + |
| 77 | +Where `args` is optional and `this` is bound to the string. |
| 78 | + |
| 79 | +In just a few lines of code _Clor_ packs a lot of interesting functionality. |
| 80 | + |
| 81 | +# Install |
| 82 | + |
| 83 | +```sh |
| 84 | +npm install clor |
| 85 | +``` |
| 86 | + |
| 87 | +# Usage |
| 88 | + |
| 89 | +```js |
| 90 | +var $ = require("clor") |
| 91 | + |
| 92 | +$.red("hey") |
| 93 | +//→ \u001b[31mhey\u001b[0m |
| 94 | + |
| 95 | +$.underline.bold.bgBlue.yellow("howdy!") |
| 96 | +//→ \u001b[4m\u001b[1m\u001b[44m\u001b[33mhowdy!\u001b[0m |
| 97 | + |
| 98 | +// You can add new lines with `line` or \n |
| 99 | +$("1st line").line("2nd line").red.line("3rd line") |
| 100 | +//→ 1st line\u001b[0m\n2nd line\u001b[0m\u001b[31m\n3rd line\u001b[0m |
| 101 | +``` |
| 102 | + |
| 103 | +## Examples |
| 104 | + |
| 105 | +```js |
| 106 | +console.log("npm install %s", $.blue("clor")) |
| 107 | + |
| 108 | +// No need to cast to String explicitly when concatenating |
| 109 | +console.log( |
| 110 | + $.red("a red line") + $.line.blue("and a blue one") |
| 111 | +) |
| 112 | + |
| 113 | +// Using Clor |
| 114 | +var $ = require("clor") |
| 115 | +console.log($ |
| 116 | + .blue("A blue line\n") |
| 117 | + .green("I am a green line ") |
| 118 | + .blue.underline.bold("with a blue substring") |
| 119 | + .green(" that becomes green again!") + "Au revoir!" |
| 120 | +) |
| 121 | + |
| 122 | +// Using Chalk |
| 123 | +var $ = require("chalk") |
| 124 | +console.log( |
| 125 | + $.blue("A blue line.\n") + |
| 126 | + $.green( |
| 127 | + "I am a green line " + |
| 128 | + $.blue.underline.bold("with a blue substring") + |
| 129 | + " that becomes green again!" |
| 130 | + ) + "Hasta la vista!" |
| 131 | +) |
| 132 | + |
| 133 | +// Using Colors.js |
| 134 | +console.log( |
| 135 | + "A blue line.\n".blue + |
| 136 | + "I am a green line ".green + |
| 137 | + "with a blue substring".blue.underline.bold + |
| 138 | + " that becomes green again!".green + |
| 139 | + " Saraba!" |
| 140 | +) |
| 141 | +``` |
| 142 | + |
| 143 | +> Notes: To be fair, [_colors_](https://github.com/marak/colors.js/) is probably the most readable, but it extends the [String Prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype) which is generally a [bad practice](http://perfectionkills.com/whats-wrong-with-extending-the-dom/). |
| 144 | +
|
| 145 | + |
| 146 | + |
| 147 | +# Styles |
| 148 | + |
| 149 | +| Modifiers | Colors | Background Colors | |
| 150 | +|:---------------:|:---------:|:-----------------:| |
| 151 | +| `reset` | `black` | bgBlack | |
| 152 | +| `bold` | `red` | `bgRed` | |
| 153 | +| `dim` | `green` | `bgGreen` | |
| 154 | +| `italic` | `yellow` | `bgYellow` | |
| 155 | +| `underline` | `blue` | `bgBlue` | |
| 156 | +| `inverse` | `magenta` | `bgMagenta` | |
| 157 | +| `hidden` | `cyan` | `bgCyan` | |
| 158 | +| `strikethrough` | `white` | `bgWhite` | |
| 159 | +| `line` | `gray` | | |
| 160 | +| `_` or `space` | | | |
| 161 | +| `tab` | | | |
| 162 | + |
| 163 | +## Custom Styles |
| 164 | + |
| 165 | +Create custom styles easily: |
| 166 | + |
| 167 | +```js |
| 168 | +let Style { |
| 169 | + title: $.bold.underline, |
| 170 | + quote: $.inverse, |
| 171 | + notes: $.bold.green.italic |
| 172 | +} |
| 173 | + |
| 174 | +console.log("[" + Style.title(title) + "]") |
| 175 | + |
| 176 | +``` |
| 177 | + |
| 178 | +# License |
| 179 | + |
| 180 | +[MIT](http://opensource.org/licenses/MIT) |
| 181 | + |
| 182 | +[TravisLogo]: http://img.shields.io/travis/bucaran/clor.svg?style=flat-square |
| 183 | +[Travis]: https://travis-ci.org/bucaran/clor |
0 commit comments