Skip to content

Commit 9e33afb

Browse files
committed
Add flow checks for chalk
1 parent 9fc1ba2 commit 9e33afb

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

lib/chalk.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
'use strict';
2+
// @flow
23
const supportsColor = require('./supports-color');
34

45
// Find more colors/styles in
56
// https://github.com/chalk/ansi-styles/blob/main/index.js
6-
const colors = {
7-
blue: { open: '\x1B[34m', close: '\x1B[39m' },
8-
red: { open: '\x1B[31m', close: '\x1B[39m' },
9-
};
10-
11-
const chalk = { supportsColor };
127

13-
for (const [styleName, style] of Object.entries(colors)) {
14-
chalk[styleName] = (string) => {
15-
if (!supportsColor || !string) {
16-
return string;
17-
}
8+
function red(string /*: string */) /*: string */ {
9+
return supportsColor ? `\x1B[31m${string}\x1B[39m` : string;
10+
}
1811

19-
return style.open + string + style.close;
20-
};
12+
function blue(string /*: string */) /*: string */ {
13+
return supportsColor ? `\x1B[34m${string}\x1B[39m` : string;
2114
}
2215

23-
module.exports = chalk;
16+
module.exports = {
17+
supportsColor,
18+
19+
red,
20+
blue,
21+
};

0 commit comments

Comments
 (0)