Skip to content

Instantly share code, notes, and snippets.

@marianocordoba
Last active January 24, 2020 15:03
Show Gist options
  • Save marianocordoba/6cd6e9df6bbd8c7136c09c457e18d9a9 to your computer and use it in GitHub Desktop.
Save marianocordoba/6cd6e9df6bbd8c7136c09c457e18d9a9 to your computer and use it in GitHub Desktop.
Print a shield to the console

Print a shield to the console.

Example
console.shield('Version', '1.0.0')

Version 1.0.0

console.shield('Version', '1.0.0', { labelBackgroundColor: '#ff0000', messageBackgroundColor: '#fafafa', messageTextColor: '#222' })

Version 1.0.0

(console.shield = (label, message, options = {}) => {
const {
labelBackgroundColor,
messageBackgroundColor,
labelTextColor,
messageTextColor
} = Object.assign({
labelBackgroundColor: '#555',
messageBackgroundColor: '#97ca00',
labelTextColor: '#fff',
messageTextColor: '#fff'
}, options)
console.log(
`%c ${label} %c ${message} %c`,
`background:${labelBackgroundColor} ; padding: 1px; border-radius: 3px 0 0 3px; color: ${labelTextColor}`,
`background:${messageBackgroundColor} ; padding: 1px; border-radius: 0 3px 3px 0; color: ${messageTextColor}`,
'background:transparent'
)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment