bahttext 2.2.0 → 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.md CHANGED
@@ -93,4 +93,3 @@ bahttext(-0.20) // ลบยี่สิบสตางค์
93
93
  - [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en)
94
94
  - [Microsoft Office's BAHTTEXT function](https://support.office.com/en-us/article/BAHTTEXT-function-5ba4d0b4-abd3-4325-8d22-7a92d59aab9c)
95
95
  - แรงบัลดาลใจจาก [earthchie/BAHTTEXT.js](https://github.com/earthchie/BAHTTEXT.js)
96
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bahttext",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Change number to Thai pronunciation string",
5
5
  "main": "src/index.js",
6
6
  "typings": "src/index.d.ts",
package/src/index.test.js DELETED
@@ -1,119 +0,0 @@
1
- const {
2
- bahttext,
3
- bahtxtGrammarFix: grammarFix,
4
- bahtxtCombine: combine
5
- } = require('./index')
6
- const defaultResult = 'ศูนย์บาทถ้วน'
7
- const groupedTestCasesKey = 'categoryCase'
8
- const googleSheetTestCases = require('../misc/testcases.json').map(item => {
9
- item[groupedTestCasesKey] = `${item.category}-${item.case}`
10
- return item
11
- })
12
- jest.autoMockOff()
13
-
14
- // TODO: move to somewhere else
15
- // TODO: write test
16
- function groupBy (arr, key) {
17
- return arr.reduce((acc, curr) => {
18
- acc[curr[key]] = (acc[curr[key]] || []).concat(curr)
19
- return acc
20
- }, {})
21
- }
22
-
23
- const groupedTestCases = groupBy(googleSheetTestCases, groupedTestCasesKey)
24
-
25
- // TODO: to be implemented
26
- describe('num2Word', () => {
27
- test('test', () => {
28
- expect(true).toBeTruthy()
29
- })
30
- })
31
-
32
- describe('grammarFix', () => {
33
- test('replace "หนึ่งสิบ" with "สิบ"', () => {
34
- expect(grammarFix('หนึ่งสิบหก')).toBe('สิบหก')
35
- expect(grammarFix('หนึ่งสิบสี่')).toBe('สิบสี่')
36
- expect(grammarFix('ห้าร้อยหนึ่งสิบสาม')).toBe('ห้าร้อยสิบสาม')
37
- expect(grammarFix('สี่หมื่นหนึ่งสิบสาม')).toBe('สี่หมื่นสิบสาม')
38
- })
39
-
40
- test('replace "สองสิบ" with "ยี่สิบ"', () => {
41
- expect(grammarFix('ห้าร้อยสองสิบหนึ่ง')).toBe('ห้าร้อยยี่สิบเอ็ด')
42
- expect(grammarFix('สองสิบสี่')).toBe('ยี่สิบสี่')
43
- expect(grammarFix('เก้าแสนหกหมื่นสามพันสามร้อยสองสิบสี่')).toBe('เก้าแสนหกหมื่นสามพันสามร้อยยี่สิบสี่')
44
- expect(grammarFix('เจ็ดหมื่นห้าพันสี่ร้อยสองสิบหนึ่ง')).toBe('เจ็ดหมื่นห้าพันสี่ร้อยยี่สิบเอ็ด')
45
- })
46
-
47
- test('replace "สิบหนึ่ง" with "สิบเอ็ด"', () => {
48
- expect(grammarFix('หนึ่งสิบหนึ่ง')).toBe('สิบเอ็ด')
49
- })
50
- })
51
-
52
- describe('combine', () => {
53
- test('both baht and satang are empty', () => {
54
- expect(combine('', '')).toBe('ศูนย์บาทถ้วน')
55
- })
56
-
57
- test('both baht and satang are not empty', () => {
58
- expect(combine('หนึ่งร้อยยี่สิบสาม', 'ห้าสิบหก')).toBe('หนึ่งร้อยยี่สิบสามบาทห้าสิบหกสตางค์')
59
- })
60
-
61
- test('has only baht', () => {
62
- expect(combine('แปดแสนเจ็ดหมื่นสี่พันห้าร้อยหกสิบสาม', '')).toBe('แปดแสนเจ็ดหมื่นสี่พันห้าร้อยหกสิบสามบาทถ้วน')
63
- })
64
-
65
- test('has only satang', () => {
66
- expect(combine('', 'ลบสามสิบหก')).toBe('ลบสามสิบหกสตางค์')
67
- })
68
- })
69
-
70
- describe('bahttext', () => {
71
- test('invalid number', () => {
72
- const zeroText = 'ศูนย์บาทถ้วน'
73
-
74
- expect(bahttext(null)).toBe(zeroText)
75
- expect(bahttext(true)).toBe(zeroText)
76
- expect(bahttext(false)).toBe(zeroText)
77
- expect(bahttext([])).toBe(zeroText)
78
- expect(bahttext([1, 2, 3])).toBe(zeroText)
79
- expect(bahttext({})).toBe(zeroText)
80
- expect(bahttext('')).toBe(zeroText)
81
- expect(bahttext()).toBe(zeroText)
82
- expect(bahttext(undefined)).toBe(zeroText)
83
- expect(bahttext('this-is-not-number')).toBe(zeroText)
84
- expect(bahttext('it-must-be-number-only')).toBe(zeroText)
85
- expect(bahttext('a123')).toBe(zeroText)
86
- })
87
-
88
- test('leading with zero', () => {
89
- expect(bahttext('0.1')).toBe('สิบสตางค์')
90
- expect(bahttext('01.1')).toBe('หนึ่งบาทสิบสตางค์')
91
- expect(bahttext('-01.1')).toBe('ลบหนึ่งบาทสิบสตางค์')
92
- expect(bahttext('000.01')).toBe('หนึ่งสตางค์')
93
- })
94
-
95
- test('less than Number.MIN_SAFE_INTEGER', () => {
96
- const items = [1, 20, 9451, 5656549]
97
- for (let i = 0; i < items.length; i++) {
98
- expect(bahttext(Number.MIN_SAFE_INTEGER - items[i])).toBe(defaultResult)
99
- }
100
- })
101
-
102
- test('more than Number.MAX_SAFE_INTEGER', () => {
103
- const items = [1, 20, 9451, 5656549]
104
- for (let i = 0; i < items.length; i++) {
105
- expect(bahttext(Number.MAX_SAFE_INTEGER + items[i])).toBe(defaultResult)
106
- }
107
- })
108
-
109
- // numbers are imported from Google Sheets
110
- for (const [groupedName, testCases] of Object.entries(groupedTestCases)) {
111
- test(`imported Google Sheets: ${groupedName}`, () => {
112
- for (let i = 0; i < testCases.length; i++) {
113
- const customMessage = JSON.stringify(testCases[i])
114
- const number = Number(testCases[i].number)
115
- expect(bahttext(number), customMessage).toBe(testCases[i].text)
116
- }
117
- })
118
- }
119
- })