Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve math with formats/parsing unit related functions #518

Merged
merged 8 commits into from
Sep 26, 2022

Conversation

LuizAsFight
Copy link
Contributor

@LuizAsFight LuizAsFight commented Sep 23, 2022

Improvements to math package

  • now bn accepts undefined, and use default value 0 (zero)
  • Added helper functions to our math bn
    • format - format units and precision. Returns a formatted value from any of BnInput
    • formatUnits - format units. Returns a formatted value from any of BnInput
    • parseUnits - create a BN instance parsing to unit value.
    • toFixed - formats a string to precision. don't consider units
  • added functional shortcuts to new helpers as well

Usage (all parameters are optional):

bn('1001000000200000000').format({
  minPrecision: 3,
  precision: 8,
  units: 9
});

bn('1000000000').formatUnits(7);

bn.parseUnits('100100.00002');
bn.parseUnits('100100.00002', 5);

Closes #165

@github-actions
Copy link
Contributor

github-actions bot commented Sep 23, 2022

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
89.66% (+0.14% 🔼)
3382/3772
🟡 Branches
70.01% (+0.09% 🔼)
649/927
🟢 Functions
86.43% (+0.11% 🔼)
675/781
🟢 Lines
89.62% (+0.15% 🔼)
3238/3613
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / constants.ts
100% 100% 100% 100%
🟢 math/src/decimal.ts 100% 46.15% 100% 100%
🟢
... / functional.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢 math/src/bn.ts
93.1% (+3.45% 🔼)
90.24% (-4.2% 🔻)
87.5% (+1.29% 🔼)
92.94% (+3.66% 🔼)

Test suite run success

515 tests passing in 46 suites.

Report generated by 🧪jest coverage report action from 14f9898

packages/math/src/bn.test.ts Outdated Show resolved Hide resolved
packages/math/src/bn.test.ts Outdated Show resolved Hide resolved
packages/math/src/bn.ts Outdated Show resolved Hide resolved
packages/math/src/bn.test.ts Show resolved Hide resolved
packages/math/src/decimal.ts Outdated Show resolved Hide resolved
packages/math/src/decimal.ts Outdated Show resolved Hide resolved
@LuizAsFight LuizAsFight self-assigned this Sep 25, 2022
@LuizAsFight LuizAsFight marked this pull request as ready for review September 26, 2022 02:00
@LuizAsFight LuizAsFight enabled auto-merge (squash) September 26, 2022 02:01
Copy link
Contributor

@camsjams camsjams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small tweaks

packages/math/src/bn.ts Show resolved Hide resolved
packages/math/src/bn.ts Show resolved Hide resolved
packages/math/src/bn.test.ts Show resolved Hide resolved
@LuizAsFight LuizAsFight merged commit 658b065 into master Sep 26, 2022
@LuizAsFight LuizAsFight deleted the lf-165/feat/improve-math branch September 26, 2022 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a units utility to work with decimals
3 participants