Skip to content

Commit 39dc947

Browse files
devsnekBridgeAR
authored andcommitted
util: add bigint formatting to util.inspect
PR-URL: #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>
1 parent e4fc6d4 commit 39dc947

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ inspect.colors = Object.assign(Object.create(null), {
342342
inspect.styles = Object.assign(Object.create(null), {
343343
'special': 'cyan',
344344
'number': 'yellow',
345+
'bigint': 'yellow',
345346
'boolean': 'yellow',
346347
'undefined': 'grey',
347348
'null': 'bold',
@@ -650,6 +651,9 @@ function formatPrimitive(fn, value, ctx) {
650651
}
651652
if (typeof value === 'number')
652653
return formatNumber(fn, value);
654+
// eslint-disable-next-line valid-typeof
655+
if (typeof value === 'bigint')
656+
return fn(`${value}n`, 'bigint');
653657
if (typeof value === 'boolean')
654658
return fn(`${value}`, 'boolean');
655659
if (typeof value === 'undefined')
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
// Flags: --harmony-bigint
4+
5+
require('../common');
6+
const assert = require('assert');
7+
8+
const { inspect } = require('util');
9+
10+
assert.strictEqual(inspect(1n), '1n');

0 commit comments

Comments
 (0)