Releases: hckhanh/vn-number
Releases · hckhanh/vn-number
[email protected]
Patch Changes
-
2ea7e8e: Refactors several functions related to reading and processing digit groups in Vietnamese number words, focusing on code readability, logic simplification, and consistent parameter handling. Minor formatting and code quality improvements are also included, along with updates to development dependencies.
Refactoring and Code Simplification
- Replaced multi-line if statements with concise ternary expressions in
readFirstGroupandreadSubsequentGroupto improve readability insrc/read/three-digits.ts. - Simplified the
getDigitWordfunction by removing the intermediate variable and returning the mapped value directly insrc/read/digits.ts.
Consistent Parameter Handling
- Updated
readHundredsto usegroupLengthinstead of a boolean flag, and made related changes in calls toreadHundreds,readTens, andreadOnesfor more predictable behavior insrc/read/three-digits.ts. [1] [2]
Minor Code Quality Improvements
- Added spacing and minor formatting for readability in utility functions such as
allFollowingGroupsAreZeroinsrc/read/utils.tsandcalculateGroupTypesinsrc/read/groups.ts. [1] [2]
Dependency Updates
- Updated development dependencies in
package.json, including@biomejs/biome,syncpack, andtsdownto their latest versions.
- Replaced multi-line if statements with concise ternary expressions in
[email protected]
Patch Changes
- 6c3cdee: Exclude test and benchmark files from the JSR package
[email protected]
v2.0.0
Major Changes
-
4b7c059: Performance Optimization & Code Quality Improvements
Breaking Changes
- Refactored from OOP to functional programming: Removed class-based architecture (
NumberReader,Numbers,Thousand,Million,Billion,Zerofillclasses) in favor of pure functional approach - Internal implementation completely restructured for better performance and maintainability
- Note: Public API (
readVnNumber) remains unchanged and fully compatible
Performance Improvements
- Eliminated class instantiation overhead: No more object creation for each 3-digit group
- Removed property access overhead: Direct string index access instead of class properties
- Eliminated inheritance chain lookups: Flat function calls instead of prototype chain traversal
- Removed dynamic dispatch: Direct function calls instead of class lookup maps
- Optimized string operations: More efficient concatenation patterns
- Benchmarks: Maintained excellent performance (2.3-6.8M ops/sec for typical use cases)
Code Quality
- Reduced cognitive complexity: Refactored complex functions to meet SonarCloud standards (<15 complexity)
readThreeDigits: Complexity reduced from 27 to <15readVnNumber: Complexity reduced from 37 to <15
- Better code organization: Split monolithic file into 5 focused modules:
digits.ts- Digit mapping and conversionutils.ts- Utility functions for grouping and validationthree-digits.ts- Three-digit group reading logicgroups.ts- Group type calculation and processingindex.ts- Clean public API entry point
- Improved maintainability: Smaller, focused functions with single responsibilities
- Better testability: Individual modules can be tested in isolation
Testing
- Expanded test coverage: Increased from 42 to 68 tests (+62% increase)
- Comprehensive edge case coverage: Added extensive tests for:
- All leading zero patterns (001, 068, 060, etc.)
- All tens patterns (10-99) with special rules
- All hundreds patterns (100-999)
- Mixed magnitude numbers
- Boundary values at each magnitude level
- All Vietnamese reading rules (mốt, lăm, lẻ, không trăm)
- 91 total tests passing (68 for read module, 23 for format module)
Internal Changes
- Removed 12 files (old class implementations and their tests)
- Added 4 new modular files with clear separation of concerns
- Maintained 100% backward compatibility for public API
- Refactored from OOP to functional programming: Removed class-based architecture (
Patch Changes
- 4b7c059: Optimize logic of
formatNumberfunction