-
Notifications
You must be signed in to change notification settings - Fork 1
Modularize readVnNumber function instead of using classes
#43
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #43 +/- ##
===========================================
+ Coverage 93.02% 100.00% +6.97%
===========================================
Files 12 6 -6
Lines 258 245 -13
Branches 68 82 +14
===========================================
+ Hits 240 245 +5
+ Misses 15 0 -15
+ Partials 3 0 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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 refactors the formatNumber function to use Number.isNaN() instead of the global isNaN() function for NaN checking. This is a best practice improvement that avoids the type coercion issues associated with the global isNaN() function.
Key Changes:
- Replaced
isNaN()withNumber.isNaN()for checking NaN values in the number validation logic
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0a30fb3 to
962e996
Compare
Replaced `isNaN` with `Number.isNaN` to improve type safety and clarity. Ensures more predictable behavior when handling `NaN` values across different types. Updated fallback logic to conform to the new check.
Removed redundant classes and consolidated the Vietnamese number reading process into a single function. Streamlined implementation improves maintainability, reduces code complexity, and eliminates duplication across modules. Updated tests and adjusted configurations accordingly.
Added exclusions for `tsdown.config.*` in test and coverage settings within the Vitest configuration. This ensures that unnecessary files are not included in tests or coverage reports, improving accuracy and performance.
Added extensive test cases for various number patterns, including leading zeros, tens, hundreds, and boundary values. These improvements enhance the coverage and reliability of the Vietnamese number reading functionality. Updated logic to handle corner cases more accurately.
Refactored `formatNumber` to reduce redundancy and improve readability. Combined conditions to streamline the implementation and adjusted handling of null and string inputs. Updated fallback behavior to maintain correctness and consistency. test(config): refine Vitest exclusions Added specific exclusions for `src/index.ts` and `src/format/index.ts` in both test and coverage settings. Improves test accuracy by omitting irrelevant files from coverage metrics.
readVnNumber function instead of using classes
Added badges for publish workflow, quality gate status, and CodSpeed performance. Enhances README visualization and provides quick access to project metrics.
Refactored number reading logic by introducing separate functions for first and subsequent groups, improving modularity and readability. Removed redundant logic and reorganized code for better maintainability.
Added support for BigInt values in number formatting tests, ensuring compatibility across formats. Introduced comprehensive test cases for Vietnamese number reading, covering edge cases, groups, and suffix handling for enhanced accuracy and reliability.
|



This pull request introduces a major refactor of the Vietnamese number reading module, shifting from an object-oriented approach to a functional, modular design for improved performance, maintainability, and code quality. The public API remains unchanged and fully backward compatible, but the internal structure has been completely rewritten, resulting in significant performance gains, reduced complexity, and better test coverage. Additionally, there is a minor optimization to the
formatNumberfunction.Major Refactor: Functional Rewrite and Modularization
NumberReader,Numbers,Thousand,Million,Billion,Zerofilland related files) with a pure functional approach, removing inheritance and dynamic dispatch for better performance and maintainability. The internal logic is now split into five focused modules:digits.ts,utils.ts,three-digits.ts,groups.ts, andindex.ts. Public API (readVnNumber) remains unchanged. (.changeset/late-wings-add.md, [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]Performance and Code Quality Improvements
readThreeDigits,readVnNumber) to reduce cognitive complexity below SonarCloud thresholds, improving readability and maintainability. (.changeset/late-wings-add.md)Testing Enhancements
Minor Function Optimization
formatNumberfunction insrc/format/number.tsfor early returns and clearer handling ofnull,bigint, andnumbertypes. (.changeset/wide-things-dig.md, src/format/number.tsL13-R19)