1 | const chalk = require('chalk');
|
2 |
|
3 | const {
|
4 | isObjectLike,
|
5 | } = require('lodash');
|
6 |
|
7 | const {
|
8 | jsonStringify,
|
9 | } = require('./jsonOp');
|
10 |
|
11 | const colors = require('./color');
|
12 |
|
13 | /**
|
14 | * 生成带 color 颜色的字串 str
|
15 | */
|
16 | const createColorStr = (str, color) => {
|
17 | if (isObjectLike(str)) {
|
18 | str = jsonStringify(str);
|
19 | }
|
20 | return chalk.hex(color)(str);
|
21 | };
|
22 |
|
23 | /**
|
24 | * 暴露出去带颜色的字符串
|
25 | * red|blue|green|yellow|cyan|grey|pink|orange|purple
|
26 | */
|
27 | Object.entries(colors).forEach(([name, color]) => {
|
28 | exports[name] = str => createColorStr(str, color);
|
29 | });
|