Skip to content

Commit 42c8fea

Browse files
committed
fix: Replace colors with chalk.
1 parent 90c7438 commit 42c8fea

13 files changed

+115
-86
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cli-table3
1+
cli-table3
22
===============================================================================
33

44
[![npm version](https://img.shields.io/npm/v/cli-table3.svg)](https://www.npmjs.com/package/cli-table3)
@@ -30,7 +30,7 @@ unmaintained. `cli-table3` includes all the additional features from
3030

3131
- Customizable characters that constitute the table.
3232
- Color/background styling in the header through
33-
[colors.js](https://github.com/marak/colors.js)
33+
[chalk](https://github.com/chalk/chalk)
3434
- Column width customization
3535
- Text truncation based on predefined widths
3636
- Text alignment (left, right, center)

advanced-usage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
```javascript
242242
var table = new Table({colWidths:[5],style:{head:[],border:[]}});
243243

244-
table.push([colors.red('hello')]);
244+
table.push([chalk.red('hello')]);
245245

246246
```
247247

basic-usage.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@
110110
```
111111

112112

113-
##### Use ansi colors (i.e. colors.js) to style text within the cells at will, even across multiple lines
113+
##### Use ansi colors (i.e. chalk) to style text within the cells at will, even across multiple lines
114114
![table image](./examples/screenshots/multi-line-colors.png)
115115
```javascript
116116
var table = new Table({style:{border:[],header:[]}});
117117

118118
table.push([
119-
colors.red('Hello\nhow\nare\nyou?'),
120-
colors.blue('I\nam\nfine\nthanks!')
119+
chalk.red('Hello\nhow\nare\nyou?'),
120+
chalk.blue('I\nam\nfine\nthanks!')
121121
]);
122122

123123
```

examples/basic-usage-examples.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Table = require('../src/table');
2-
const colors = require('colors/safe');
2+
const chalk = require('chalk');
33

44
module.exports = function (runTest) {
55
function it(name, fn) {
@@ -18,11 +18,11 @@ module.exports = function (runTest) {
1818
}
1919

2020
let expected = [
21-
colors.gray('┌───') + colors.gray('┬───┐'),
22-
colors.gray('│') + colors.red(' a ') + colors.gray('│') + colors.red(' b ') + colors.gray('│'),
23-
colors.gray('├───') + colors.gray('┼───┤'),
24-
colors.gray('│') + ' c ' + colors.gray('│') + ' d ' + colors.gray('│'),
25-
colors.gray('└───') + colors.gray('┴───┘'),
21+
chalk.gray('┌───') + chalk.gray('┬───┐'),
22+
chalk.gray('│') + chalk.red(' a ') + chalk.gray('│') + chalk.red(' b ') + chalk.gray('│'),
23+
chalk.gray('├───') + chalk.gray('┼───┤'),
24+
chalk.gray('│') + ' c ' + chalk.gray('│') + ' d ' + chalk.gray('│'),
25+
chalk.gray('└───') + chalk.gray('┴───┘'),
2626
];
2727

2828
return [makeTable, expected, 'basic-usage-with-colors'];
@@ -152,21 +152,21 @@ module.exports = function (runTest) {
152152
return [makeTable, expected];
153153
});
154154

155-
it('Use ansi colors (i.e. colors.js) to style text within the cells at will, even across multiple lines', function () {
155+
it('Use ansi colors (i.e. chalk) to style text within the cells at will, even across multiple lines', function () {
156156
function makeTable() {
157157
let table = new Table({ style: { border: [], header: [] } });
158158

159-
table.push([colors.red('Hello\nhow\nare\nyou?'), colors.blue('I\nam\nfine\nthanks!')]);
159+
table.push([chalk.red('Hello\nhow\nare\nyou?'), chalk.blue('I\nam\nfine\nthanks!')]);
160160

161161
return table;
162162
}
163163

164164
let expected = [
165165
'┌───────┬─────────┐',
166-
'│ ' + colors.red('Hello') + ' │ ' + colors.blue('I') + ' │',
167-
'│ ' + colors.red('how') + ' │ ' + colors.blue('am') + ' │',
168-
'│ ' + colors.red('are') + ' │ ' + colors.blue('fine') + ' │',
169-
'│ ' + colors.red('you?') + ' │ ' + colors.blue('thanks!') + ' │',
166+
'│ ' + chalk.red('Hello') + ' │ ' + chalk.blue('I') + ' │',
167+
'│ ' + chalk.red('how') + ' │ ' + chalk.blue('am') + ' │',
168+
'│ ' + chalk.red('are') + ' │ ' + chalk.blue('fine') + ' │',
169+
'│ ' + chalk.red('you?') + ' │ ' + chalk.blue('thanks!') + ' │',
170170
'└───────┴─────────┘',
171171
];
172172

examples/col-and-row-span-examples.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Table = require('../src/table');
2-
const colors = require('colors/safe');
2+
const chalk = require('chalk');
33

44
module.exports = function (runTest) {
55
function it(name, fn) {
@@ -290,12 +290,12 @@ module.exports = function (runTest) {
290290
style: { head: [], border: [] },
291291
});
292292

293-
table.push([colors.red('hello')]);
293+
table.push([chalk.red('hello')]);
294294

295295
return table;
296296
}
297297

298-
let expected = ['┌─────┐', '│ ' + colors.red('he') + '… │', '└─────┘'];
298+
let expected = ['┌─────┐', '│ ' + chalk.red('he') + '… │', '└─────┘'];
299299

300300
return [makeTable, expected, 'truncation-with-colors'];
301301
});

lib/print-example.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* eslint-env jest */
22
/* eslint-disable no-console */
33

4-
const colors = require('colors/safe');
4+
const chalk = require('chalk');
55
const fs = require('fs');
66

77
function logExample(fn) {
88
runPrintingExample(
99
fn,
1010
function logName(name) {
11-
console.log(colors.gray('========= ') + name + colors.gray(' ================'));
11+
console.log(chalk.gray('========= ') + name + chalk.gray(' ================'));
1212
},
1313
console.log, //logTable
1414
console.log, //logCode

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"devDependencies": {
1919
"ansi-256-colors": "^1.1.0",
20+
"chalk": "^4.1.2",
2021
"cli-table": "^0.3.1",
2122
"eslint-config-prettier": "^6.0.0",
2223
"eslint-plugin-prettier": "^3.0.0",
@@ -26,7 +27,7 @@
2627
"prettier": "2.3.2"
2728
},
2829
"optionalDependencies": {
29-
"colors": "1.4.0"
30+
"chalk": "^4.1.2"
3031
},
3132
"scripts": {
3233
"changelog": "lerna-changelog",

src/cell.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ class Cell {
186186
wrapWithStyleColors(styleProperty, content) {
187187
if (this[styleProperty] && this[styleProperty].length) {
188188
try {
189-
let colors = require('colors/safe');
189+
let chalk = require('chalk');
190190
for (let i = this[styleProperty].length - 1; i >= 0; i--) {
191-
colors = colors[this[styleProperty][i]];
191+
chalk = chalk[this[styleProperty][i]];
192192
}
193-
return colors(content);
193+
return chalk(content);
194194
} catch (e) {
195195
return content;
196196
}

test/cell-test.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
describe('Cell', function () {
2-
const colors = require('colors');
2+
const chalk = require('chalk');
33
const Cell = require('../src/cell');
44
const { ColSpanCell, RowSpanCell } = Cell;
55
const { mergeOptions } = require('../src/utils');
66

7+
chalk.level = 3;
8+
79
function defaultOptions() {
810
//overwrite coloring of head and border by default for easier testing.
911
return mergeOptions({ style: { head: [], border: [] } });
@@ -603,7 +605,7 @@ describe('Cell', function () {
603605

604606
it('will draw in the color specified by border style', function () {
605607
cell.border = ['gray'];
606-
expect(cell.draw('top')).toEqual(colors.gray('┌───────'));
608+
expect(cell.draw('top')).toEqual(chalk.gray('┌───────'));
607609
});
608610
});
609611

@@ -626,7 +628,7 @@ describe('Cell', function () {
626628

627629
it('will draw in the color specified by border style', function () {
628630
cell.border = ['gray'];
629-
expect(cell.draw('bottom')).toEqual(colors.gray('└───────'));
631+
expect(cell.draw('bottom')).toEqual(chalk.gray('└───────'));
630632
});
631633
});
632634

@@ -639,8 +641,8 @@ describe('Cell', function () {
639641
it('draws an empty line', function () {
640642
cell.border = ['gray'];
641643
cell.head = ['red'];
642-
expect(cell.drawEmpty()).toEqual(colors.gray('L') + colors.red(' '));
643-
expect(cell.drawEmpty(true)).toEqual(colors.gray('L') + colors.red(' ') + colors.gray('R'));
644+
expect(cell.drawEmpty()).toEqual(chalk.gray('L') + chalk.red(' '));
645+
expect(cell.drawEmpty(true)).toEqual(chalk.gray('L') + chalk.red(' ') + chalk.gray('R'));
644646
});
645647
});
646648

@@ -682,17 +684,17 @@ describe('Cell', function () {
682684
it('left and right will be drawn in color of border style', function () {
683685
cell.border = ['gray'];
684686
cell.x = 0;
685-
expect(cell.draw(0)).toEqual(colors.gray('L') + ' hello ');
687+
expect(cell.draw(0)).toEqual(chalk.gray('L') + ' hello ');
686688
cell.drawRight = true;
687-
expect(cell.draw(0)).toEqual(colors.gray('L') + ' hello ' + colors.gray('R'));
689+
expect(cell.draw(0)).toEqual(chalk.gray('L') + ' hello ' + chalk.gray('R'));
688690
});
689691

690692
it('text will be drawn in color of head style if y == 0', function () {
691693
cell.head = ['red'];
692694
cell.x = cell.y = 0;
693-
expect(cell.draw(0)).toEqual('L' + colors.red(' hello '));
695+
expect(cell.draw(0)).toEqual('L' + chalk.red(' hello '));
694696
cell.drawRight = true;
695-
expect(cell.draw(0)).toEqual('L' + colors.red(' hello ') + 'R');
697+
expect(cell.draw(0)).toEqual('L' + chalk.red(' hello ') + 'R');
696698
});
697699

698700
it('text will NOT be drawn in color of head style if y == 1', function () {
@@ -707,9 +709,9 @@ describe('Cell', function () {
707709
cell.border = ['gray'];
708710
cell.head = ['red'];
709711
cell.x = cell.y = 0;
710-
expect(cell.draw(0)).toEqual(colors.gray('L') + colors.red(' hello '));
712+
expect(cell.draw(0)).toEqual(chalk.gray('L') + chalk.red(' hello '));
711713
cell.drawRight = true;
712-
expect(cell.draw(0)).toEqual(colors.gray('L') + colors.red(' hello ') + colors.gray('R'));
714+
expect(cell.draw(0)).toEqual(chalk.gray('L') + chalk.red(' hello ') + chalk.gray('R'));
713715
});
714716
});
715717

test/table-test.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
describe('@api Table ', function () {
22
const Table = require('..');
3-
const colors = require('colors/safe');
3+
const chalk = require('chalk');
4+
5+
chalk.level = 3;
46

57
it('wordWrap with colored text', function () {
68
let table = new Table({ style: { border: [], head: [] }, wordWrap: true, colWidths: [7, 9] });
79

8-
table.push([colors.red('Hello how are you?'), colors.blue('I am fine thanks!')]);
10+
table.push([chalk.red('Hello how are you?'), chalk.blue('I am fine thanks!')]);
911

1012
let expected = [
1113
'┌───────┬─────────┐',
12-
'│ ' + colors.red('Hello') + ' │ ' + colors.blue('I am') + ' │',
13-
'│ ' + colors.red('how') + ' │ ' + colors.blue('fine') + ' │',
14-
'│ ' + colors.red('are') + ' │ ' + colors.blue('thanks!') + ' │',
15-
'│ ' + colors.red('you?') + ' │ │',
14+
'│ ' + chalk.red('Hello') + ' │ ' + chalk.blue('I am') + ' │',
15+
'│ ' + chalk.red('how') + ' │ ' + chalk.blue('fine') + ' │',
16+
'│ ' + chalk.red('are') + ' │ ' + chalk.blue('thanks!') + ' │',
17+
'│ ' + chalk.red('you?') + ' │ │',
1618
'└───────┴─────────┘',
1719
];
1820

0 commit comments

Comments
 (0)