Added rainbow styling
This commit is contained in:
parent
0133342393
commit
24e6a26bbb
2 changed files with 21 additions and 0 deletions
17
chalk.js
17
chalk.js
|
|
@ -60,3 +60,20 @@ chalk.supportsColor = require('has-color');
|
|||
if (chalk.enabled === undefined) {
|
||||
chalk.enabled = chalk.supportsColor;
|
||||
}
|
||||
|
||||
// rainbow style
|
||||
var rainbowColors = [
|
||||
chalk.red,
|
||||
chalk.yellow,
|
||||
chalk.green,
|
||||
chalk.blue,
|
||||
chalk.magenta
|
||||
];
|
||||
chalk.rainbow = function(str) {
|
||||
var arStr = str.split(''),
|
||||
out = '';
|
||||
for (var i in arStr) {
|
||||
out += rainbowColors[i % rainbowColors.length](arStr[i]);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
|
|
|||
4
test.js
4
test.js
|
|
@ -29,6 +29,10 @@ describe('chalk', function () {
|
|||
it('should alias gray to grey', function () {
|
||||
assert.equal(chalk.grey('foo'), '\x1b[90mfoo\x1b[39m');
|
||||
});
|
||||
|
||||
it('should style a string in rainbow colors', function () {
|
||||
assert.equal(chalk.rainbow('rygbmr g\tm\ny'), '\x1b[31mr\x1b[39m\x1b[33my\x1b[39m\x1b[32mg\x1b[39m\x1b[34mb\x1b[39m\x1b[35mm\x1b[39m\x1b[31mr\x1b[39m\x1b[33m \x1b[39m\x1b[32mg\x1b[39m\x1b[34m\t\x1b[39m\x1b[35mm\x1b[39m\x1b[31m\n\x1b[39m\x1b[33my\x1b[39m');
|
||||
});
|
||||
});
|
||||
|
||||
describe('chalk.enabled', function () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue