MCPcopy Index your code
hub / github.com/debug-js/debug / formatArgs

Function formatArgs

src/browser.js:149–182  ·  view source on GitHub ↗

* Colorize log arguments if enabled. * * @api public

(args)

Source from the content-addressed store, hash-verified

147 */
148
149function 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.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…