summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api/util.md3
-rw-r--r--lib/util.js11
-rw-r--r--test/parallel/test-util-format.js19
3 files changed, 20 insertions, 13 deletions
diff --git a/doc/api/util.md b/doc/api/util.md
index 19032aaab2..396667be13 100644
--- a/doc/api/util.md
+++ b/doc/api/util.md
@@ -245,8 +245,7 @@ util.format('%s:%s', 'foo');
```
Values that are not part of the format string are formatted using
-`util.inspect()` if their type is either `'object'`, `'symbol'`, `'function'`
-or `'number'` and using `String()` in all other cases.
+`util.inspect()` if their type is not `string`.
If there are more arguments passed to the `util.format()` method than the
number of specifiers, the extra arguments are concatenated to the returned
diff --git a/lib/util.js b/lib/util.js
index ef28427cd8..f48d93d124 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -174,17 +174,8 @@ function formatWithOptions(inspectOptions, ...args) {
while (a < args.length) {
const value = args[a];
- // TODO(BridgeAR): This should apply for all besides strings. Especially
- // BigInt should be properly inspected.
str += join;
- if (typeof value !== 'string' &&
- typeof value !== 'boolean' &&
- // eslint-disable-next-line valid-typeof
- typeof value !== 'bigint') {
- str += inspect(value, inspectOptions);
- } else {
- str += value;
- }
+ str += typeof value !== 'string' ? inspect(value, inspectOptions) : value;
join = ' ';
a++;
}
diff --git a/test/parallel/test-util-format.js b/test/parallel/test-util-format.js
index 066b4de58c..a90e52946b 100644
--- a/test/parallel/test-util-format.js
+++ b/test/parallel/test-util-format.js
@@ -316,10 +316,27 @@ assert.strictEqual(util.format(new BadCustomError('foo')),
assert.strictEqual(util.format('1', '1'), '1 1');
assert.strictEqual(util.format(1, '1'), '1 1');
assert.strictEqual(util.format('1', 1), '1 1');
-assert.strictEqual(util.format(1, 1), '1 1');
+assert.strictEqual(util.format(1, -0), '1 -0');
assert.strictEqual(util.format('1', () => {}), '1 [Function]');
assert.strictEqual(util.format(1, () => {}), '1 [Function]');
assert.strictEqual(util.format('1', "'"), "1 '");
assert.strictEqual(util.format(1, "'"), "1 '");
assert.strictEqual(util.format('1', 'number'), '1 number');
assert.strictEqual(util.format(1, 'number'), '1 number');
+assert.strictEqual(util.format(5n), '5n');
+assert.strictEqual(util.format(5n, 5n), '5n 5n');
+
+// Check `formatWithOptions`.
+assert.strictEqual(
+ util.formatWithOptions(
+ { colors: true },
+ true, undefined, Symbol(), 1, 5n, null, 'foobar'
+ ),
+ '\u001b[33mtrue\u001b[39m ' +
+ '\u001b[90mundefined\u001b[39m ' +
+ '\u001b[32mSymbol()\u001b[39m ' +
+ '\u001b[33m1\u001b[39m ' +
+ '\u001b[33m5n\u001b[39m ' +
+ '\u001b[1mnull\u001b[22m ' +
+ 'foobar'
+);