Skip to content

Commit

Permalink
fix(grammar): multi occurrence of 1x and 2x
Browse files Browse the repository at this point in the history
  • Loading branch information
jojoee committed Oct 12, 2021
1 parent 7527dd4 commit b606788
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ function grammarFix (str) {
let result = str

// "สิบ"
result = result.replace('หนึ่งสิบ', 'สิบ')
result = result.replace(/หนึ่งสิบ/g, 'สิบ')
// "ยี่สิบ"
result = result.replace('สองสิบ', 'ยี่สิบ')
result = result.replace(/สองสิบ/g, 'ยี่สิบ')
// "เอ็ด"
const neungLen = 5
if (result.length > neungLen &&
Expand Down
8 changes: 8 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ describe('grammar', () => {
expect(bahttext(57.23)).toBe('ห้าสิบเจ็ดบาทยี่สิบสามสตางค์')
expect(bahttext(422.26)).toBe('สี่ร้อยยี่สิบสองบาทยี่สิบหกสตางค์')
})

test('multi occurrence of 1x', () => {
expect(bahttext(10056518)).toBe('สิบล้านห้าหมื่นหกพันห้าร้อยสิบแปดบาทถ้วน')
})

test('multi occurrence of 1x', () => {
expect(bahttext(20056528)).toBe('ยี่สิบล้านห้าหมื่นหกพันห้าร้อยยี่สิบแปดบาทถ้วน')
})
})

describe('decimals', () => {
Expand Down

0 comments on commit b606788

Please sign in to comment.