UNPKG

860 BJavaScriptView Raw
1///@ts-check
2"use strict";
3const colors = require('ansi-colors');
4
5const availableColors = [
6 "cyanBright",
7 "magentaBright",
8 "greenBright",
9 "blueBright",
10 // "yellowBright",
11 // "whiteBright",
12 // "gray",
13 // "yellow",
14 "cyan",
15 "green",
16 "blue",
17 // "magenta", // cannot display in power shell
18];
19
20const availableStyle = [
21 "reset",
22 // "bold",
23 "italic",
24 "dim",
25 // "underline",
26]
27const maps = {}
28
29let index = 0;
30
31/**
32 *
33 * @param {string} str
34 * @returns {string}
35 */
36function color(str) {
37 str = str && str.trim();
38 if (!maps[str]) {
39 maps[str] = colors.gray.dim(index+'.')+colors
40 .reset
41 [availableStyle[index % availableStyle.length]]
42 [availableColors[index++ % availableColors.length]]
43 .bold(str);
44 }
45 return maps[str];
46}
47
48module.exports = color;
\No newline at end of file