Permalink
Browse files

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>
  • Loading branch information...
devsnek authored and BridgeAR committed Jan 27, 2018
1 parent e4fc6d4 commit 39dc947409c7df19ac4f9502df8cb0d4a1b2829a
Showing with 14 additions and 0 deletions.
  1. +4 −0 lib/util.js
  2. +10 −0 test/parallel/test-util-inspect-bigint.js
@@ -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')
@@ -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.