bahttext 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-en.md +43 -5
- package/README.md +43 -5
- package/index.html +6 -5
- package/package.json +9 -17
- package/src/index.js +28 -21
- package/src/index.test.js +60 -5
- package/stryker.conf.json +25 -0
package/README-en.md
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|

|
|
10
10
|

|
|
11
11
|

|
|
12
|
+
[](https://dashboard.stryker-mutator.io/reports/github.com/jojoee/bahttext/master)
|
|
12
13
|
|
|
13
14
|
Language: [ไทย](https://github.com/jojoee/bahttext/blob/master/README.md), [English](https://github.com/jojoee/bahttext/blob/master/README-en.md)
|
|
14
15
|
|
|
@@ -36,29 +37,66 @@ import { bahttext } from "bahttext"
|
|
|
36
37
|
## Example usage
|
|
37
38
|
|
|
38
39
|
```javascript
|
|
39
|
-
//
|
|
40
|
-
bahttext(
|
|
40
|
+
bahttext(8.00) // แปดบาทถ้วน
|
|
41
|
+
bahttext(5678.00) // ห้าพันหกร้อยเจ็ดสิบแปดบาทถ้วน
|
|
42
|
+
bahttext(63147.89) // หกหมื่นสามพันหนึ่งร้อยสี่สิบเจ็ดบาทแปดสิบเก้าสตางค์
|
|
43
|
+
bahttext(51000001.00) // ห้าสิบเอ็ดล้านหนึ่งบาทถ้วน
|
|
44
|
+
bahttext(317.10) // สามร้อยสิบเจ็ดบาทสิบสตางค์
|
|
45
|
+
bahttext(422.26) // สี่ร้อยยี่สิบสองบาทยี่สิบหกสตางค์
|
|
46
|
+
bahttext(11.11) // สิบเอ็ดบาทสิบเอ็ดสตางค์
|
|
47
|
+
bahttext(191415.11) // หนึ่งแสนเก้าหมื่นหนึ่งพันสี่ร้อยสิบห้าบาทสิบเอ็ดสตางค์
|
|
48
|
+
bahttext(1.01) // หนึ่งบาทหนึ่งสตางค์
|
|
49
|
+
bahttext(5678.46) // ห้าพันหกร้อยเจ็ดสิบแปดบาทสี่สิบหกสตางค์
|
|
50
|
+
bahttext(0.67) // หกสิบเจ็ดสตางค์
|
|
51
|
+
bahttext(-3.00) // ลบสามบาทถ้วน
|
|
52
|
+
bahttext(-232.00) // ลบสองร้อยสามสิบสองบาทถ้วน
|
|
53
|
+
bahttext(-44444.00) // ลบสี่หมื่นสี่พันสี่ร้อยสี่สิบสี่บาทถ้วน
|
|
54
|
+
bahttext(-5678934.00) // ลบห้าล้านหกแสนเจ็ดหมื่นแปดพันเก้าร้อยสามสิบสี่บาทถ้วน
|
|
55
|
+
bahttext(-201.00) // ลบสองร้อยหนึ่งบาทถ้วน
|
|
56
|
+
bahttext(-317.10) // ลบสามร้อยสิบเจ็ดบาทสิบสตางค์
|
|
57
|
+
bahttext(-5723.00) // ลบห้าพันเจ็ดร้อยยี่สิบสามบาทถ้วน
|
|
58
|
+
bahttext(-11.00) // ลบสิบเอ็ดบาทถ้วน
|
|
59
|
+
bahttext(-45621.21) // ลบสี่หมื่นห้าพันหกร้อยยี่สิบเอ็ดบาทยี่สิบเอ็ดสตางค์
|
|
60
|
+
bahttext(-191415.11) // ลบหนึ่งแสนเก้าหมื่นหนึ่งพันสี่ร้อยสิบห้าบาทสิบเอ็ดสตางค์
|
|
61
|
+
bahttext(-282622.22) // ลบสองแสนแปดหมื่นสองพันหกร้อยยี่สิบสองบาทยี่สิบสองสตางค์
|
|
62
|
+
bahttext(-1.04) // ลบหนึ่งบาทสี่สตางค์
|
|
63
|
+
bahttext(-574.45) // ลบห้าร้อยเจ็ดสิบสี่บาทสี่สิบห้าสตางค์
|
|
64
|
+
bahttext(-345.23) // ลบสามร้อยสี่สิบห้าบาทยี่สิบสามสตางค์
|
|
65
|
+
bahttext(-0.20) // ลบยี่สิบสตางค์
|
|
41
66
|
```
|
|
42
67
|
|
|
43
68
|
## Note
|
|
44
69
|
- [x] Compatible with all browsers
|
|
45
|
-
- [x] Node.js version support: 6
|
|
70
|
+
- [x] Node.js version support: 6+
|
|
46
71
|
- [x] 0 Dependencies
|
|
47
72
|
- [x] Unit test
|
|
48
|
-
- [ ] Browser compatibility test
|
|
49
73
|
- [x] Remove duplication between test code and test-case-csv file
|
|
50
74
|
- [x] [Demo page](https://jojoee.github.io/bahttext/)
|
|
51
75
|
- [x] Support negative number
|
|
52
76
|
- [x] Fix semantic-release
|
|
53
77
|
|
|
78
|
+
## Other languages
|
|
79
|
+
- Python: [jojoee/pybaht](https://github.com/jojoee/pybaht)
|
|
80
|
+
|
|
54
81
|
## CMD
|
|
55
82
|
|
|
56
83
|
```
|
|
57
84
|
brew install curl
|
|
58
85
|
brew install jq
|
|
59
|
-
npm install -g
|
|
86
|
+
npm install -g csvtojson
|
|
60
87
|
curl -L -o ./misc/testcases.csv https://docs.google.com/spreadsheets/d/e/2PACX-1vTb8PIKzgo07rn9UpcjqE0YrdMAmf4fyDbL2plUieLCyrn_5O3vDvece7UfkaArWQLUSsaw92jVpY_z/pub?gid=0&single=true&output=csv
|
|
61
88
|
csvtojson ./misc/testcases.csv | jq > ./misc/testcases.json
|
|
89
|
+
|
|
90
|
+
# to update dependency version
|
|
91
|
+
npm update --save
|
|
92
|
+
npm audit fix --force
|
|
93
|
+
|
|
94
|
+
# mutation test
|
|
95
|
+
npm install -g stryker-cli
|
|
96
|
+
stryker init
|
|
97
|
+
export STRYKER_DASHBOARD_API_KEY=<the_project_api_token>
|
|
98
|
+
echo $STRYKER_DASHBOARD_API_KEY
|
|
99
|
+
npx stryker run
|
|
62
100
|
```
|
|
63
101
|
|
|
64
102
|
## Reference
|
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|

|
|
9
9
|

|
|
10
10
|

|
|
11
|
+
[](https://dashboard.stryker-mutator.io/reports/github.com/jojoee/bahttext/master)
|
|
11
12
|
|
|
12
13
|
ภาษา: [ไทย](https://github.com/jojoee/bahttext/blob/master/README.md), [English](https://github.com/jojoee/bahttext/blob/master/README-en.md)
|
|
13
14
|
|
|
@@ -35,29 +36,66 @@ import { bahttext } from "bahttext"
|
|
|
35
36
|
## ตัวอย่างการใช้งาน
|
|
36
37
|
|
|
37
38
|
```javascript
|
|
38
|
-
//
|
|
39
|
-
bahttext(
|
|
39
|
+
bahttext(8.00) // แปดบาทถ้วน
|
|
40
|
+
bahttext(5678.00) // ห้าพันหกร้อยเจ็ดสิบแปดบาทถ้วน
|
|
41
|
+
bahttext(63147.89) // หกหมื่นสามพันหนึ่งร้อยสี่สิบเจ็ดบาทแปดสิบเก้าสตางค์
|
|
42
|
+
bahttext(51000001.00) // ห้าสิบเอ็ดล้านหนึ่งบาทถ้วน
|
|
43
|
+
bahttext(317.10) // สามร้อยสิบเจ็ดบาทสิบสตางค์
|
|
44
|
+
bahttext(422.26) // สี่ร้อยยี่สิบสองบาทยี่สิบหกสตางค์
|
|
45
|
+
bahttext(11.11) // สิบเอ็ดบาทสิบเอ็ดสตางค์
|
|
46
|
+
bahttext(191415.11) // หนึ่งแสนเก้าหมื่นหนึ่งพันสี่ร้อยสิบห้าบาทสิบเอ็ดสตางค์
|
|
47
|
+
bahttext(1.01) // หนึ่งบาทหนึ่งสตางค์
|
|
48
|
+
bahttext(5678.46) // ห้าพันหกร้อยเจ็ดสิบแปดบาทสี่สิบหกสตางค์
|
|
49
|
+
bahttext(0.67) // หกสิบเจ็ดสตางค์
|
|
50
|
+
bahttext(-3.00) // ลบสามบาทถ้วน
|
|
51
|
+
bahttext(-232.00) // ลบสองร้อยสามสิบสองบาทถ้วน
|
|
52
|
+
bahttext(-44444.00) // ลบสี่หมื่นสี่พันสี่ร้อยสี่สิบสี่บาทถ้วน
|
|
53
|
+
bahttext(-5678934.00) // ลบห้าล้านหกแสนเจ็ดหมื่นแปดพันเก้าร้อยสามสิบสี่บาทถ้วน
|
|
54
|
+
bahttext(-201.00) // ลบสองร้อยหนึ่งบาทถ้วน
|
|
55
|
+
bahttext(-317.10) // ลบสามร้อยสิบเจ็ดบาทสิบสตางค์
|
|
56
|
+
bahttext(-5723.00) // ลบห้าพันเจ็ดร้อยยี่สิบสามบาทถ้วน
|
|
57
|
+
bahttext(-11.00) // ลบสิบเอ็ดบาทถ้วน
|
|
58
|
+
bahttext(-45621.21) // ลบสี่หมื่นห้าพันหกร้อยยี่สิบเอ็ดบาทยี่สิบเอ็ดสตางค์
|
|
59
|
+
bahttext(-191415.11) // ลบหนึ่งแสนเก้าหมื่นหนึ่งพันสี่ร้อยสิบห้าบาทสิบเอ็ดสตางค์
|
|
60
|
+
bahttext(-282622.22) // ลบสองแสนแปดหมื่นสองพันหกร้อยยี่สิบสองบาทยี่สิบสองสตางค์
|
|
61
|
+
bahttext(-1.04) // ลบหนึ่งบาทสี่สตางค์
|
|
62
|
+
bahttext(-574.45) // ลบห้าร้อยเจ็ดสิบสี่บาทสี่สิบห้าสตางค์
|
|
63
|
+
bahttext(-345.23) // ลบสามร้อยสี่สิบห้าบาทยี่สิบสามสตางค์
|
|
64
|
+
bahttext(-0.20) // ลบยี่สิบสตางค์
|
|
40
65
|
```
|
|
41
66
|
|
|
42
67
|
## ฟีเจอร์
|
|
43
68
|
- [x] สามารถใช้งานได้ทุก เบราว์เซอร์
|
|
44
|
-
- [x] สามารถใช้งานได้ตั้งแต่ Node.js version 6
|
|
69
|
+
- [x] สามารถใช้งานได้ตั้งแต่ Node.js version 6+
|
|
45
70
|
- [x] 0 Dependencies
|
|
46
71
|
- [x] ทำการทดสอบแบบ unit test
|
|
47
|
-
- [ ] ทดสอบบนเบราว์เซอร์ ในแต่ละ เวอร์ชั่น
|
|
48
72
|
- [x] ลดการซ้ำซ้อนของการเขียน ระหว่าง code และ ไฟล์ csv ในการทำการทดสอบ
|
|
49
73
|
- [x] [หน้าตัวอย่างการใช้งาน](https://jojoee.github.io/bahttext/)
|
|
50
74
|
- [x] สนับสนุนการใช้งานกับตัวเลขติดลบ
|
|
51
75
|
- [x] แก้ไข semantic-release
|
|
52
76
|
|
|
77
|
+
## ภาษาอื่นๆ
|
|
78
|
+
- Python: [jojoee/pybaht](https://github.com/jojoee/pybaht)
|
|
79
|
+
|
|
53
80
|
## CMD
|
|
54
81
|
|
|
55
82
|
```
|
|
56
83
|
brew install curl
|
|
57
84
|
brew install jq
|
|
58
|
-
npm install -g
|
|
85
|
+
npm install -g csvtojson
|
|
59
86
|
curl -L -o ./misc/testcases.csv https://docs.google.com/spreadsheets/d/e/2PACX-1vTb8PIKzgo07rn9UpcjqE0YrdMAmf4fyDbL2plUieLCyrn_5O3vDvece7UfkaArWQLUSsaw92jVpY_z/pub?gid=0&single=true&output=csv
|
|
60
87
|
csvtojson ./misc/testcases.csv | jq > ./misc/testcases.json
|
|
88
|
+
|
|
89
|
+
# to update dependency version
|
|
90
|
+
npm update --save
|
|
91
|
+
npm audit fix --force
|
|
92
|
+
|
|
93
|
+
# mutation test
|
|
94
|
+
npm install -g stryker-cli
|
|
95
|
+
stryker init
|
|
96
|
+
export STRYKER_DASHBOARD_API_KEY=<the_project_api_token>
|
|
97
|
+
echo $STRYKER_DASHBOARD_API_KEY
|
|
98
|
+
npx stryker run
|
|
61
99
|
```
|
|
62
100
|
|
|
63
101
|
## อ้างอิง
|
package/index.html
CHANGED
|
@@ -74,12 +74,15 @@ function updateResult() {
|
|
|
74
74
|
$result.html(html)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
function
|
|
77
|
+
function randomNumber() {
|
|
78
|
+
const num = r.real(Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)
|
|
79
|
+
$number.val(num)
|
|
78
80
|
updateResult()
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
$(document).ready(function() {
|
|
82
|
-
init
|
|
84
|
+
// init
|
|
85
|
+
randomNumber()
|
|
83
86
|
|
|
84
87
|
// number
|
|
85
88
|
$number.on('input', function(e) {
|
|
@@ -88,9 +91,7 @@ $(document).ready(function() {
|
|
|
88
91
|
|
|
89
92
|
// random
|
|
90
93
|
$random.click(function(e) {
|
|
91
|
-
|
|
92
|
-
$number.val(num)
|
|
93
|
-
updateResult()
|
|
94
|
+
randomNumber()
|
|
94
95
|
})
|
|
95
96
|
|
|
96
97
|
// example
|
package/package.json
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bahttext",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Change number to Thai pronunciation string",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"typings": "src/index.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"jest": "jest",
|
|
9
9
|
"jest.watch": "jest --watch",
|
|
10
|
-
"commit": "git-cz",
|
|
11
10
|
"coverage.check": "jest --coverage",
|
|
12
11
|
"semantic-release": "semantic-release",
|
|
13
12
|
"standard": "standard",
|
|
13
|
+
"standard.fix": "standard --fix",
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"test.watch": "jest --watch",
|
|
14
16
|
"validate": "npm run standard && npm run coverage.check"
|
|
15
17
|
},
|
|
16
|
-
"config": {
|
|
17
|
-
"ghooks": {
|
|
18
|
-
"pre-commit": "npm run validate"
|
|
19
|
-
},
|
|
20
|
-
"commitizen": {
|
|
21
|
-
"path": "node_modules/cz-conventional-changelog"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
18
|
"repository": {
|
|
25
19
|
"type": "git",
|
|
26
20
|
"url": "https://github.com/jojoee/bahttext.git"
|
|
@@ -39,15 +33,13 @@
|
|
|
39
33
|
"url": "https://github.com/jojoee/bahttext/issues"
|
|
40
34
|
},
|
|
41
35
|
"homepage": "https://github.com/jojoee/bahttext#readme",
|
|
42
|
-
"dependencies": {},
|
|
43
36
|
"devDependencies": {
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"jest": "^26.6.1",
|
|
37
|
+
"@stryker-mutator/core": "^6.3.1",
|
|
38
|
+
"@stryker-mutator/jest-runner": "^6.3.1",
|
|
39
|
+
"jest": "^26.6.3",
|
|
48
40
|
"jest-expect-message": "^1.0.2",
|
|
49
|
-
"semantic-release": "^
|
|
50
|
-
"standard": "^15.0.
|
|
41
|
+
"semantic-release": "^19.0.5",
|
|
42
|
+
"standard": "^15.0.1"
|
|
51
43
|
},
|
|
52
44
|
"jest": {
|
|
53
45
|
"setupFilesAfterEnv": [
|
package/src/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const bahtxtConst = {
|
|
2
|
+
defaultResult: 'ศูนย์บาทถ้วน',
|
|
3
|
+
singleUnitStrs: ['', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า'],
|
|
4
|
+
placeNameStrs: ['', 'สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน', 'ล้าน']
|
|
5
|
+
}
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @param {number[]} nums
|
|
7
9
|
* @returns {string}
|
|
8
10
|
*/
|
|
9
|
-
function
|
|
11
|
+
function bahtxtNum2Word (nums) {
|
|
10
12
|
let result = ''
|
|
11
13
|
const len = nums.length
|
|
12
14
|
const maxLen = 7
|
|
@@ -16,12 +18,12 @@ function num2Word (nums) {
|
|
|
16
18
|
const overflowIndex = len - maxLen + 1
|
|
17
19
|
const overflowNums = nums.slice(0, overflowIndex)
|
|
18
20
|
const remainingNumbs = nums.slice(overflowIndex)
|
|
19
|
-
return
|
|
21
|
+
return bahtxtNum2Word(overflowNums) + 'ล้าน' + bahtxtNum2Word(remainingNumbs)
|
|
20
22
|
} else {
|
|
21
23
|
for (let i = 0; i < len; i++) {
|
|
22
24
|
const digit = nums[i]
|
|
23
25
|
if (digit > 0) {
|
|
24
|
-
result += singleUnitStrs[digit] + placeNameStrs[len - i - 1]
|
|
26
|
+
result += bahtxtConst.singleUnitStrs[digit] + bahtxtConst.placeNameStrs[len - i - 1]
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
}
|
|
@@ -34,7 +36,7 @@ function num2Word (nums) {
|
|
|
34
36
|
* @param {string} str
|
|
35
37
|
* @returns {string}
|
|
36
38
|
*/
|
|
37
|
-
function
|
|
39
|
+
function bahtxtGrammarFix (str) {
|
|
38
40
|
let result = str
|
|
39
41
|
|
|
40
42
|
result = result.replace(/หนึ่งสิบ/g, 'สิบ')
|
|
@@ -45,18 +47,18 @@ function grammarFix (str) {
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/**
|
|
48
|
-
*
|
|
50
|
+
* bahtxtCombine baht and satang
|
|
49
51
|
* and also adding unit
|
|
50
52
|
*
|
|
51
53
|
* @param {string} baht
|
|
52
54
|
* @param {string} satang
|
|
53
55
|
* @returns {string}
|
|
54
56
|
*/
|
|
55
|
-
function
|
|
57
|
+
function bahtxtCombine (baht, satang) {
|
|
56
58
|
let result = ''
|
|
57
59
|
|
|
58
60
|
if (baht === '' && satang === '') {
|
|
59
|
-
result = defaultResult
|
|
61
|
+
result = bahtxtConst.defaultResult
|
|
60
62
|
} else if (baht !== '' && satang === '') {
|
|
61
63
|
result = baht + 'บาท' + 'ถ้วน'
|
|
62
64
|
} else if (baht === '' && satang !== '') {
|
|
@@ -76,15 +78,15 @@ function combine (baht, satang) {
|
|
|
76
78
|
*/
|
|
77
79
|
function bahttext (num) {
|
|
78
80
|
// no null
|
|
79
|
-
if (!num) return defaultResult
|
|
81
|
+
if (!num) return bahtxtConst.defaultResult
|
|
80
82
|
// no boolean
|
|
81
|
-
if (typeof num === 'boolean') return defaultResult
|
|
83
|
+
if (typeof num === 'boolean') return bahtxtConst.defaultResult
|
|
82
84
|
// must be number only
|
|
83
|
-
if (isNaN(Number(num))) return defaultResult
|
|
85
|
+
if (isNaN(Number(num))) return bahtxtConst.defaultResult
|
|
84
86
|
// not less than Number.MIN_SAFE_INTEGER
|
|
85
|
-
if (num < Number.MIN_SAFE_INTEGER) return defaultResult
|
|
87
|
+
if (num < Number.MIN_SAFE_INTEGER) return bahtxtConst.defaultResult
|
|
86
88
|
// no more than Number.MAX_SAFE_INTEGER
|
|
87
|
-
if (num > Number.MAX_SAFE_INTEGER) return defaultResult
|
|
89
|
+
if (num > Number.MAX_SAFE_INTEGER) return bahtxtConst.defaultResult
|
|
88
90
|
|
|
89
91
|
// set
|
|
90
92
|
const positiveNum = Math.abs(num)
|
|
@@ -100,15 +102,15 @@ function bahttext (num) {
|
|
|
100
102
|
const satangArr = Array.from(satangStr).map(Number)
|
|
101
103
|
|
|
102
104
|
// proceed
|
|
103
|
-
let baht =
|
|
104
|
-
let satang =
|
|
105
|
+
let baht = bahtxtNum2Word(bahtArr)
|
|
106
|
+
let satang = bahtxtNum2Word(satangArr)
|
|
105
107
|
|
|
106
108
|
// grammar
|
|
107
|
-
baht =
|
|
108
|
-
satang =
|
|
109
|
+
baht = bahtxtGrammarFix(baht)
|
|
110
|
+
satang = bahtxtGrammarFix(satang)
|
|
109
111
|
|
|
110
112
|
// combine
|
|
111
|
-
const result =
|
|
113
|
+
const result = bahtxtCombine(baht, satang)
|
|
112
114
|
|
|
113
115
|
return num >= 0 ? result : 'ลบ' + result
|
|
114
116
|
}
|
|
@@ -116,7 +118,12 @@ function bahttext (num) {
|
|
|
116
118
|
if (typeof module !== 'undefined' &&
|
|
117
119
|
module.exports != null) {
|
|
118
120
|
module.exports = {
|
|
119
|
-
bahttext
|
|
121
|
+
bahttext,
|
|
122
|
+
|
|
123
|
+
// export for testing only
|
|
124
|
+
bahtxtNum2Word,
|
|
125
|
+
bahtxtGrammarFix,
|
|
126
|
+
bahtxtCombine
|
|
120
127
|
}
|
|
121
128
|
exports.default = {
|
|
122
129
|
bahttext
|
package/src/index.test.js
CHANGED
|
@@ -1,9 +1,58 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {
|
|
2
|
+
bahttext,
|
|
3
|
+
bahtxtGrammarFix: grammarFix,
|
|
4
|
+
bahtxtCombine: combine
|
|
5
|
+
} = require('./index')
|
|
2
6
|
const defaultResult = 'ศูนย์บาทถ้วน'
|
|
3
7
|
const testCases = require('../misc/testcases.json')
|
|
4
8
|
jest.autoMockOff()
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
// TODO: to be implemented
|
|
11
|
+
describe('num2Word', () => {
|
|
12
|
+
test('test', () => {
|
|
13
|
+
expect(true).toBeTruthy()
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('grammarFix', () => {
|
|
18
|
+
test('replace "หนึ่งสิบ" with "สิบ"', () => {
|
|
19
|
+
expect(grammarFix('หนึ่งสิบหก')).toBe('สิบหก')
|
|
20
|
+
expect(grammarFix('หนึ่งสิบสี่')).toBe('สิบสี่')
|
|
21
|
+
expect(grammarFix('ห้าร้อยหนึ่งสิบสาม')).toBe('ห้าร้อยสิบสาม')
|
|
22
|
+
expect(grammarFix('สี่หมื่นหนึ่งสิบสาม')).toBe('สี่หมื่นสิบสาม')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('replace "สองสิบ" with "ยี่สิบ"', () => {
|
|
26
|
+
expect(grammarFix('ห้าร้อยสองสิบหนึ่ง')).toBe('ห้าร้อยยี่สิบเอ็ด')
|
|
27
|
+
expect(grammarFix('สองสิบสี่')).toBe('ยี่สิบสี่')
|
|
28
|
+
expect(grammarFix('เก้าแสนหกหมื่นสามพันสามร้อยสองสิบสี่')).toBe('เก้าแสนหกหมื่นสามพันสามร้อยยี่สิบสี่')
|
|
29
|
+
expect(grammarFix('เจ็ดหมื่นห้าพันสี่ร้อยสองสิบหนึ่ง')).toBe('เจ็ดหมื่นห้าพันสี่ร้อยยี่สิบเอ็ด')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('replace "สิบหนึ่ง" with "สิบเอ็ด"', () => {
|
|
33
|
+
expect(grammarFix('หนึ่งสิบหนึ่ง')).toBe('สิบเอ็ด')
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('combine', () => {
|
|
38
|
+
test('both baht and satang are empty', () => {
|
|
39
|
+
expect(combine('', '')).toBe('ศูนย์บาทถ้วน')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('both baht and satang are not empty', () => {
|
|
43
|
+
expect(combine('หนึ่งร้อยยี่สิบสาม', 'ห้าสิบหก')).toBe('หนึ่งร้อยยี่สิบสามบาทห้าสิบหกสตางค์')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('has only baht', () => {
|
|
47
|
+
expect(combine('แปดแสนเจ็ดหมื่นสี่พันห้าร้อยหกสิบสาม', '')).toBe('แปดแสนเจ็ดหมื่นสี่พันห้าร้อยหกสิบสามบาทถ้วน')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('has only satang', () => {
|
|
51
|
+
expect(combine('', 'ลบสามสิบหก')).toBe('ลบสามสิบหกสตางค์')
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe('bahttext', () => {
|
|
7
56
|
test('invalid number', () => {
|
|
8
57
|
const zeroText = 'ศูนย์บาทถ้วน'
|
|
9
58
|
|
|
@@ -18,6 +67,14 @@ describe('misc', () => {
|
|
|
18
67
|
expect(bahttext(undefined)).toBe(zeroText)
|
|
19
68
|
expect(bahttext('this-is-not-number')).toBe(zeroText)
|
|
20
69
|
expect(bahttext('it-must-be-number-only')).toBe(zeroText)
|
|
70
|
+
expect(bahttext('a123')).toBe(zeroText)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('leading with zero', () => {
|
|
74
|
+
expect(bahttext('0.1')).toBe('สิบสตางค์')
|
|
75
|
+
expect(bahttext('01.1')).toBe('หนึ่งบาทสิบสตางค์')
|
|
76
|
+
expect(bahttext('-01.1')).toBe('ลบหนึ่งบาทสิบสตางค์')
|
|
77
|
+
expect(bahttext('000.01')).toBe('หนึ่งสตางค์')
|
|
21
78
|
})
|
|
22
79
|
|
|
23
80
|
test('less than Number.MIN_SAFE_INTEGER', () => {
|
|
@@ -33,10 +90,8 @@ describe('misc', () => {
|
|
|
33
90
|
expect(bahttext(Number.MAX_SAFE_INTEGER + items[i])).toBe(defaultResult)
|
|
34
91
|
}
|
|
35
92
|
})
|
|
36
|
-
})
|
|
37
93
|
|
|
38
|
-
|
|
39
|
-
test('imported from Google Sheet', () => {
|
|
94
|
+
test('numbers are imported from Google Sheet', () => {
|
|
40
95
|
for (let i = 0; i < testCases.length; i++) {
|
|
41
96
|
const customMessage = JSON.stringify(testCases[i])
|
|
42
97
|
const number = Number(testCases[i].number)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
|
|
3
|
+
"_comment": "This config was generated using 'stryker init'. Please take a look at: https://stryker-mutator.io/docs/stryker-js/configuration/ for more information.",
|
|
4
|
+
"packageManager": "npm",
|
|
5
|
+
"reporters": [
|
|
6
|
+
"json",
|
|
7
|
+
"progress",
|
|
8
|
+
"html",
|
|
9
|
+
"dashboard"
|
|
10
|
+
],
|
|
11
|
+
"testRunner": "jest",
|
|
12
|
+
"testRunner_comment": "Take a look at https://stryker-mutator.io/docs/stryker-js/jest-runner for information about the jest plugin.",
|
|
13
|
+
"thresholds": {
|
|
14
|
+
"high": 85,
|
|
15
|
+
"low": 80,
|
|
16
|
+
"break": 75
|
|
17
|
+
},
|
|
18
|
+
"dashboard": {
|
|
19
|
+
"project": "github.com/jojoee/bahttext",
|
|
20
|
+
"version": "master",
|
|
21
|
+
"baseUrl": "https://dashboard.stryker-mutator.io/api/reports",
|
|
22
|
+
"reportType": "full"
|
|
23
|
+
},
|
|
24
|
+
"coverageAnalysis": "perTest"
|
|
25
|
+
}
|