Created
December 10, 2018 19:11
-
-
Save sulco/e635a7511d5ff17d44fe9bb2ab8b3cc6 to your computer and use it in GitHub Desktop.
A clown formatter
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
window.devtoolsFormatters = [{ | |
header: function(obj){ | |
if (!obj.__clown) { | |
return null; | |
} | |
delete obj.__clown; | |
const style = ` | |
color: red; | |
border: dotted 2px gray; | |
border-radius: 4px; | |
padding: 5px; | |
` | |
const content = `🤡 ${JSON.stringify(obj, null, 2)}`; | |
try { | |
return ['div', {style}, content] | |
} catch (err) { // for circular structures | |
return null; // use the default formatter | |
} | |
}, | |
hasBody: function(){ | |
return false; | |
} | |
}] | |
console.clown = function (obj) { | |
console.log({...obj, __clown: true}); | |
} | |
console.log({message: 'hello!'}); // normal log | |
console.clown({message: 'hello!'}); // a silly log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice! I got it and shared it to my workmate, thank you very much!