From 2c192c3538f772d2976cfe8714ea84df6fe3fb36 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 19 Jan 2017 17:18:13 -0800 Subject: [PATCH] url: refactor lib/internal/url.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * set an identifier for the separator rather than using multiple instances of the same literal * consistent arrow function body formatting PR-URL: https://github.com/nodejs/node/pull/10912 Reviewed-By: Michaƫl Zasso Reviewed-By: Joyee Cheung Reviewed-By: Colin Ihrig Reviewed-By: Italo A. Casas Reviewed-By: Timothy Gu --- lib/internal/url.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index 9be683f28a4e06..679e14d72a9c39 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -860,6 +860,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; @@ -872,13 +873,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} {}`; }