From 59e348c87d698c0f25eed8aec215149b0e71627c Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 30 Nov 2021 12:07:23 +0100 Subject: [PATCH] fixup! util: add numericSeparator to util.inspect Signed-off-by: Ruben Bridgewater --- doc/api/util.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/api/util.md b/doc/api/util.md index 8f22dc99cf719d8..a91928fa6b85a08 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -610,7 +610,8 @@ changes: This might cause side effects depending on the getter function. **Default:** `false`. * `numericSeparator` {boolean} If set to `true`, an underscore is used to - separate thousands in all bigints and numbers. **Default:** `false`. + separate every three digits in all bigints and numbers. + **Default:** `false`. * Returns: {string} The representation of `object`. The `util.inspect()` method returns a string representation of `object` that is @@ -759,6 +760,21 @@ assert.strict.equal( ); ``` +The `numericSeparator` option adds an underscore every three digits to all +numbers. + +```js +const { inspect } = require('util'); + +const thousand = 1_000; +const million = 1_000_000; +const bigNumber = 123_456_789n; +const bigDecimal = 1_234.123_45 + +console.log(thousand, million, bigNumber, bigDecimal); +// 1_000 1_000_000 123_456_789n 1_234.123_45 +``` + `util.inspect()` is a synchronous method intended for debugging. Its maximum output length is approximately 128 MB. Inputs that result in longer output will be truncated.