-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
const { Suite } = require('benchmark'); | ||
const cursor = require('ansi')(process.stdout); | ||
const color = require('ansi-colors'); | ||
const clorox = require('clorox'); | ||
const chalk = require('chalk'); | ||
const kleur = require('..'); | ||
|
||
const names = [ | ||
'reset', | ||
'bold', | ||
'dim', | ||
'italic', | ||
'underline', | ||
'inverse', | ||
'hidden', | ||
'strikethrough', | ||
'black', | ||
'red', | ||
'green', | ||
'yellow', | ||
'blue', | ||
'magenta', | ||
'cyan', | ||
'white', | ||
'gray', | ||
'bgBlack', | ||
'bgRed', | ||
'bgGreen', | ||
'bgYellow', | ||
'bgBlue', | ||
'bgMagenta', | ||
'bgCyan', | ||
'bgWhite' | ||
]; | ||
|
||
const cycle = (e, nl) => { | ||
cursor.eraseLine(); | ||
cursor.horizontalAbsolute(); | ||
cursor.write(' ' + e.target); | ||
if (nl) cursor.write('\n'); | ||
}; | ||
|
||
function bench(name) { | ||
console.log(`\n# ${name}`); | ||
const suite = new Suite(); | ||
const res = { | ||
run: suite.run.bind(suite), | ||
add: (key, fn) => { | ||
suite.add(key, { | ||
onCycle: e => cycle(e), | ||
onComplete: e => cycle(e, true), | ||
fn: fn | ||
}); | ||
return res; | ||
} | ||
}; | ||
return res; | ||
} | ||
|
||
bench('All Colors') | ||
.add('ansi-colors', () => { | ||
names.forEach(name => color[name]('foo')); | ||
}) | ||
.add('chalk', () => { | ||
names.forEach(name => chalk[name]('foo')); | ||
}) | ||
.add('clorox', () => { | ||
names.forEach(name => clorox[name]('foo').toString()); | ||
}) | ||
.add('kleur', () => { | ||
names.forEach(name => kleur[name]('foo')); | ||
}) | ||
.run(); | ||
|
||
bench('Stacked colors') | ||
.add('ansi-colors', () => { | ||
names.forEach(name => color[name].bold.underline.italic('foo')); | ||
}) | ||
.add('chalk', () => { | ||
names.forEach(name => chalk[name].bold.underline.italic('foo')); | ||
}) | ||
.add('clorox', () => { | ||
names.forEach(name => clorox[name].bold.underline.italic('foo').toString()); | ||
}) | ||
.add('kleur', () => { | ||
names.forEach(name => kleur[name].bold.underline.italic('foo')); | ||
}) | ||
.run(); | ||
|
||
bench('Nested colors') | ||
.add('ansi-colors', () => fixture(color)) | ||
.add('chalk', () => fixture(chalk)) | ||
.add('clorox', () => fixture(clorox).toString()) | ||
.add('kleur', () => fixture(kleur)) | ||
.run(); | ||
|
||
function fixture(lib) { | ||
return lib.red(`a red ${lib.white('red')} red ${lib.red('red')} red ${lib.gray('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.blue('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')}red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')}red ${lib.green('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.magenta('red')} red ${lib.red('red')}red ${lib.red('red')} red ${lib.cyan('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.yellow('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} message`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const libs = { | ||
chalk: require('chalk'), | ||
clorox: require('clorox'), | ||
colors: require('ansi-colors'), | ||
kleur: require('..') | ||
}; | ||
|
||
const color = libs[process.argv[2] || 'kleur']; | ||
[ | ||
'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow', 'dim', 'gray', | ||
'bgBlack', 'bgBlue', 'bgCyan', 'bgGreen', 'bgMagenta', 'bgRed', 'bgWhite', 'bgYellow', | ||
'hidden', 'inverse', 'bold', 'italic', 'reset', 'strikethrough', 'underline' | ||
].forEach(str => { | ||
console.log(color[str]('~foobar~')); | ||
}); | ||
|
||
console.log(); | ||
console.log(color.bold(color.cyan('[info]')), color.cyan('This is some information')); | ||
console.log(color.bold(color.yellow('[warning]')), color.yellow('This is a warning')); | ||
console.log(color.bold(color.red('[ERROR]')), color.red('Danger! There was an error!')); | ||
console.log(); | ||
|
||
console.log(color.red(`a red ${color.white('white')} red ${color.red('red')} red ${color.gray('gray')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.blue('blue')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')}red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')}red ${color.green('green')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.magenta('red')} red ${color.red('red')}red ${color.red('red')} red ${color.cyan('cyan')} red ${color.red('red')} red ${color.red('red')} red ${color.yellow('yellow')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.blue('blue')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} message`).toString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./colors'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
console.time('ansi-colors'); | ||
const color = require('ansi-colors'); | ||
console.timeEnd('ansi-colors'); | ||
|
||
console.time('chalk'); | ||
const chalk = require('chalk'); | ||
console.timeEnd('chalk'); | ||
|
||
console.time('clorox'); | ||
const clorox = require('clorox'); | ||
console.timeEnd('clorox'); | ||
|
||
console.time('kleur'); | ||
const kleur = require('..'); | ||
console.timeEnd('kleur'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"private": true, | ||
"devDependencies": { | ||
"ansi": "^0.3.1", | ||
"ansi-colors": "^2.0.2", | ||
"benchmark": "^2.1.4", | ||
"chalk": "^2.4.0", | ||
"clorox": "^1.0.3" | ||
} | ||
} |