refactor(fmt): add unit arrays
This PR adds unit arrays which makes it more readable and avoids string manipulation.
Several other changes like num = Math.abs(num) only for negative numbers and pre-calculation of magnitudes.
Codecov Report
Attention: Patch coverage is 98.78049% with 1 line in your changes missing coverage. Please review.
Project coverage is 94.15%. Comparing base (
fc59ca6) to head (bc419dd). Report is 1 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| fmt/bytes.ts | 98.78% | 0 Missing and 1 partial :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #6696 +/- ##
=======================================
Coverage 94.14% 94.15%
=======================================
Files 586 586
Lines 42465 42501 +36
Branches 6701 6694 -7
=======================================
+ Hits 39980 40018 +38
+ Misses 2435 2433 -2
Partials 50 50
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Let's not do this. It seems very confusing to include many of unused values in the source code
Let's not do this. It seems very confusing to include many of unused values in the source code
This was in preparation for adding the unitDisplay as an option. I've updated the PR so it is introduced here to avoid unused values.
One question remains whether short and altShort should coexist. This implementation deviates from the IEC standard names (for example Kibibyte uses KiB according to IEC but kiB in the current implementation) which seems like an error imo, but I am not sure if that is the consensus.