diff --git a/lib/util.js b/lib/util.js index 0f0ed408ba4cc1..4525792b2ec4c4 100644 --- a/lib/util.js +++ b/lib/util.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') diff --git a/test/parallel/test-util-inspect-bigint.js b/test/parallel/test-util-inspect-bigint.js new file mode 100644 index 00000000000000..cb50c1f6982460 --- /dev/null +++ b/test/parallel/test-util-inspect-bigint.js @@ -0,0 +1,10 @@ +'use strict'; + +// Flags: --harmony-bigint + +require('../common'); +const assert = require('assert'); + +const { inspect } = require('util'); + +assert.strictEqual(inspect(1n), '1n');