Skip to content

Instantly share code, notes, and snippets.

@GalindoSVQ
Last active October 3, 2022 11:57
Show Gist options
  • Save GalindoSVQ/a0c8752733c649fa3d4ed99e13abe6ff to your computer and use it in GitHub Desktop.
Save GalindoSVQ/a0c8752733c649fa3d4ed99e13abe6ff to your computer and use it in GitHub Desktop.
const bgColor: Record<string, string> = {
Warning: 'orange',
Error: 'red',
Success: 'green',
}
type msgType = keyof typeof bgColor;
function createPrintLog(type: msgType) {
return function log(str: string) {
return console.log(`%c ${type}: ${str} `, `background: ${bgColor[type]}; color: white`);
}
}
const warning = createPrintLog("Warning")
const error = createPrintLog("Error")
const success = createPrintLog("Success")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment