From a9bf6652b5353f2098d4c0cd0eb77d17e02e164d Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 26 Mar 2019 15:53:11 +0100 Subject: util: use minimal object inspection with %s specifier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This improves `util.format()` by returning more meaningful results when using `%s` as specifier and any object as value. Besides that `BigInt` will also be represented with an `n` at the end to indicate that it's of type `BigInt`. PR-URL: https://github.com/nodejs/node/pull/26927 Reviewed-By: Michaƫl Zasso Reviewed-By: Yongsheng Zhang --- doc/api/util.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'doc/api/util.md') diff --git a/doc/api/util.md b/doc/api/util.md index beb79ae0f8..6a8b30ef7a 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -220,15 +220,17 @@ as a `printf`-like format string which can contain zero or more format specifiers. Each specifier is replaced with the converted value from the corresponding argument. Supported specifiers are: -* `%s` - `String`. -* `%d` - `Number` (integer or floating point value) or `BigInt`. -* `%i` - Integer or `BigInt`. -* `%f` - Floating point value. -* `%j` - JSON. Replaced with the string `'[Circular]'` if the argument -contains circular references. -* `%o` - `Object`. A string representation of an object - with generic JavaScript object formatting. - Similar to `util.inspect()` with options +* `%s` - `String` will be used to convert all values except `BigInt` and + `Object`. `BigInt` values will be represented with an `n` and Objects are + inspected using `util.inspect()` with options + `{ depth: 0, colors: false, compact: 3 }`. +* `%d` - `Number` will be used to convert all values except `BigInt`. +* `%i` - `parseInt(value, 10)` is used for all values except `BigInt`. +* `%f` - `parseFloat(value)` is used for all values. +* `%j` - JSON. Replaced with the string `'[Circular]'` if the argument contains + circular references. +* `%o` - `Object`. A string representation of an object with generic JavaScript + object formatting. Similar to `util.inspect()` with options `{ showHidden: true, showProxy: true }`. This will show the full object including non-enumerable properties and proxies. * `%O` - `Object`. A string representation of an object with generic JavaScript -- cgit v1.2.3