ciallorize
Version:
Ciallorize your bundled js into ascii art.
66 lines (56 loc) • 2.1 kB
JavaScript
function rainbowText(text) {
// ANSI 颜色代码数组 (红、黄、绿、蓝、紫、青)
const colors = [
'\x1b[38;5;204m', // 粉红
'\x1b[38;5;221m', // 浅黄
'\x1b[38;5;114m', // 浅绿
'\x1b[38;5;117m', // 浅蓝
'\x1b[38;5;183m', // 淡紫
'\x1b[38;5;211m' // 浅橙
];
const reset = '\x1b[0m';
let result = '';
for (let i = 0; i < text.length; i++) {
const color = colors[i % colors.length];
result += `${color}${text[i]}`;
}
return result + reset;
}
function y2kCoolRainbow(text) {
// Y2K科技感冷色调色表:蓝绿青紫为主,带一点未来感荧光色
const y2kColors = [
'\x1b[38;5;45m', // 电子蓝
'\x1b[38;5;51m', // 荧光青
'\x1b[38;5;87m', // 霓虹蓝
'\x1b[38;5;123m', // 海水蓝
'\x1b[38;5;159m', // 浅海蓝
'\x1b[38;5;122m', // 绿松石
'\x1b[38;5;86m', // 蓝绿色
'\x1b[38;5;44m', // 深水蓝
'\x1b[38;5;105m', // 紫晶色
'\x1b[38;5;141m', // 淡紫色
'\x1b[38;5;147m', // 薰衣草灰
'\x1b[38;5;153m' // 冰蓝色
];
const reset = '\x1b[0m';
let result = '';
// 添加一点Y2K风格的随机闪烁感
const getRandomColor = () => y2kColors[Math.floor(Math.random() * y2kColors.length)];
for (let i = 0; i < text.length; i++) {
// 70%概率使用顺序色,30%概率随机跳色增加Y2K数字感
const color = Math.random() > 0.3 ? y2kColors[i % y2kColors.length] : getRandomColor();
result += `${color}${text[i]}`;
}
return result + reset;
}
const ciallorize = rainbowText('Ciallorize');
const bar = y2kCoolRainbow('-'.repeat(54))
module.exports = (phase) => {
console.error(bar)
console.error(' '+ciallorize+` failed to parse during [${phase}] phase`)
console.error(' '+ciallorize+` does not guarantee to properly handle any`)
console.error(` code, please try another one.`)
console.error(bar)
}
module.exports['rainbowText'] = rainbowText
module.exports['y2kCoolRainbow'] = y2kCoolRainbow