Skip to content

feat(FR-918): Add BigNumber to manage bit number #3674

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

Merged
merged 1 commit into from
May 26, 2025
Merged

Conversation

ragingwind
Copy link
Contributor

@ragingwind ragingwind commented May 19, 2025

Add big.js library for precise number handling

Added the big.js library and created a BigNumber utility class to handle large numbers and unit conversions with precision. This implementation provides:

  • Parsing of numbers with units (e.g., "123px", "45.67em")
  • Converting between binary size units (B, K, M, G, T, P, E)
  • Comparing numbers with different units
  • Adding and subtracting numbers with units
  • Range validation for numbers with units
  • Formatting numbers without trailing zeros

The utility includes comprehensive test coverage to ensure reliability.

resolves #3593 (FR-918)

@github-actions github-actions bot added the size:L 100~500 LoC label May 19, 2025
Copy link
Contributor Author

ragingwind commented May 19, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • flow:merge-queue - adds this PR to the back of the merge queue
  • flow:hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ragingwind ragingwind marked this pull request as ready for review May 19, 2025 08:43
@Copilot Copilot AI review requested due to automatic review settings May 19, 2025 08:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a BigNumber helper class extending Big.js to support size unit handling and conversion, along with accompanying unit tests and dependency updates.

  • Adds a BigNumber class with unit parsing, automatic unit selection, and conversion methods.
  • Introduces tests verifying BigNumber behaviors.
  • Updates dependencies in package.json to include Big.js and its types.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
react/src/helper/big-number.ts Implements BigNumber class with unit conversion and parsing logic
react/src/helper/big-number.test.ts Adds tests for parsing and unit conversion functionalities
react/package.json Updates dependency versions for Big.js and associated type definitions
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

@github-actions github-actions bot added size:XL 500~ LoC and removed size:L 100~500 LoC labels May 20, 2025
@ragingwind ragingwind changed the title wip feat(FR-918): Add BigNumber to manage bit number May 21, 2025
@ragingwind ragingwind requested a review from Copilot May 21, 2025 06:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a BigNumber utility class using the big.js library to provide precise arithmetic and unit conversion functionality for handling large numbers. Key changes include:

  • Introducing the BigNumber utility class with functions for parsing, converting, comparing, adding, and subtracting numbers with units.
  • Adding comprehensive test coverage for BigNumber operations.
  • Fixing a typo in the existing helper function name.

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
react/src/helper/index.tsx Corrected function name typo from "subNumberWihUnits" to "subNumberWithUnits".
react/src/helper/big-number.ts Added BigNumber utility class with unit parsing, conversion, and arithmetic functions.
react/src/helper/big-number.test.ts Added tests covering all BigNumber functionality.
react/package.json Added the big.js library and its type definitions.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

react/src/helper/index.tsx:270

  • The function name has been corrected from 'subNumberWihUnits' to 'subNumberWithUnits', which improves clarity. Please ensure all internal references use the updated name.
export function subNumberWithUnits(

Copy link

github-actions bot commented May 21, 2025

Coverage report for ./react

St.
Category Percentage Covered / Total
🔴 Statements 4.56% 479/10494
🔴 Branches 4.03% 297/7361
🔴 Functions 2.72% 90/3311
🔴 Lines 4.52% 464/10271

Test suite run success

161 tests passing in 15 suites.

Report generated by 🧪jest coverage report action from eb7ab1c

Copy link
Contributor

@lizable lizable left a comment

Choose a reason for hiding this comment

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

We need to update pnpm-lock.yaml I got import error from @jest/globals and @jest/test

Copy link
Contributor Author

I didn't touch any packages related to jest. Other tests are working well on main branch. Please let me see the error you've got @lizable

Copy link
Contributor

@lizable lizable left a comment

Choose a reason for hiding this comment

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

All tests have been passed. LGTM.

How to test:

  1. Go to react directory
  2. input pnpm test src/helper/big-number.test.ts
  3. See all test have been passed.

Copy link
Contributor

@agatha197 agatha197 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

graphite-app bot commented May 26, 2025

Merge activity

# Add big.js library for precise number handling

Added the big.js library and created a BigNumber utility class to handle large numbers and unit conversions with precision. This implementation provides:

- Parsing of numbers with units (e.g., "123px", "45.67em")
- Converting between binary size units (B, K, M, G, T, P, E)
- Comparing numbers with different units
- Adding and subtracting numbers with units
- Range validation for numbers with units
- Formatting numbers without trailing zeros

The utility includes comprehensive test coverage to ensure reliability.

resolves #3593 (FR-918)
@graphite-app graphite-app bot force-pushed the feat/big-number branch from 0ab6e5b to eb7ab1c Compare May 26, 2025 08:14
@graphite-app graphite-app bot merged commit eb7ab1c into main May 26, 2025
7 checks passed
@graphite-app graphite-app bot deleted the feat/big-number branch May 26, 2025 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XL 500~ LoC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance UI Components and Utilities to Support Values Beyond BigInt (8PiB+)
3 participants