- eafda0c: Add PURE annotations to enable better tree-shaking
-
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.
- 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.
- 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]
- Added spacing and minor formatting for readability in utility functions such as
allFollowingGroupsAreZeroinsrc/read/utils.tsandcalculateGroupTypesinsrc/read/groups.ts. [1] [2]
- Updated development dependencies in
package.json, including@biomejs/biome,syncpack, andtsdownto their latest versions.
- Replaced multi-line if statements with concise ternary expressions in
- 6c3cdee: Exclude test and benchmark files from the JSR package
- e9b3f15: Simplified
readVnNumberstring conversion to improve performance - e9b3f15: Fixed logic to repeat "tỷ" based on group position dynamically, ensuring accurate representation for billions, octillions, and undecillions.
-
4b7c059: Performance Optimization & Code Quality Improvements
- 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
- 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)
- 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
- 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)
- 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 (
- 4b7c059: Optimize logic of
formatNumberfunction
- 59d9cfb: Fix configurations for release workflow
- d47e3e4: Simplify the internal
formatNumberhelper by removing theinvalidValueparameter. The function now directly checks if the parsed number isNaNand returns the fallback value, making the code more straightforward and easier to maintain. - d47e3e4: Improve performance by reusing shared
Intl.NumberFormatinstances. The formatter instances for Vietnamese number, currency, and percent formats are now created once and reused across all function calls, reducing memory allocation and improving execution speed.
- 6c09073: Fix currency formatting to use Unicode non-breaking space (
U+00A0) between number and currency symbol. This ensures consistent spacing that won't break across lines and matches the standardIntl.NumberFormatbehavior.