Skip to content

Commit 2ea7e8e

Browse files
authored
Simplify conditional expressions in reading utilities (#75)
* Simplify conditional expressions in reading utilities Refactored multiple functions to use concise conditional expressions, improving readability and reducing code verbosity. These changes enhance maintainability without altering existing functionality. * Refactor `readTens` function for conciseness Simplified the `readTens` function by replacing nested ternary operators with straightforward conditional statements. This improves readability and maintains the same functionality. * Simplify conditional in `readHundreds` function Reversed the ternary operator condition to improve code clarity and consistency with other similar functions. This adjustment maintains the original functionality while enhancing readability. * Refactor `readHundreds` function for clarity and flexibility Replaced the `hasHundredsPosition` parameter with `groupLength` to improve clarity and make the function more versatile. Updated dependent code to reflect this change and maintain consistent behavior. * Clarify `hasTensPosition` variable usage in `read` function Renamed and refactored the variable `len > 1` to `hasTensPosition` for improved readability and intent clarity. Updated its usage across the function to enhance maintainability without changing the existing behavior. * Refactor digit group processing for readability Improved code readability and consistency in functions handling Vietnamese number words. Simplified conditionals, standardized parameter usage, and enhanced formatting to ensure maintainability without altering functionality. * Update devDependencies in `package.json` and lockfile Upgraded several devDependencies including `@biomejs/biome`, `syncpack`, and `tsdown` to the latest versions. This ensures compatibility with the latest features and improvements while maintaining stability. Updated the `pnpm-lock.yaml` to reflect these changes. * Refactor group processing conditionals for readability Replaced a nested ternary operator with explicit conditional statements in `groups.ts`. This enhances code readability and aligns with the consistent structure of similar functions. No functionality was altered. * Refactor digit group processing and update dependencies Improved readability, simplified logic, and standardized parameter handling in functions processing Vietnamese number words. Made minor formatting updates, enhanced code quality, and updated development dependencies in `package.json`.
1 parent 5c00605 commit 2ea7e8e

File tree

7 files changed

+345
-159
lines changed

7 files changed

+345
-159
lines changed

.changeset/gold-guests-attack.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
"vn-number": patch
3+
---
4+
5+
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.
6+
7+
### Refactoring and Code Simplification
8+
9+
* Replaced multi-line if statements with concise ternary expressions in `readFirstGroup` and `readSubsequentGroup` to improve readability in `src/read/three-digits.ts`.
10+
* Simplified the `getDigitWord` function by removing the intermediate variable and returning the mapped value directly in `src/read/digits.ts`.
11+
12+
### Consistent Parameter Handling
13+
14+
* Updated `readHundreds` to use `groupLength` instead of a boolean flag, and made related changes in calls to `readHundreds`, `readTens`, and `readOnes` for more predictable behavior in `src/read/three-digits.ts`. [[1]](diffhunk://#diff-3fec7bfdd409e9017a9411ada902007e8e4e09dfe468f1566e38e002a7b0a521L6-R7) [[2]](diffhunk://#diff-3fec7bfdd409e9017a9411ada902007e8e4e09dfe468f1566e38e002a7b0a521L56-R65)
15+
16+
### Minor Code Quality Improvements
17+
18+
* Added spacing and minor formatting for readability in utility functions such as `allFollowingGroupsAreZero` in `src/read/utils.ts` and `calculateGroupTypes` in `src/read/groups.ts`. [[1]](diffhunk://#diff-3f1a9cf533aed941787f7a40ca3900d359c1da32f1bc1536d2380c3b4968dbb4R26-R31) [[2]](diffhunk://#diff-8c09ad2ec1c3b0524c8cdbfe07826bfc856285b756983a817f609404a880821aR14-R20)
19+
20+
### Dependency Updates
21+
22+
* Updated development dependencies in `package.json`, including `@biomejs/biome`, `syncpack`, and `tsdown` to their latest versions.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
"test": "vitest"
3737
},
3838
"devDependencies": {
39-
"@biomejs/biome": "2.3.4",
39+
"@biomejs/biome": "2.3.5",
4040
"@changesets/cli": "2.29.7",
4141
"@codspeed/vitest-plugin": "5.0.1",
4242
"@vitest/coverage-v8": "3.2.4",
43-
"syncpack": "14.0.0-alpha.25",
44-
"tsdown": "0.16.0",
43+
"syncpack": "14.0.0-alpha.26",
44+
"tsdown": "0.16.3",
4545
"typescript": "5.9.3",
4646
"vitest": "3.2.4"
4747
},

0 commit comments

Comments
 (0)