mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
util: add bigint formatting to util.inspect
PR-URL: https://github.com/nodejs/node/pull/18412 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
e4fc6d44c5
commit
39dc947409
@ -342,6 +342,7 @@ inspect.colors = Object.assign(Object.create(null), {
|
||||
inspect.styles = Object.assign(Object.create(null), {
|
||||
'special': 'cyan',
|
||||
'number': 'yellow',
|
||||
'bigint': 'yellow',
|
||||
'boolean': 'yellow',
|
||||
'undefined': 'grey',
|
||||
'null': 'bold',
|
||||
@ -650,6 +651,9 @@ function formatPrimitive(fn, value, ctx) {
|
||||
}
|
||||
if (typeof value === 'number')
|
||||
return formatNumber(fn, value);
|
||||
// eslint-disable-next-line valid-typeof
|
||||
if (typeof value === 'bigint')
|
||||
return fn(`${value}n`, 'bigint');
|
||||
if (typeof value === 'boolean')
|
||||
return fn(`${value}`, 'boolean');
|
||||
if (typeof value === 'undefined')
|
||||
|
10
test/parallel/test-util-inspect-bigint.js
Normal file
10
test/parallel/test-util-inspect-bigint.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
// Flags: --harmony-bigint
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const { inspect } = require('util');
|
||||
|
||||
assert.strictEqual(inspect(1n), '1n');
|
Loading…
Reference in New Issue
Block a user