0
0
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:
Gus Caplan 2018-01-27 13:57:53 -06:00 committed by Ruben Bridgewater
parent e4fc6d44c5
commit 39dc947409
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 14 additions and 0 deletions

View File

@ -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')

View 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');