* Colorize log arguments if enabled. * * @api public
(args)
| 147 | */ |
| 148 | |
| 149 | function formatArgs(args) { |
| 150 | args[0] = (this.useColors ? '%c' : '') + |
| 151 | this.namespace + |
| 152 | (this.useColors ? ' %c' : ' ') + |
| 153 | args[0] + |
| 154 | (this.useColors ? '%c ' : ' ') + |
| 155 | '+' + module.exports.humanize(this.diff); |
| 156 | |
| 157 | if (!this.useColors) { |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | const c = 'color: ' + this.color; |
| 162 | args.splice(1, 0, c, 'color: inherit'); |
| 163 | |
| 164 | // The final "%c" is somewhat tricky, because there could be other |
| 165 | // arguments passed either before or after the %c, so we need to |
| 166 | // figure out the correct index to insert the CSS into |
| 167 | let index = 0; |
| 168 | let lastC = 0; |
| 169 | args[0].replace(/%[a-zA-Z%]/g, match => { |
| 170 | if (match === '%%') { |
| 171 | return; |
| 172 | } |
| 173 | index++; |
| 174 | if (match === '%c') { |
| 175 | // We only are interested in the *last* %c |
| 176 | // (the user may have provided their own) |
| 177 | lastC = index; |
| 178 | } |
| 179 | }); |
| 180 | |
| 181 | args.splice(lastC, 0, c); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Invokes `console.debug()` when available. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…