Skip to content

Commit

Permalink
fixup! util: add numericSeparator to util.inspect
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
BridgeAR committed Nov 30, 2021
1 parent fbf660a commit 59e348c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 59e348c

Please sign in to comment.