UNPKG

561 BJavaScriptView Raw
1const chalk = require('chalk');
2
3const {
4 isObjectLike,
5} = require('lodash');
6
7const {
8 jsonStringify,
9} = require('./jsonOp');
10
11const colors = require('./color');
12
13/**
14 * 生成带 color 颜色的字串 str
15 */
16const 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 */
27Object.entries(colors).forEach(([name, color]) => {
28 exports[name] = str => createColorStr(str, color);
29});