From b606788412be2b49f66f41808b22e7754948a3e5 Mon Sep 17 00:00:00 2001 From: Nathachai Thongniran Date: Tue, 12 Oct 2021 10:52:34 +0700 Subject: [PATCH] fix(grammar): multi occurrence of 1x and 2x --- src/index.js | 4 ++-- src/index.test.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 8f9ef8c..e726396 100644 --- a/src/index.js +++ b/src/index.js @@ -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 && diff --git a/src/index.test.js b/src/index.test.js index fd0bda7..8fbc47a 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -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', () => {