main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
748 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | function stringifyNumber({ format, minFractionDigits, tag, value }) {
|
---|
4 | if (typeof value === 'bigint')
|
---|
5 | return String(value);
|
---|
6 | const num = typeof value === 'number' ? value : Number(value);
|
---|
7 | if (!isFinite(num))
|
---|
8 | return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf';
|
---|
9 | let n = JSON.stringify(value);
|
---|
10 | if (!format &&
|
---|
11 | minFractionDigits &&
|
---|
12 | (!tag || tag === 'tag:yaml.org,2002:float') &&
|
---|
13 | /^\d/.test(n)) {
|
---|
14 | let i = n.indexOf('.');
|
---|
15 | if (i < 0) {
|
---|
16 | i = n.length;
|
---|
17 | n += '.';
|
---|
18 | }
|
---|
19 | let d = minFractionDigits - (n.length - i - 1);
|
---|
20 | while (d-- > 0)
|
---|
21 | n += '0';
|
---|
22 | }
|
---|
23 | return n;
|
---|
24 | }
|
---|
25 |
|
---|
26 | exports.stringifyNumber = stringifyNumber;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.