import get from 'lodash.get' ; import { Severity , Color , ColorCode } from 'src/types' ; const RESET = '\x1b[0m' as const ; const COLORS = < const > { reset : { fg : '\x1b[0m' , bg : '\x1b[0m' , } , black : { fg : '\x1b[30m' , bg : '\x1b[40m' , } , red : { fg : '\x1b[31m' , bg : '\x1b[41m' , } , green : { fg : '\x1b[32m' , bg : '\x1b[42m' , } , yellow : { fg : '\x1b[33m' , bg : '\x1b[43m' , } , blue : { fg : '\x1b[34m' , bg : '\x1b[44m' , } , magenta : { fg : '\x1b[35m' , bg : '\x1b[45m' , } , cyan : { fg : '\x1b[36m' , bg : '\x1b[46m' , } , white : { fg : '\x1b[37m' , bg : '\x1b[47m' , } , } ; param { String } message param { String } fgColor param { String } bgColor return { String } export function color ( message , fgColor ? , bgColor ? ) { return [ < ColorCode > get ( COLORS , `${ fgColor }.fg` , '' ) , < ColorCode > get ( COLORS , `${ bgColor }.bg` , '' ) , message , < ColorCode > RESET , ] . join ( '' ) ; } param { String } severity return { ( String | undefined ) } export function getSeverityBgColor ( severity ) { switch ( severity ) { case 'info' : return undefined ; case 'low' : return undefined ; case 'moderate' : return undefined ; case 'high' : return 'red' ; case 'critical' : return 'red' ; default : { const exhaustiveCheck = severity ; return exhaustiveCheck ; } } }