fes.js/scripts/randomColor.mjs

36 lines
645 B
JavaScript
Raw Normal View History

2021-08-07 15:43:24 +08:00
/* eslint import/no-extraneous-dependencies: 0 */
import chalk from 'chalk';
2021-08-07 15:43:24 +08:00
const colors = [
'red',
'green',
'yellow',
'blue',
'magenta',
'cyan',
'gray',
'redBright',
'greenBright',
'yellowBright',
'blueBright',
'magentaBright',
2022-03-26 14:58:01 +08:00
'cyanBright',
2021-08-07 15:43:24 +08:00
];
let index = 0;
const cache = {};
export default function (pkg) {
2021-08-07 15:43:24 +08:00
if (!cache[pkg]) {
const color = colors[index];
const str = chalk[color].bold(pkg);
cache[pkg] = str;
if (index === colors.length - 1) {
index = 0;
} else {
index += 1;
}
}
return cache[pkg];
}