Skip to content

Commit

Permalink
util: add bigint formatting to util.inspect
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
devsnek authored and BridgeAR committed Feb 1, 2018
1 parent e4fc6d4 commit 39dc947
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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')
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-util-inspect-bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

// Flags: --harmony-bigint

require('../common');
const assert = require('assert');

const { inspect } = require('util');

assert.strictEqual(inspect(1n), '1n');

0 comments on commit 39dc947

Please sign in to comment.