Skip to content

Commit c0c1a4c

Browse files
Trottitaloacasas
authored andcommitted
url: refactor lib/internal/url.js
* set an identifier for the separator rather than using multiple instances of the same literal * consistent arrow function body formatting PR-URL: nodejs#10912 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Italo A. Casas <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
1 parent 90a9917 commit c0c1a4c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/internal/url.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ URLSearchParams.prototype[Symbol.iterator] = URLSearchParams.prototype.entries;
860860

861861
URLSearchParams.prototype[util.inspect.custom] =
862862
function inspect(recurseTimes, ctx) {
863+
const separator = ', ';
863864
const innerOpts = Object.assign({}, ctx);
864865
if (recurseTimes !== null) {
865866
innerOpts.depth = recurseTimes - 1;
@@ -872,13 +873,14 @@ URLSearchParams.prototype[util.inspect.custom] =
872873
output.push(`${innerInspect(list[i])} => ${innerInspect(list[i + 1])}`);
873874

874875
const colorRe = /\u001b\[\d\d?m/g;
875-
const length = output.reduce((prev, cur) => {
876-
return prev + cur.replace(colorRe, '').length + ', '.length;
877-
}, -', '.length);
876+
const length = output.reduce(
877+
(prev, cur) => prev + cur.replace(colorRe, '').length + separator.length,
878+
-separator.length
879+
);
878880
if (length > ctx.breakLength) {
879881
return `${this.constructor.name} {\n ${output.join(',\n ')} }`;
880882
} else if (output.length) {
881-
return `${this.constructor.name} { ${output.join(', ')} }`;
883+
return `${this.constructor.name} { ${output.join(separator)} }`;
882884
} else {
883885
return `${this.constructor.name} {}`;
884886
}

0 commit comments

Comments
 (0)