Browse Source

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: https://github.com/nodejs/node/pull/10912
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
v6
Rich Trott 8 years ago
parent
commit
6b6123cfbe
  1. 10
      lib/internal/url.js

10
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} {}`;
}

Loading…
Cancel
Save