Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save OlivierPerceboisGarve/5dd73333e9c8d94ebd5a to your computer and use it in GitHub Desktop.
Save OlivierPerceboisGarve/5dd73333e9c8d94ebd5a to your computer and use it in GitHub Desktop.
console.highlight = function(text, sample) {
var escapedSample = sample.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
var reSample = new RegExp(escapedSample, 'g');
var args = [''];
var highlightedText = text.replace(reSample, function(match) {
args.push('background-color: #ffc', 'background-color: none');
return '%c' + match + '%c';
});
args[0] = highlightedText;
console.log.apply(console, args);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment