bahttext 2.1.3 → 2.3.0
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 +27 -38
- package/README.md +32 -41
- package/package.json +6 -4
- package/src/index.d.ts +35 -0
- package/src/index.js +4 -0
- package/benchmark.js +0 -29
- package/bower.json +0 -21
- package/index.html +0 -127
- package/src/index.test.js +0 -101
- package/stryker.conf.json +0 -25
package/README-en.md
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
# bahttext
|
|
2
2
|
|
|
3
|
-
[](https://codecov.io/github/jojoee/bahttext)
|
|
4
3
|
[](https://www.npmjs.com/package/bahttext)
|
|
5
4
|
[](http://opensource.org/licenses/MIT)
|
|
6
5
|
[](https://github.com/semantic-release/semantic-release) [](https://greenkeeper.io/)
|
|
7
|
-
|
|
8
|
-

|
|
9
|
-

|
|
10
|
-

|
|
11
|
-

|
|
6
|
+
[](https://codecov.io/github/jojoee/bahttext)
|
|
12
7
|
[](https://dashboard.stryker-mutator.io/reports/github.com/jojoee/bahttext/master)
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
[](https://github.com/jojoee/bahttext/actions/workflows/continuous-integration.yml)
|
|
10
|
+
[](https://github.com/jojoee/bahttext/actions/workflows/release.yml)
|
|
11
|
+
[](https://github.com/jojoee/bahttext/actions/workflows/runnable.yml)
|
|
12
|
+
[](https://github.com/jojoee/bahttext/actions/workflows/runnable-old-node.yml)
|
|
13
|
+
|
|
14
|
+
Only `TH` and `EN` languages are maintained, the rest is auto-generated by ChatGPT API. Language:
|
|
15
|
+
[ไทย](https://github.com/jojoee/bahttext/blob/master/README.md),
|
|
16
|
+
[English](https://github.com/jojoee/bahttext/blob/master/README-en.md),
|
|
17
|
+
[中国大陆](https://github.com/jojoee/bahttext/blob/master/doc/README-cn.md),
|
|
18
|
+
[대한민국](https://github.com/jojoee/bahttext/blob/master/doc/README-kr.md),
|
|
19
|
+
[Việt Nam](https://github.com/jojoee/bahttext/blob/master/doc/README-vn.md),
|
|
20
|
+
[日本](https://github.com/jojoee/bahttext/blob/master/doc/README-jp.md),
|
|
21
|
+
[Россия](https://github.com/jojoee/bahttext/blob/master/doc/README-ru.md),
|
|
22
|
+
[Español](https://github.com/jojoee/bahttext/blob/master/doc/README-la.md),
|
|
23
|
+
[Français](https://github.com/jojoee/bahttext/blob/master/doc/README-fr.md)
|
|
24
|
+
|
|
25
|
+
Change number to Thai pronunciation string, test
|
|
26
|
+
against [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en), [Demo page](https://jojoee.github.io/bahttext/)
|
|
17
27
|
|
|
18
28
|
## Installation
|
|
19
29
|
|
|
@@ -66,40 +76,19 @@ bahttext(-0.20) // ลบยี่สิบสตางค์
|
|
|
66
76
|
```
|
|
67
77
|
|
|
68
78
|
## Note
|
|
69
|
-
- [x] Compatible with all browsers
|
|
70
|
-
- [x] Node.js version support: 6+
|
|
71
|
-
- [x] 0 Dependencies
|
|
72
|
-
- [x] Unit test
|
|
73
|
-
- [x] Remove duplication between test code and test-case-csv file
|
|
74
|
-
- [x] [Demo page](https://jojoee.github.io/bahttext/)
|
|
75
|
-
- [x] Support negative number
|
|
76
|
-
- [x] Fix semantic-release
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
-
|
|
80
|
+
- Compatible with all browsers
|
|
81
|
+
- Node.js version support: 6+
|
|
82
|
+
- 0 Dependencies
|
|
83
|
+
- Demo page
|
|
84
|
+
- Support negative number
|
|
80
85
|
|
|
81
|
-
##
|
|
86
|
+
## Other languages
|
|
82
87
|
|
|
83
|
-
|
|
84
|
-
brew install curl
|
|
85
|
-
brew install jq
|
|
86
|
-
npm install -g csvtojson
|
|
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
|
|
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
|
|
100
|
-
```
|
|
88
|
+
- Python: [jojoee/pybaht](https://github.com/jojoee/pybaht)
|
|
101
89
|
|
|
102
90
|
## Reference
|
|
91
|
+
|
|
103
92
|
- [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en)
|
|
104
93
|
- [Microsoft Office's BAHTTEXT function](https://support.office.com/en-us/article/BAHTTEXT-function-5ba4d0b4-abd3-4325-8d22-7a92d59aab9c)
|
|
105
94
|
- Inspired by [earthchie/BAHTTEXT.js](https://github.com/earthchie/BAHTTEXT.js)
|
package/README.md
CHANGED
|
@@ -1,34 +1,46 @@
|
|
|
1
1
|
# bahttext
|
|
2
2
|
|
|
3
|
-
[](https://codecov.io/github/jojoee/bahttext)
|
|
4
3
|
[](https://www.npmjs.com/package/bahttext)
|
|
5
4
|
[](http://opensource.org/licenses/MIT)
|
|
6
5
|
[](https://github.com/semantic-release/semantic-release) [](https://greenkeeper.io/)
|
|
7
|
-

|
|
9
|
-

|
|
10
|
-

|
|
6
|
+
[](https://codecov.io/github/jojoee/bahttext)
|
|
11
7
|
[](https://dashboard.stryker-mutator.io/reports/github.com/jojoee/bahttext/master)
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
[](https://github.com/jojoee/bahttext/actions/workflows/continuous-integration.yml)
|
|
10
|
+
[](https://github.com/jojoee/bahttext/actions/workflows/release.yml)
|
|
11
|
+
[](https://github.com/jojoee/bahttext/actions/workflows/runnable.yml)
|
|
12
|
+
[](https://github.com/jojoee/bahttext/actions/workflows/runnable-old-node.yml)
|
|
13
|
+
|
|
14
|
+
Only `TH` and `EN` languages are maintained, the rest is auto-generated by ChatGPT API. Language:
|
|
15
|
+
[ไทย](https://github.com/jojoee/bahttext/blob/master/README.md),
|
|
16
|
+
[English](https://github.com/jojoee/bahttext/blob/master/README-en.md),
|
|
17
|
+
[中国大陆](https://github.com/jojoee/bahttext/blob/master/doc/README-cn.md),
|
|
18
|
+
[대한민국](https://github.com/jojoee/bahttext/blob/master/doc/README-kr.md),
|
|
19
|
+
[Việt Nam](https://github.com/jojoee/bahttext/blob/master/doc/README-vn.md),
|
|
20
|
+
[日本](https://github.com/jojoee/bahttext/blob/master/doc/README-jp.md),
|
|
21
|
+
[Россия](https://github.com/jojoee/bahttext/blob/master/doc/README-ru.md),
|
|
22
|
+
[Español](https://github.com/jojoee/bahttext/blob/master/doc/README-la.md),
|
|
23
|
+
[Français](https://github.com/jojoee/bahttext/blob/master/doc/README-fr.md)
|
|
24
|
+
|
|
25
|
+
เปลี่ยนตัวเลข เป็นคำอ่านภาษาไทย,
|
|
26
|
+
โมดูลตัวนี้ได้ทำการทดสอบกับ [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en), [Demo page](https://jojoee.github.io/bahttext/)
|
|
27
|
+
เรียบร้อยแล้ว
|
|
16
28
|
|
|
17
29
|
## ติดตั้ง
|
|
18
30
|
|
|
19
31
|
```
|
|
20
|
-
//
|
|
32
|
+
// CommonJS
|
|
21
33
|
npm install bahttext
|
|
22
34
|
const { bahttext } = require('bahttext')
|
|
23
35
|
|
|
24
|
-
//
|
|
36
|
+
// Bower
|
|
25
37
|
bower install bahttext
|
|
26
38
|
<script src="bower_components/bahttext/src/index.js"></script>
|
|
27
39
|
|
|
28
|
-
//
|
|
40
|
+
// githack
|
|
29
41
|
<script src="https://raw.githack.com/jojoee/bahttext/master/src/index.js"></script>
|
|
30
42
|
|
|
31
|
-
//
|
|
43
|
+
// ES6
|
|
32
44
|
npm install bahttext
|
|
33
45
|
import { bahttext } from "bahttext"
|
|
34
46
|
```
|
|
@@ -65,40 +77,19 @@ bahttext(-0.20) // ลบยี่สิบสตางค์
|
|
|
65
77
|
```
|
|
66
78
|
|
|
67
79
|
## ฟีเจอร์
|
|
68
|
-
- [x] สามารถใช้งานได้ทุก เบราว์เซอร์
|
|
69
|
-
- [x] สามารถใช้งานได้ตั้งแต่ Node.js version 6+
|
|
70
|
-
- [x] 0 Dependencies
|
|
71
|
-
- [x] ทำการทดสอบแบบ unit test
|
|
72
|
-
- [x] ลดการซ้ำซ้อนของการเขียน ระหว่าง code และ ไฟล์ csv ในการทำการทดสอบ
|
|
73
|
-
- [x] [หน้าตัวอย่างการใช้งาน](https://jojoee.github.io/bahttext/)
|
|
74
|
-
- [x] สนับสนุนการใช้งานกับตัวเลขติดลบ
|
|
75
|
-
- [x] แก้ไข semantic-release
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
-
|
|
81
|
+
- สามารถใช้งานได้ทุก เบราว์เซอร์
|
|
82
|
+
- สามารถใช้งานได้ตั้งแต่ Node.js version 6+
|
|
83
|
+
- 0 Dependencies
|
|
84
|
+
- หน้าตัวอย่างการใช้งาน
|
|
85
|
+
- สนับสนุนการใช้งานกับตัวเลขติดลบ
|
|
79
86
|
|
|
80
|
-
##
|
|
87
|
+
## ภาษาอื่นๆ
|
|
81
88
|
|
|
82
|
-
|
|
83
|
-
brew install curl
|
|
84
|
-
brew install jq
|
|
85
|
-
npm install -g csvtojson
|
|
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
|
|
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
|
|
99
|
-
```
|
|
89
|
+
- Python: [jojoee/pybaht](https://github.com/jojoee/pybaht)
|
|
100
90
|
|
|
101
91
|
## อ้างอิง
|
|
92
|
+
|
|
102
93
|
- [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en)
|
|
103
94
|
- [Microsoft Office's BAHTTEXT function](https://support.office.com/en-us/article/BAHTTEXT-function-5ba4d0b4-abd3-4325-8d22-7a92d59aab9c)
|
|
104
95
|
- แรงบัลดาลใจจาก [earthchie/BAHTTEXT.js](https://github.com/earthchie/BAHTTEXT.js)
|
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bahttext",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Change number to Thai pronunciation string",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
-
"typings": "src/index.
|
|
6
|
+
"typings": "src/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"jest": "jest",
|
|
9
9
|
"jest.watch": "jest --watch",
|
|
10
10
|
"coverage.check": "jest --coverage",
|
|
11
|
+
"build": "tsc",
|
|
11
12
|
"semantic-release": "semantic-release",
|
|
12
13
|
"standard": "standard",
|
|
13
14
|
"standard.fix": "standard --fix",
|
|
14
15
|
"test": "jest",
|
|
15
16
|
"test.watch": "jest --watch",
|
|
16
|
-
"validate": "npm run standard && npm run coverage.check"
|
|
17
|
+
"validate": "npm run standard && npm run coverage.check && npm run build"
|
|
17
18
|
},
|
|
18
19
|
"repository": {
|
|
19
20
|
"type": "git",
|
|
@@ -43,7 +44,8 @@
|
|
|
43
44
|
"semantic-release": "^19.0.5",
|
|
44
45
|
"standard": "^15.0.1",
|
|
45
46
|
"thai-baht-text": "^1.0.8",
|
|
46
|
-
"thai-baht-text-ts": "^1.1.0"
|
|
47
|
+
"thai-baht-text-ts": "^1.1.0",
|
|
48
|
+
"typescript": "*"
|
|
47
49
|
},
|
|
48
50
|
"jest": {
|
|
49
51
|
"setupFilesAfterEnv": [
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { bahttext };
|
|
3
|
+
}
|
|
4
|
+
export default _default;
|
|
5
|
+
/**
|
|
6
|
+
* Change number to Thai pronunciation string
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
* @param {number} num
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export function bahttext(num: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* @private
|
|
15
|
+
* @param {number[]} nums
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
export function bahtxtNum2Word(nums: number[]): string;
|
|
19
|
+
/**
|
|
20
|
+
* @private
|
|
21
|
+
* @todo improve performance
|
|
22
|
+
* @param {string} str
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
25
|
+
export function bahtxtGrammarFix(str: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* bahtxtCombine baht and satang
|
|
28
|
+
* and also adding unit
|
|
29
|
+
*
|
|
30
|
+
* @private
|
|
31
|
+
* @param {string} baht
|
|
32
|
+
* @param {string} satang
|
|
33
|
+
* @returns {string}
|
|
34
|
+
*/
|
|
35
|
+
export function bahtxtCombine(baht: string, satang: string): string;
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const bahtxtConst = {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
+
* @private
|
|
8
9
|
* @param {number[]} nums
|
|
9
10
|
* @returns {string}
|
|
10
11
|
*/
|
|
@@ -32,6 +33,7 @@ function bahtxtNum2Word (nums) {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
36
|
+
* @private
|
|
35
37
|
* @todo improve performance
|
|
36
38
|
* @param {string} str
|
|
37
39
|
* @returns {string}
|
|
@@ -46,6 +48,7 @@ function bahtxtGrammarFix (str) {
|
|
|
46
48
|
* bahtxtCombine baht and satang
|
|
47
49
|
* and also adding unit
|
|
48
50
|
*
|
|
51
|
+
* @private
|
|
49
52
|
* @param {string} baht
|
|
50
53
|
* @param {string} satang
|
|
51
54
|
* @returns {string}
|
|
@@ -65,6 +68,7 @@ function bahtxtCombine (baht, satang) {
|
|
|
65
68
|
/**
|
|
66
69
|
* Change number to Thai pronunciation string
|
|
67
70
|
*
|
|
71
|
+
* @public
|
|
68
72
|
* @param {number} num
|
|
69
73
|
* @returns {string}
|
|
70
74
|
*/
|
package/benchmark.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const { bahttext } = require('./src')
|
|
2
|
-
const THBText = require('thai-baht-text')
|
|
3
|
-
const { ThaiBaht } = require('thai-baht-text-ts')
|
|
4
|
-
const { convert } = require('baht')
|
|
5
|
-
|
|
6
|
-
const allTestcases = require('./misc/testcases.json')
|
|
7
|
-
const nTestCases = allTestcases.length
|
|
8
|
-
const testcases = allTestcases.slice(0, nTestCases)
|
|
9
|
-
const numbers = testcases.map(item => parseFloat(item.number))
|
|
10
|
-
const nIterations = 10000
|
|
11
|
-
|
|
12
|
-
const testedLib = {
|
|
13
|
-
bahttext: n => bahttext(n),
|
|
14
|
-
baht: n => convert(n),
|
|
15
|
-
'thai-baht-text': n => THBText(n),
|
|
16
|
-
'thai-baht-text-ts': n => ThaiBaht(n)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
Object.entries(testedLib).forEach(([name, fn]) => {
|
|
20
|
-
const start = new Date()
|
|
21
|
-
|
|
22
|
-
new Array(nIterations).fill(0).forEach(_ => {
|
|
23
|
-
numbers.forEach(number => fn(number))
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
const end = new Date()
|
|
27
|
-
const elapsed = end - start
|
|
28
|
-
console.log(`${name}: elapsed: ${elapsed} ms, start: ${start.toISOString()}, end: ${end.toISOString()}`)
|
|
29
|
-
})
|
package/bower.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "bahttext",
|
|
3
|
-
"homepage": "https://github.com/jojoee/bahttext",
|
|
4
|
-
"authors": [
|
|
5
|
-
"Nathachai Thongniran <inid3a@gmail.com>"
|
|
6
|
-
],
|
|
7
|
-
"description": "Change number to Thai pronunciation string",
|
|
8
|
-
"main": "src/index.js",
|
|
9
|
-
"keywords": [
|
|
10
|
-
"baht",
|
|
11
|
-
"thai"
|
|
12
|
-
],
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"ignore": [
|
|
15
|
-
"**/.*",
|
|
16
|
-
"node_modules",
|
|
17
|
-
"bower_components",
|
|
18
|
-
"test",
|
|
19
|
-
"tests"
|
|
20
|
-
]
|
|
21
|
-
}
|
package/index.html
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
7
|
-
<title>bahttext.js</title>
|
|
8
|
-
<link href='//fonts.googleapis.com/css?family=Raleway:400,300,600' rel='stylesheet' type='text/css'>
|
|
9
|
-
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
|
|
10
|
-
<link rel="stylesheet" href="//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
|
|
11
|
-
<style>
|
|
12
|
-
table {
|
|
13
|
-
table-layout: fixed
|
|
14
|
-
}
|
|
15
|
-
td {
|
|
16
|
-
overflow: hidden;
|
|
17
|
-
white-space: nowrap;
|
|
18
|
-
text-overflow: ellipsis;
|
|
19
|
-
}
|
|
20
|
-
</style>
|
|
21
|
-
</head>
|
|
22
|
-
<body>
|
|
23
|
-
<div class="container">
|
|
24
|
-
<div class="row">
|
|
25
|
-
<h2>bahttext.js</h2>
|
|
26
|
-
<hr>
|
|
27
|
-
|
|
28
|
-
<input type="text" id="number" class="u-full-width" placeholder="number">
|
|
29
|
-
<div id="result" class="u-full-width"></div><br>
|
|
30
|
-
<button id="random">
|
|
31
|
-
Random
|
|
32
|
-
</button>
|
|
33
|
-
<hr>
|
|
34
|
-
|
|
35
|
-
<h4>Example</h4>
|
|
36
|
-
<table id="example" class="display" cellspacing="0" width="100%">
|
|
37
|
-
<thead>
|
|
38
|
-
<tr>
|
|
39
|
-
<th>category</th>
|
|
40
|
-
<th>case</th>
|
|
41
|
-
<th>number</th>
|
|
42
|
-
<th>text</th>
|
|
43
|
-
</tr>
|
|
44
|
-
</thead>
|
|
45
|
-
<tfoot>
|
|
46
|
-
<tr>
|
|
47
|
-
<th>category</th>
|
|
48
|
-
<th>case</th>
|
|
49
|
-
<th>number</th>
|
|
50
|
-
<th>text</th>
|
|
51
|
-
</tr>
|
|
52
|
-
</tfoot>
|
|
53
|
-
</table>
|
|
54
|
-
</div>
|
|
55
|
-
</div>
|
|
56
|
-
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
|
57
|
-
<script src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
|
|
58
|
-
<script src="//cdnjs.cloudflare.com/ajax/libs/random-js/1.0.8/random.min.js"></script>
|
|
59
|
-
<script src="./src/index.js"></script>
|
|
60
|
-
<script>
|
|
61
|
-
// random
|
|
62
|
-
const r = new Random(Random.engines.mt19937().autoSeed())
|
|
63
|
-
|
|
64
|
-
const $number = $('#number')
|
|
65
|
-
const $result = $('#result')
|
|
66
|
-
const $random = $('#random')
|
|
67
|
-
const $exmaple = $('#example')
|
|
68
|
-
|
|
69
|
-
function updateResult() {
|
|
70
|
-
const val = $number.val()
|
|
71
|
-
const num = parseFloat(val)
|
|
72
|
-
const html = bahttext(num)
|
|
73
|
-
|
|
74
|
-
$result.html(html)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function randomNumber() {
|
|
78
|
-
const num = r.real(Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)
|
|
79
|
-
$number.val(num)
|
|
80
|
-
updateResult()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
$(document).ready(function() {
|
|
84
|
-
// init
|
|
85
|
-
randomNumber()
|
|
86
|
-
|
|
87
|
-
// number
|
|
88
|
-
$number.on('input', function(e) {
|
|
89
|
-
updateResult()
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
// random
|
|
93
|
-
$random.click(function(e) {
|
|
94
|
-
randomNumber()
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
// example
|
|
98
|
-
$exmaple.DataTable({
|
|
99
|
-
paging: false,
|
|
100
|
-
searching: false,
|
|
101
|
-
ordering: false,
|
|
102
|
-
ajax: {
|
|
103
|
-
url: 'misc/testcases.json',
|
|
104
|
-
dataSrc: ''
|
|
105
|
-
},
|
|
106
|
-
columns: [
|
|
107
|
-
{
|
|
108
|
-
data: 'category',
|
|
109
|
-
width: '10%'
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
data: 'case',
|
|
113
|
-
width: '16%'
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
data: 'number',
|
|
117
|
-
width: '22%'
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
data: 'text'
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
})
|
|
124
|
-
})
|
|
125
|
-
</script>
|
|
126
|
-
</body>
|
|
127
|
-
</html>
|
package/src/index.test.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
bahttext,
|
|
3
|
-
bahtxtGrammarFix: grammarFix,
|
|
4
|
-
bahtxtCombine: combine
|
|
5
|
-
} = require('./index')
|
|
6
|
-
const defaultResult = 'ศูนย์บาทถ้วน'
|
|
7
|
-
const testCases = require('../misc/testcases.json')
|
|
8
|
-
jest.autoMockOff()
|
|
9
|
-
|
|
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', () => {
|
|
56
|
-
test('invalid number', () => {
|
|
57
|
-
const zeroText = 'ศูนย์บาทถ้วน'
|
|
58
|
-
|
|
59
|
-
expect(bahttext(null)).toBe(zeroText)
|
|
60
|
-
expect(bahttext(true)).toBe(zeroText)
|
|
61
|
-
expect(bahttext(false)).toBe(zeroText)
|
|
62
|
-
expect(bahttext([])).toBe(zeroText)
|
|
63
|
-
expect(bahttext([1, 2, 3])).toBe(zeroText)
|
|
64
|
-
expect(bahttext({})).toBe(zeroText)
|
|
65
|
-
expect(bahttext('')).toBe(zeroText)
|
|
66
|
-
expect(bahttext()).toBe(zeroText)
|
|
67
|
-
expect(bahttext(undefined)).toBe(zeroText)
|
|
68
|
-
expect(bahttext('this-is-not-number')).toBe(zeroText)
|
|
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('หนึ่งสตางค์')
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
test('less than Number.MIN_SAFE_INTEGER', () => {
|
|
81
|
-
const items = [1, 20, 9451, 5656549]
|
|
82
|
-
for (let i = 0; i < items.length; i++) {
|
|
83
|
-
expect(bahttext(Number.MIN_SAFE_INTEGER - items[i])).toBe(defaultResult)
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
test('more than Number.MAX_SAFE_INTEGER', () => {
|
|
88
|
-
const items = [1, 20, 9451, 5656549]
|
|
89
|
-
for (let i = 0; i < items.length; i++) {
|
|
90
|
-
expect(bahttext(Number.MAX_SAFE_INTEGER + items[i])).toBe(defaultResult)
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
test('numbers are imported from Google Sheet', () => {
|
|
95
|
-
for (let i = 0; i < testCases.length; i++) {
|
|
96
|
-
const customMessage = JSON.stringify(testCases[i])
|
|
97
|
-
const number = Number(testCases[i].number)
|
|
98
|
-
expect(bahttext(number), customMessage).toBe(testCases[i].text)
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
})
|
package/stryker.conf.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|