diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2021-12-03 17:56:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-03 17:56:43 +0300 |
commit | 85764c0e1a9b2e6fc1734a3977dc11651a4bec80 (patch) | |
tree | 421bb319be0ee1632008450d487f240ae6266d77 /doc/api/util.md | |
parent | 3f51f052ec805ecae77b7c9e7470c5c1f0b82f3b (diff) |
util: add numericSeparator to util.inspect
This adds the `numericSeparator` option to util.inspect. Using it
separates numbers by thousands adding the underscore accordingly.
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: https://github.com/nodejs/node/pull/41003
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'doc/api/util.md')
-rw-r--r-- | doc/api/util.md | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/doc/api/util.md b/doc/api/util.md index 3810b1145cd..3b4078b6dc8 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -485,6 +485,9 @@ stream.write('With ES6'); <!-- YAML added: v0.3.0 changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/41003 + description: The `numericSeparator` option is supported now. - version: - v14.6.0 - v12.19.0 @@ -606,6 +609,9 @@ changes: set to `'set'`, only getters with a corresponding setter are inspected. This might cause side effects depending on the getter function. **Default:** `false`. + * `numericSeparator` {boolean} If set to `true`, an underscore is used to + 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 @@ -754,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. |