( n: number | string, options?: prettyMillisecondsOriginal.Options & PrettyValueOptions )
| 550 | }; |
| 551 | |
| 552 | export const prettyMilliseconds = ( |
| 553 | n: number | string, |
| 554 | options?: prettyMillisecondsOriginal.Options & PrettyValueOptions |
| 555 | ) => { |
| 556 | if (typeof n === 'undefined' || n === null) { |
| 557 | return options?.showNullAs ?? 'N/A'; // null, undefined -> N/A |
| 558 | } |
| 559 | |
| 560 | if (options?.showLargeAsInfinite && isUInt64Maximum(String(n))) { |
| 561 | return 'Infinite'; |
| 562 | } |
| 563 | |
| 564 | if (typeof n !== 'number') { |
| 565 | if (typeof n === 'string') { |
| 566 | // string |
| 567 | if (n === '') { |
| 568 | return 'N/A'; // empty -> N/A |
| 569 | } |
| 570 | |
| 571 | const parsed = Number.parseFloat(String(n)); |
| 572 | |
| 573 | if (!Number.isFinite(parsed)) { |
| 574 | return String(parsed); // "NaN" or "Infinity" |
| 575 | } |
| 576 | |
| 577 | // number parsed, fall through |
| 578 | return prettyMillisecondsOriginal(parsed, options); |
| 579 | } |
| 580 | // something else: object, function, ... |
| 581 | return 'NaN'; |
| 582 | } |
| 583 | if (!Number.isFinite(n)) { |
| 584 | return 'N/A'; |
| 585 | } |
| 586 | |
| 587 | // n is a finite number |
| 588 | return prettyMillisecondsOriginal(n, options); |
| 589 | }; |
| 590 | |
| 591 | const ONE_THOUSAND = 1000; |
| 592 | const ONE_MILLION = 1_000_000; |
no test coverage detected
searching dependent graphs…