diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-26 15:53:11 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-04 12:48:57 +0200 |
commit | a9bf6652b5353f2098d4c0cd0eb77d17e02e164d (patch) | |
tree | 3c62cdca11156d359979e251883605aeee3b033e /lib/internal/util/inspect.js | |
parent | adbcda1eef4377c6fd0c88a1df1003e1e100ffbe (diff) | |
download | android-node-v8-a9bf6652b5353f2098d4c0cd0eb77d17e02e164d.tar.gz android-node-v8-a9bf6652b5353f2098d4c0cd0eb77d17e02e164d.tar.bz2 android-node-v8-a9bf6652b5353f2098d4c0cd0eb77d17e02e164d.zip |
util: use minimal object inspection with %s specifier
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 <targos@protonmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Diffstat (limited to 'lib/internal/util/inspect.js')
-rw-r--r-- | lib/internal/util/inspect.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 52924a4f70..f25c2eaca7 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -1446,7 +1446,20 @@ function formatWithOptions(inspectOptions, ...args) { if (a + 1 !== args.length) { switch (nextChar) { case 115: // 's' - tempStr = String(args[++a]); + const tempArg = args[++a]; + if (typeof tempArg === 'object' && tempArg !== null) { + tempStr = inspect(tempArg, { + ...inspectOptions, + compact: 3, + colors: false, + depth: 0 + }); + // eslint-disable-next-line valid-typeof + } else if (typeof tempArg === 'bigint') { + tempStr = `${tempArg}n`; + } else { + tempStr = String(tempArg); + } break; case 106: // 'j' tempStr = tryStringify(args[++a]); |