mirror of
https://github.com/debug-js/debug.git
synced 2026-01-18 16:12:38 +00:00
browser: even more robust "%c" handling
Now we support the user passing in their own "%c" fields in `debug()` calls.
This commit is contained in:
parent
9a282f9a41
commit
9b5e9f7ef2
@ -91,14 +91,18 @@ function log() {
|
||||
// arguments passed either before or after the %c, so we need to
|
||||
// figure out the correct index to insert the CSS into
|
||||
var index = 0;
|
||||
var lastC = 0;
|
||||
args[0].replace(/%[a-z%]/g, function(match) {
|
||||
if ('%%' === match) return;
|
||||
index++;
|
||||
if (index < 3) return; // skip the first 2 %c's since that's handled already
|
||||
if ('%c' === match) {
|
||||
args.splice(index, 0, c);
|
||||
// we only are interested in the *last* %c
|
||||
// (the user may have provided their own)
|
||||
lastC = index;
|
||||
}
|
||||
});
|
||||
|
||||
args.splice(lastC, 0, c);
|
||||
}
|
||||
|
||||
// This hackery is required for IE8,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user