diff --git a/lib/internal/url.js b/lib/internal/url.js index 1d63c26e511340..a4c31fb4266bb1 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -862,6 +862,7 @@ URLSearchParams.prototype[Symbol.iterator] = URLSearchParams.prototype.entries; URLSearchParams.prototype[util.inspect.custom] = function inspect(recurseTimes, ctx) { + const separator = ', '; const innerOpts = Object.assign({}, ctx); if (recurseTimes !== null) { innerOpts.depth = recurseTimes - 1; @@ -874,13 +875,14 @@ URLSearchParams.prototype[util.inspect.custom] = output.push(`${innerInspect(list[i])} => ${innerInspect(list[i + 1])}`); const colorRe = /\u001b\[\d\d?m/g; - const length = output.reduce((prev, cur) => { - return prev + cur.replace(colorRe, '').length + ', '.length; - }, -', '.length); + const length = output.reduce( + (prev, cur) => prev + cur.replace(colorRe, '').length + separator.length, + -separator.length + ); if (length > ctx.breakLength) { return `${this.constructor.name} {\n ${output.join(',\n ')} }`; } else if (output.length) { - return `${this.constructor.name} { ${output.join(', ')} }`; + return `${this.constructor.name} { ${output.join(separator)} }`; } else { return `${this.constructor.name} {}`; }