Last active
January 12, 2023 06:07
-
-
Save luislobo14rap/67a22e55400b99e2f3a2fc74de112ce5 to your computer and use it in GitHub Desktop.
log-css.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// log-css.js v2 | |
const log = console.log.bind() | |
const css = (text, options) => { | |
let cssOptions = '' | |
for (let prop in options) { | |
const value = options[prop] | |
prop = camelCaseToDashCase(prop) | |
cssOptions += `${prop}: ${value}; ` | |
} | |
return [`%c${text}`, cssOptions.trim()] | |
function camelCaseToDashCase(value) { | |
return value.replace(/[A-Z]/g, matched => `-${matched.toLowerCase()}`) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// log-css.js v1.1 | |
const log = console.log.bind(); | |
const css = function(item, color = '#fff', background = 'none', fontSize = '12px', fontWeight = 700, fontFamily) { | |
return ['%c' + item, 'color:' + color + ';background:' + background + ';font-size:' + fontSize + ';font-weight:' + fontWeight + (fontFamily ? ';font-family:' + fontFamily : '')]; | |
}; |
Example v2:
log(...css('Example =P', {
backgroundColor: 'blue',
color: 'white',
fontFamily: 'Consolas',
fontSize: '25px',
fontWeight: '700',
lineHeight: '20px',
padding: '7px 7px'
}))
Example v2:
log(...css('asduhasudha', {'font-size': '20px', backgroundColor: 'rebeccapurple', color: '#fff', 'padding': '0.2rem'}))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// example
log(...css('TEXT', 'rebeccapurple', '#000', '14px'));