modernirc
Version:
IRC library for creating modern IRC bots
142 lines (133 loc) • 2.38 kB
JavaScript
/**
* Utility functions for text formatting
*/
export const Colors = {
White: '00',
Black: '01',
Blue: '02',
Green: '03',
Red: '04',
Brown: '05',
Magenta: '06',
Orange: '07',
Yellow: '08',
LightGreen: '09',
Cyan: '10',
LightCyan: '11',
LightBlue: '12',
Pink: '13',
Grey: '14',
LightGrey: '15',
Ansi52: '16',
Ansi94: '17',
Ansi100: '18',
Ansi58: '19',
Ansi22: '20',
Ansi29: '21',
Ansi23: '22',
Ansi24: '23',
Ansi17: '24',
Ansi54: '25',
Ansi53: '26',
Ansi89: '27',
Ansi88: '28',
Ansi130: '29',
Ansi142: '30',
Ansi64: '31',
Ansi28: '32',
Ansi35: '33',
Ansi30: '34',
Ansi25: '35',
Ansi18: '36',
Ansi91: '37',
Ansi90: '38',
Ansi125: '39',
Ansi124: '40',
Ansi166: '41',
Ansi184: '42',
Ansi106: '43',
Ansi34: '44',
Ansi49: '45',
Ansi37: '46',
Ansi33: '47',
Ansi19: '48',
Ansi129: '49',
Ansi127: '50',
Ansi161: '51',
Ansi196: '52',
Ansi208: '53',
Ansi226: '54',
Ansi154: '55',
Ansi46: '56',
Ansi86: '57',
Ansi51: '58',
Ansi75: '59',
Ansi21: '60',
Ansi171: '61',
Ansi201: '62',
Ansi198: '63',
Ansi203: '64',
Ansi215: '65',
Ansi227: '66',
Ansi191: '67',
Ansi83: '68',
Ansi122: '69',
Ansi87: '70',
Ansi111: '71',
Ansi63: '72',
Ansi177: '73',
Ansi207: '74',
Ansi205: '75',
Ansi217: '76',
Ansi223: '77',
Ansi229: '78',
Ansi193: '79',
Ansi157: '80',
Ansi158: '81',
Ansi159: '82',
Ansi153: '83',
Ansi147: '84',
Ansi183: '85',
Ansi219: '86',
Ansi212: '87',
Ansi16: '88',
Ansi233: '89',
Ansi235: '90',
Ansi237: '91',
Ansi239: '92',
Ansi241: '93',
Ansi244: '94',
Ansi247: '95',
Ansi250: '96',
Ansi254: '97',
Ansi231: '98',
}
export function bold(text) {
return `\x02${text}\x02`
}
export function italic(text) {
return `\x1D${text}\x1D`
}
export function underline(text) {
return `\x1F${text}\x1F`
}
export function strikethrough(text) {
return `\x1E${text}\x1E`
}
export function monospace(text) {
return `\x11${text}\x11`
}
export function color(text, foreground, background = null) {
let result = `\x03${foreground}`
if (background !== null) {
result += `,${background}`
}
result += `${text}\x03`
return result
}
export function hexColor(text, rgb) {
if (typeof rgb !== 'string' || rgb.length !== 6) {
return text
}
return `\x04${rgb}${text}\x04`
}