bahttext 2.1.1 → 2.1.3
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 +8 -0
- package/README.md +8 -0
- package/benchmark.js +29 -0
- package/package.json +10 -2
- package/src/index.js +19 -29
- package/src/index.test.js +8 -0
- 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
|
|
|
@@ -89,6 +90,13 @@ csvtojson ./misc/testcases.csv | jq > ./misc/testcases.json
|
|
|
89
90
|
# to update dependency version
|
|
90
91
|
npm update --save
|
|
91
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
|
|
92
100
|
```
|
|
93
101
|
|
|
94
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
|
|
|
@@ -88,6 +89,13 @@ csvtojson ./misc/testcases.csv | jq > ./misc/testcases.json
|
|
|
88
89
|
# to update dependency version
|
|
89
90
|
npm update --save
|
|
90
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
|
|
91
99
|
```
|
|
92
100
|
|
|
93
101
|
## อ้างอิง
|
package/benchmark.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bahttext",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Change number to Thai pronunciation string",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"typings": "src/index.js",
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
"semantic-release": "semantic-release",
|
|
12
12
|
"standard": "standard",
|
|
13
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
18
|
"repository": {
|
|
@@ -32,10 +34,16 @@
|
|
|
32
34
|
},
|
|
33
35
|
"homepage": "https://github.com/jojoee/bahttext#readme",
|
|
34
36
|
"devDependencies": {
|
|
37
|
+
"@stryker-mutator/core": "^6.3.1",
|
|
38
|
+
"@stryker-mutator/jest-runner": "^6.3.1",
|
|
39
|
+
"@to-da-moon/thai-baht-lib": "^0.0.12",
|
|
40
|
+
"baht": "^0.7.1",
|
|
35
41
|
"jest": "^26.6.3",
|
|
36
42
|
"jest-expect-message": "^1.0.2",
|
|
37
43
|
"semantic-release": "^19.0.5",
|
|
38
|
-
"standard": "^15.0.1"
|
|
44
|
+
"standard": "^15.0.1",
|
|
45
|
+
"thai-baht-text": "^1.0.8",
|
|
46
|
+
"thai-baht-text-ts": "^1.1.0"
|
|
39
47
|
},
|
|
40
48
|
"jest": {
|
|
41
49
|
"setupFilesAfterEnv": [
|
package/src/index.js
CHANGED
|
@@ -37,13 +37,9 @@ function bahtxtNum2Word (nums) {
|
|
|
37
37
|
* @returns {string}
|
|
38
38
|
*/
|
|
39
39
|
function bahtxtGrammarFix (str) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
result = result.replace(/สองสิบ/g, 'ยี่สิบ')
|
|
44
|
-
result = result.replace(/สิบหนึ่ง/g, 'สิบเอ็ด')
|
|
45
|
-
|
|
46
|
-
return result
|
|
40
|
+
return str.replace(/หนึ่งสิบ/g, 'สิบ')
|
|
41
|
+
.replace(/สองสิบ/g, 'ยี่สิบ')
|
|
42
|
+
.replace(/สิบหนึ่ง/g, 'สิบเอ็ด')
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
/**
|
|
@@ -55,19 +51,15 @@ function bahtxtGrammarFix (str) {
|
|
|
55
51
|
* @returns {string}
|
|
56
52
|
*/
|
|
57
53
|
function bahtxtCombine (baht, satang) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (baht
|
|
61
|
-
|
|
62
|
-
} else if (baht
|
|
63
|
-
|
|
64
|
-
} else if (baht === '' && satang !== '') {
|
|
65
|
-
result = satang + 'สตางค์'
|
|
54
|
+
if (!baht && !satang) {
|
|
55
|
+
return bahtxtConst.defaultResult
|
|
56
|
+
} else if (baht && !satang) {
|
|
57
|
+
return baht + 'บาท' + 'ถ้วน'
|
|
58
|
+
} else if (!baht && satang) {
|
|
59
|
+
return satang + 'สตางค์'
|
|
66
60
|
} else {
|
|
67
|
-
|
|
61
|
+
return baht + 'บาท' + satang + 'สตางค์'
|
|
68
62
|
}
|
|
69
|
-
|
|
70
|
-
return result
|
|
71
63
|
}
|
|
72
64
|
|
|
73
65
|
/**
|
|
@@ -77,16 +69,14 @@ function bahtxtCombine (baht, satang) {
|
|
|
77
69
|
* @returns {string}
|
|
78
70
|
*/
|
|
79
71
|
function bahttext (num) {
|
|
80
|
-
// no null
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// no more than Number.MAX_SAFE_INTEGER
|
|
89
|
-
if (num > Number.MAX_SAFE_INTEGER) return bahtxtConst.defaultResult
|
|
72
|
+
if (!num || // no null
|
|
73
|
+
typeof num === 'boolean' || // no boolean
|
|
74
|
+
isNaN(Number(num)) || // must be number only
|
|
75
|
+
num < Number.MIN_SAFE_INTEGER || // not less than Number.MIN_SAFE_INTEGER
|
|
76
|
+
num > Number.MAX_SAFE_INTEGER // no more than Number.MAX_SAFE_INTEGER
|
|
77
|
+
) {
|
|
78
|
+
return bahtxtConst.defaultResult
|
|
79
|
+
}
|
|
90
80
|
|
|
91
81
|
// set
|
|
92
82
|
const positiveNum = Math.abs(num)
|
|
@@ -94,7 +84,7 @@ function bahttext (num) {
|
|
|
94
84
|
// split baht and satang e.g. 432.214567 >> 432, 21
|
|
95
85
|
const bahtStr = Math.floor(positiveNum).toString()
|
|
96
86
|
/** @type {string} */
|
|
97
|
-
const satangStr = (positiveNum % 1 * 100).toFixed(
|
|
87
|
+
const satangStr = (positiveNum % 1 * 100).toFixed(0)
|
|
98
88
|
|
|
99
89
|
/** @type {number[]} */
|
|
100
90
|
const bahtArr = Array.from(bahtStr).map(Number)
|
package/src/index.test.js
CHANGED
|
@@ -67,6 +67,14 @@ describe('bahttext', () => {
|
|
|
67
67
|
expect(bahttext(undefined)).toBe(zeroText)
|
|
68
68
|
expect(bahttext('this-is-not-number')).toBe(zeroText)
|
|
69
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('หนึ่งสตางค์')
|
|
70
78
|
})
|
|
71
79
|
|
|
72
80
|
test('less than Number.MIN_SAFE_INTEGER', () => {
|
|
@@ -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
|
+
}
|