diff options
author | Michaël Zasso <targos@protonmail.com> | 2018-03-14 10:03:36 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2018-03-17 11:37:53 +0100 |
commit | 893432ad928e25854950c0b5c581dfb3081ed4bb (patch) | |
tree | 76890a06b79c69297c77fb896041af7da1f1ab13 | |
parent | 6a5a9ad62decfc7a5a41e362484dc0e56c648e67 (diff) | |
download | node-new-893432ad928e25854950c0b5c581dfb3081ed4bb.tar.gz |
util: add boxed BigInt formatting to util.inspect
Before:
> Object(7n)
BigInt {}
After:
> Object(7n)
[BigInt: 7n]
PR-URL: https://github.com/nodejs/node/pull/19341
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
-rw-r--r-- | lib/util.js | 7 | ||||
-rw-r--r-- | test/parallel/test-util-inspect-bigint.js | 2 |
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/util.js b/lib/util.js index b64d103cb3..b9ad76f4ad 100644 --- a/lib/util.js +++ b/lib/util.js @@ -580,6 +580,13 @@ function formatValue(ctx, value, recurseTimes, ln) { if (keyLength === 0) return ctx.stylize(`[Boolean: ${formatted}]`, 'boolean'); base = `[Boolean: ${formatted}]`; + // eslint-disable-next-line valid-typeof + } else if (typeof raw === 'bigint') { + // Make boxed primitive BigInts look like such + const formatted = formatPrimitive(stylizeNoColor, raw); + if (keyLength === 0) + return ctx.stylize(`[BigInt: ${formatted}]`, 'bigint'); + base = `[BigInt: ${formatted}]`; } else if (typeof raw === 'symbol') { const formatted = formatPrimitive(stylizeNoColor, raw); return ctx.stylize(`[Symbol: ${formatted}]`, 'symbol'); diff --git a/test/parallel/test-util-inspect-bigint.js b/test/parallel/test-util-inspect-bigint.js index cb50c1f698..5e0233640e 100644 --- a/test/parallel/test-util-inspect-bigint.js +++ b/test/parallel/test-util-inspect-bigint.js @@ -8,3 +8,5 @@ const assert = require('assert'); const { inspect } = require('util'); assert.strictEqual(inspect(1n), '1n'); +assert.strictEqual(inspect(Object(-1n)), '[BigInt: -1n]'); +assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]'); |