* Colorize log arguments if enabled. * * @api public
()
| 367 | */ |
| 368 | |
| 369 | function formatArgs() { |
| 370 | var args = arguments; |
| 371 | var useColors = this.useColors; |
| 372 | |
| 373 | args[0] = (useColors ? '%c' : '') |
| 374 | + this.namespace |
| 375 | + (useColors ? ' %c' : ' ') |
| 376 | + args[0] |
| 377 | + (useColors ? '%c ' : ' ') |
| 378 | + '+' + exports.humanize(this.diff); |
| 379 | |
| 380 | if (!useColors) return args; |
| 381 | |
| 382 | var c = 'color: ' + this.color; |
| 383 | args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1)); |
| 384 | |
| 385 | // the final "%c" is somewhat tricky, because there could be other |
| 386 | // arguments passed either before or after the %c, so we need to |
| 387 | // figure out the correct index to insert the CSS into |
| 388 | var index = 0; |
| 389 | var lastC = 0; |
| 390 | args[0].replace(/%[a-z%]/g, function(match) { |
| 391 | if ('%%' === match) return; |
| 392 | index++; |
| 393 | if ('%c' === match) { |
| 394 | // we only are interested in the *last* %c |
| 395 | // (the user may have provided their own) |
| 396 | lastC = index; |
| 397 | } |
| 398 | }); |
| 399 | |
| 400 | args.splice(lastC, 0, c); |
| 401 | return args; |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Invokes `console.log()` when available. |