Skip to content

Commit c48ba79

Browse files
committed
Fixes bad align in colored level.
Signed-off-by: Eric Wang <[email protected]>
1 parent 3fa1fb1 commit c48ba79

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Diff for: lib/helper.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ h.prettyTime = function(n) {
8989

9090
h.prettyLevel = function(level) {
9191
var chalk = require('./chalk');
92-
switch (level) {
93-
case 'Easy': return chalk.green('Easy');
94-
case 'Medium': return chalk.yellow('Medium');
95-
case 'Hard': return chalk.red('Hard');
96-
default: return ' ';
92+
switch (level.toLowerCase()) {
93+
case 'easy': return chalk.green(level + ' ');
94+
case 'medium': return chalk.yellow(level);
95+
case 'hard': return chalk.red(level + ' ');
96+
default: return level;
9797
}
9898
};
9999

Diff for: test/test_helper.js

+14
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ describe('helper', function() {
4646
});
4747
}); // #prettyText
4848

49+
describe('#prettyLevel', function() {
50+
it('should ok w/ color', function() {
51+
chalk.enabled = true;
52+
53+
assert.equal(h.prettyLevel('Easy'), chalk.green('Easy '));
54+
assert.equal(h.prettyLevel('Medium'), chalk.yellow('Medium'));
55+
assert.equal(h.prettyLevel('Hard'), chalk.red('Hard '));
56+
assert.equal(h.prettyLevel('easy'), chalk.green('easy '));
57+
assert.equal(h.prettyLevel('medium'), chalk.yellow('medium'));
58+
assert.equal(h.prettyLevel('hard'), chalk.red('hard '));
59+
assert.equal(h.prettyLevel('unknown'), 'unknown');
60+
});
61+
}); // #prettyLevel
62+
4963
describe('#prettySize', function() {
5064
it('should ok', function() {
5165
assert.equal(h.prettySize(0), '0.00B');

0 commit comments

Comments
 (0)