(n: number | string | null | undefined, options?: PrettyValueOptions)
| 517 | } |
| 518 | |
| 519 | export const prettyBytes = (n: number | string | null | undefined, options?: PrettyValueOptions) => { |
| 520 | if (typeof n === 'undefined' || n === null) { |
| 521 | return options?.showNullAs ?? 'N/A'; // null, undefined -> N/A |
| 522 | } |
| 523 | |
| 524 | if (options?.showLargeAsInfinite && isUInt64Maximum(String(n))) { |
| 525 | return 'Infinite'; |
| 526 | } |
| 527 | |
| 528 | if (typeof n !== 'number') { |
| 529 | if (typeof n === 'string') { |
| 530 | // string |
| 531 | if (n === '') { |
| 532 | return 'N/A'; // empty -> N/A |
| 533 | } |
| 534 | |
| 535 | const parsed = Number.parseFloat(String(n)); |
| 536 | |
| 537 | if (!Number.isFinite(parsed)) { |
| 538 | return String(parsed); // "NaN" or "Infinity" |
| 539 | } |
| 540 | |
| 541 | // number parsed, fall through |
| 542 | return prettyBytesOriginal(parsed, { binary: true }); |
| 543 | } |
| 544 | // something else: object, function, ... |
| 545 | return 'NaN'; |
| 546 | } |
| 547 | |
| 548 | // n is a finite number |
| 549 | return prettyBytesOriginal(n, { binary: true }); |
| 550 | }; |
| 551 | |
| 552 | export const prettyMilliseconds = ( |
| 553 | n: number | string, |
no test coverage detected
searching dependent graphs…