Skip to content

Commit 8b2157c

Browse files
committed
chore: migrate from chalk to stdlib
1 parent c0851fa commit 8b2157c

File tree

6 files changed

+33
-30
lines changed

6 files changed

+33
-30
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ For the list of available translations, please refer to the main [tldr](https://
6262

6363
You can configure the `tldr` client by adding a `.tldrrc` file in your HOME directory. You can copy the contents of the `config.json` file from the repo to get the basic structure to start with, and modify it to suit your needs.
6464

65-
The default color theme is the one named `"simple"`. You can change the theme by assigning a different value to the `"theme"` variable -- either to one of the pre-configured themes, or to a new theme that you have previously created in the `"themes"` section. Note that the colors and text effects you can choose are limited. Refer to the [chalk documentation](https://github.com/chalk/chalk#styles) for all options.
65+
The default color theme is the one named `"simple"`. You can change the theme by assigning a different value to the `"theme"` variable -- either to one of the pre-configured themes, or to a new theme that you have previously created in the `"themes"` section. Note that the colors and text effects you can choose are limited. Refer to the [Node.js documentation](https://nodejs.org/api/util.html#modifiers) for all options.
6666

6767
```json
6868
{

lib/parser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3+
const { styleText } = require('node:util');
34
const unescape = require('lodash/unescape');
45
const marked = require('marked');
5-
const chalk = require('chalk');
66
const index = require('./index');
77

88
const allElements = [
@@ -70,11 +70,11 @@ exports.parse = (markdown) => {
7070
};
7171

7272
r.strong = (text) => {
73-
return chalk.bold(text);
73+
return styleText('bold', text);
7474
};
7575

7676
r.em = (text) => {
77-
return chalk.italic(text);
77+
return styleText('italic', text);
7878
};
7979

8080
r.listitem = (text) => {

lib/theme.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
'use strict';
22

3-
const get = require('lodash/get');
43
const isEmpty = require('lodash/isEmpty');
54
const identity = require('lodash/identity');
6-
const chalk = require('chalk');
5+
const { styleText } = require('node:util');
76

87
// Translates strings like 'red, underline, bold'
9-
// into function chalk.red.underline.bold(text)
8+
// into function styleText(['red', 'underline', 'bold'], text)
109
function buildStylingFunction(styles) {
1110
if (isEmpty(styles)) {
1211
return identity;
1312
}
14-
let stylingFunction = chalk;
15-
let stylesPath = styles.replace(/,\s*/g, '.');
16-
return get(stylingFunction, stylesPath);
13+
14+
let stylesArr = styles.split(/,\s*/g);
15+
return (text) => styleText(stylesArr, text);
1716
}
1817

1918
class Theme {

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"dependencies": {
6060
"adm-zip": "^0.5.10",
6161
"axios": "^1.6.0",
62-
"chalk": "^4.1.0",
6362
"commander": "^6.1.0",
6463
"fs-extra": "^11.2.0",
6564
"glob": "^11.0.0",

test/theme.spec.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3+
const { styleText } = require('node:util');
34
const Theme = require('../lib/theme');
4-
const chalk = require('chalk');
55

66
describe('Theme', () => {
77

@@ -18,31 +18,31 @@ describe('Theme', () => {
1818
it('should render name with green and bold', () => {
1919
theme.renderCommandName('text')
2020
.should.equal(
21-
chalk.green.bold('text'));
21+
styleText(['green', 'bold'], 'text'));
2222
});
2323

2424
it('should render description with red and underline', () => {
2525
theme.renderMainDescription('text')
2626
.should.equal(
27-
chalk.red.underline('text'));
27+
styleText(['red', 'underline'], 'text'));
2828
});
2929

3030
it('should render example description with blue', () => {
3131
theme.renderExampleDescription('text')
3232
.should.equal(
33-
chalk.blue('text'));
33+
styleText('blue', 'text'));
3434
});
3535

3636
it('should render example code with blue', () => {
3737
theme.renderExampleCode('text')
3838
.should.equal(
39-
chalk.bold('text'));
39+
styleText('bold', 'text'));
4040
});
4141

4242
it('should render example argument with yellow, dim, underline', () => {
4343
theme.renderExampleToken('text')
4444
.should.equal(
45-
chalk.yellow.dim.underline('text'));
45+
styleText(['yellow', 'dim', 'underline'], 'text'));
4646
});
4747
});
4848

@@ -59,31 +59,31 @@ describe('Theme', () => {
5959
it('should render name with greenBright and bold', () => {
6060
theme.renderCommandName('text')
6161
.should.equal(
62-
chalk.greenBright.bold('text'));
62+
styleText(['greenBright', 'bold'], 'text'));
6363
});
6464

6565
it('should render description with greenBright and bold', () => {
6666
theme.renderMainDescription('text')
6767
.should.equal(
68-
chalk.greenBright.bold('text'));
68+
styleText(['greenBright', 'bold'], 'text'));
6969
});
7070

7171
it('should render example description with greenBright', () => {
7272
theme.renderExampleDescription('text')
7373
.should.equal(
74-
chalk.greenBright('text'));
74+
styleText('greenBright', 'text'));
7575
});
7676

7777
it('should render example code with redBright', () => {
7878
theme.renderExampleCode('text')
7979
.should.equal(
80-
chalk.redBright('text'));
80+
styleText('redBright', 'text'));
8181
});
8282

8383
it('should render example argument with white', () => {
8484
theme.renderExampleToken('text')
8585
.should.equal(
86-
chalk.white('text'));
86+
styleText('white', 'text'));
8787
});
8888
});
8989

@@ -102,37 +102,37 @@ describe('Theme', () => {
102102
it('should render name with greenBright and bold', () => {
103103
theme.renderCommandName('text')
104104
.should.equal(
105-
chalk.greenBright.bold('text'));
105+
styleText(['greenBright', 'bold'], 'text'));
106106
});
107107

108108
it('should render description with greenBright and bold', () => {
109109
theme.renderMainDescription('text')
110110
.should.equal(
111-
chalk.greenBright.bold('text'));
111+
styleText(['greenBright', 'bold'], 'text'));
112112
});
113113

114114
it('should render example description with greenBright', () => {
115115
theme.renderExampleDescription('text')
116116
.should.equal(
117-
chalk.greenBright('text'));
117+
styleText('greenBright', 'text'));
118118
});
119119

120120
it('should render example code with redBright', () => {
121121
theme.renderExampleCode('text')
122122
.should.equal(
123-
chalk.redBright('text'));
123+
styleText('redBright', 'text'));
124124
});
125125

126126
it('should render example arguments with magenta, white, and blue, for boolean, number, and string respectively', () => {
127127
theme.renderExampleToken('true')
128128
.should.equal(
129-
chalk.magenta('true'));
129+
styleText('magenta', 'true'));
130130
theme.renderExampleToken('9')
131131
.should.equal(
132-
chalk.white('9'));
132+
styleText('white', '9'));
133133
theme.renderExampleToken('text')
134134
.should.equal(
135-
chalk.blue('text'));
135+
styleText('blue', 'text'));
136136
});
137137
});
138138
});

0 commit comments

Comments
 (0)