Comparing version 2.1.0 to 2.1.1
{ | ||
"name": "bahttext", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Change number to Thai pronunciation string", | ||
@@ -10,16 +10,8 @@ "main": "src/index.js", | ||
"jest.watch": "jest --watch", | ||
"commit": "git-cz", | ||
"coverage.check": "jest --coverage", | ||
"semantic-release": "semantic-release", | ||
"standard": "standard", | ||
"standard.fix": "standard --fix", | ||
"validate": "npm run standard && npm run coverage.check" | ||
}, | ||
"config": { | ||
"ghooks": { | ||
"pre-commit": "npm run validate" | ||
}, | ||
"commitizen": { | ||
"path": "node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"repository": { | ||
@@ -43,11 +35,7 @@ "type": "git", | ||
"homepage": "https://github.com/jojoee/bahttext#readme", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"commitizen": "4.2.2", | ||
"cz-conventional-changelog": "3.3.0", | ||
"ghooks": "2.0.4", | ||
"jest": "^26.6.1", | ||
"jest": "^26.6.3", | ||
"jest-expect-message": "^1.0.2", | ||
"semantic-release": "^17.2.1", | ||
"standard": "^15.0.0" | ||
"semantic-release": "^19.0.5", | ||
"standard": "^15.0.1" | ||
}, | ||
@@ -54,0 +42,0 @@ "jest": { |
@@ -39,4 +39,28 @@ # bahttext | ||
```javascript | ||
// หกหมื่นสามพันหนึ่งร้อยสี่สิบเจ็ดบาทแปดสิบเก้าสตางค์ | ||
bahttext(63147.89) | ||
bahttext(8.00) // แปดบาทถ้วน | ||
bahttext(5678.00) // ห้าพันหกร้อยเจ็ดสิบแปดบาทถ้วน | ||
bahttext(63147.89) // หกหมื่นสามพันหนึ่งร้อยสี่สิบเจ็ดบาทแปดสิบเก้าสตางค์ | ||
bahttext(51000001.00) // ห้าสิบเอ็ดล้านหนึ่งบาทถ้วน | ||
bahttext(317.10) // สามร้อยสิบเจ็ดบาทสิบสตางค์ | ||
bahttext(422.26) // สี่ร้อยยี่สิบสองบาทยี่สิบหกสตางค์ | ||
bahttext(11.11) // สิบเอ็ดบาทสิบเอ็ดสตางค์ | ||
bahttext(191415.11) // หนึ่งแสนเก้าหมื่นหนึ่งพันสี่ร้อยสิบห้าบาทสิบเอ็ดสตางค์ | ||
bahttext(1.01) // หนึ่งบาทหนึ่งสตางค์ | ||
bahttext(5678.46) // ห้าพันหกร้อยเจ็ดสิบแปดบาทสี่สิบหกสตางค์ | ||
bahttext(0.67) // หกสิบเจ็ดสตางค์ | ||
bahttext(-3.00) // ลบสามบาทถ้วน | ||
bahttext(-232.00) // ลบสองร้อยสามสิบสองบาทถ้วน | ||
bahttext(-44444.00) // ลบสี่หมื่นสี่พันสี่ร้อยสี่สิบสี่บาทถ้วน | ||
bahttext(-5678934.00) // ลบห้าล้านหกแสนเจ็ดหมื่นแปดพันเก้าร้อยสามสิบสี่บาทถ้วน | ||
bahttext(-201.00) // ลบสองร้อยหนึ่งบาทถ้วน | ||
bahttext(-317.10) // ลบสามร้อยสิบเจ็ดบาทสิบสตางค์ | ||
bahttext(-5723.00) // ลบห้าพันเจ็ดร้อยยี่สิบสามบาทถ้วน | ||
bahttext(-11.00) // ลบสิบเอ็ดบาทถ้วน | ||
bahttext(-45621.21) // ลบสี่หมื่นห้าพันหกร้อยยี่สิบเอ็ดบาทยี่สิบเอ็ดสตางค์ | ||
bahttext(-191415.11) // ลบหนึ่งแสนเก้าหมื่นหนึ่งพันสี่ร้อยสิบห้าบาทสิบเอ็ดสตางค์ | ||
bahttext(-282622.22) // ลบสองแสนแปดหมื่นสองพันหกร้อยยี่สิบสองบาทยี่สิบสองสตางค์ | ||
bahttext(-1.04) // ลบหนึ่งบาทสี่สตางค์ | ||
bahttext(-574.45) // ลบห้าร้อยเจ็ดสิบสี่บาทสี่สิบห้าสตางค์ | ||
bahttext(-345.23) // ลบสามร้อยสี่สิบห้าบาทยี่สิบสามสตางค์ | ||
bahttext(-0.20) // ลบยี่สิบสตางค์ | ||
``` | ||
@@ -46,6 +70,5 @@ | ||
- [x] Compatible with all browsers | ||
- [x] Node.js version support: 6-12 | ||
- [x] Node.js version support: 6+ | ||
- [x] 0 Dependencies | ||
- [x] Unit test | ||
- [ ] Browser compatibility test | ||
- [x] Remove duplication between test code and test-case-csv file | ||
@@ -56,2 +79,5 @@ - [x] [Demo page](https://jojoee.github.io/bahttext/) | ||
## Other languages | ||
- Python: [jojoee/pybaht](https://github.com/jojoee/pybaht) | ||
## CMD | ||
@@ -62,5 +88,9 @@ | ||
brew install jq | ||
npm install -g | ||
npm install -g csvtojson | ||
curl -L -o ./misc/testcases.csv https://docs.google.com/spreadsheets/d/e/2PACX-1vTb8PIKzgo07rn9UpcjqE0YrdMAmf4fyDbL2plUieLCyrn_5O3vDvece7UfkaArWQLUSsaw92jVpY_z/pub?gid=0&single=true&output=csv | ||
csvtojson ./misc/testcases.csv | jq > ./misc/testcases.json | ||
# to update dependency version | ||
npm update --save | ||
npm audit fix --force | ||
``` | ||
@@ -67,0 +97,0 @@ |
@@ -38,4 +38,28 @@ # bahttext | ||
```javascript | ||
// หกหมื่นสามพันหนึ่งร้อยสี่สิบเจ็ดบาทแปดสิบเก้าสตางค์ | ||
bahttext(63147.89) | ||
bahttext(8.00) // แปดบาทถ้วน | ||
bahttext(5678.00) // ห้าพันหกร้อยเจ็ดสิบแปดบาทถ้วน | ||
bahttext(63147.89) // หกหมื่นสามพันหนึ่งร้อยสี่สิบเจ็ดบาทแปดสิบเก้าสตางค์ | ||
bahttext(51000001.00) // ห้าสิบเอ็ดล้านหนึ่งบาทถ้วน | ||
bahttext(317.10) // สามร้อยสิบเจ็ดบาทสิบสตางค์ | ||
bahttext(422.26) // สี่ร้อยยี่สิบสองบาทยี่สิบหกสตางค์ | ||
bahttext(11.11) // สิบเอ็ดบาทสิบเอ็ดสตางค์ | ||
bahttext(191415.11) // หนึ่งแสนเก้าหมื่นหนึ่งพันสี่ร้อยสิบห้าบาทสิบเอ็ดสตางค์ | ||
bahttext(1.01) // หนึ่งบาทหนึ่งสตางค์ | ||
bahttext(5678.46) // ห้าพันหกร้อยเจ็ดสิบแปดบาทสี่สิบหกสตางค์ | ||
bahttext(0.67) // หกสิบเจ็ดสตางค์ | ||
bahttext(-3.00) // ลบสามบาทถ้วน | ||
bahttext(-232.00) // ลบสองร้อยสามสิบสองบาทถ้วน | ||
bahttext(-44444.00) // ลบสี่หมื่นสี่พันสี่ร้อยสี่สิบสี่บาทถ้วน | ||
bahttext(-5678934.00) // ลบห้าล้านหกแสนเจ็ดหมื่นแปดพันเก้าร้อยสามสิบสี่บาทถ้วน | ||
bahttext(-201.00) // ลบสองร้อยหนึ่งบาทถ้วน | ||
bahttext(-317.10) // ลบสามร้อยสิบเจ็ดบาทสิบสตางค์ | ||
bahttext(-5723.00) // ลบห้าพันเจ็ดร้อยยี่สิบสามบาทถ้วน | ||
bahttext(-11.00) // ลบสิบเอ็ดบาทถ้วน | ||
bahttext(-45621.21) // ลบสี่หมื่นห้าพันหกร้อยยี่สิบเอ็ดบาทยี่สิบเอ็ดสตางค์ | ||
bahttext(-191415.11) // ลบหนึ่งแสนเก้าหมื่นหนึ่งพันสี่ร้อยสิบห้าบาทสิบเอ็ดสตางค์ | ||
bahttext(-282622.22) // ลบสองแสนแปดหมื่นสองพันหกร้อยยี่สิบสองบาทยี่สิบสองสตางค์ | ||
bahttext(-1.04) // ลบหนึ่งบาทสี่สตางค์ | ||
bahttext(-574.45) // ลบห้าร้อยเจ็ดสิบสี่บาทสี่สิบห้าสตางค์ | ||
bahttext(-345.23) // ลบสามร้อยสี่สิบห้าบาทยี่สิบสามสตางค์ | ||
bahttext(-0.20) // ลบยี่สิบสตางค์ | ||
``` | ||
@@ -45,6 +69,5 @@ | ||
- [x] สามารถใช้งานได้ทุก เบราว์เซอร์ | ||
- [x] สามารถใช้งานได้ตั้งแต่ Node.js version 6-12 | ||
- [x] สามารถใช้งานได้ตั้งแต่ Node.js version 6+ | ||
- [x] 0 Dependencies | ||
- [x] ทำการทดสอบแบบ unit test | ||
- [ ] ทดสอบบนเบราว์เซอร์ ในแต่ละ เวอร์ชั่น | ||
- [x] ลดการซ้ำซ้อนของการเขียน ระหว่าง code และ ไฟล์ csv ในการทำการทดสอบ | ||
@@ -55,2 +78,5 @@ - [x] [หน้าตัวอย่างการใช้งาน](https://jojoee.github.io/bahttext/) | ||
## ภาษาอื่นๆ | ||
- Python: [jojoee/pybaht](https://github.com/jojoee/pybaht) | ||
## CMD | ||
@@ -61,5 +87,9 @@ | ||
brew install jq | ||
npm install -g | ||
npm install -g csvtojson | ||
curl -L -o ./misc/testcases.csv https://docs.google.com/spreadsheets/d/e/2PACX-1vTb8PIKzgo07rn9UpcjqE0YrdMAmf4fyDbL2plUieLCyrn_5O3vDvece7UfkaArWQLUSsaw92jVpY_z/pub?gid=0&single=true&output=csv | ||
csvtojson ./misc/testcases.csv | jq > ./misc/testcases.json | ||
# to update dependency version | ||
npm update --save | ||
npm audit fix --force | ||
``` | ||
@@ -66,0 +96,0 @@ |
@@ -1,4 +0,6 @@ | ||
const defaultResult = 'ศูนย์บาทถ้วน' | ||
const singleUnitStrs = ['', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า'] | ||
const placeNameStrs = ['', 'สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน', 'ล้าน'] | ||
const bahtxtConst = { | ||
defaultResult: 'ศูนย์บาทถ้วน', | ||
singleUnitStrs: ['', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า'], | ||
placeNameStrs: ['', 'สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน', 'ล้าน'] | ||
} | ||
@@ -9,3 +11,3 @@ /** | ||
*/ | ||
function num2Word (nums) { | ||
function bahtxtNum2Word (nums) { | ||
let result = '' | ||
@@ -20,3 +22,3 @@ const len = nums.length | ||
const remainingNumbs = nums.slice(overflowIndex) | ||
return num2Word(overflowNums) + 'ล้าน' + num2Word(remainingNumbs) | ||
return bahtxtNum2Word(overflowNums) + 'ล้าน' + bahtxtNum2Word(remainingNumbs) | ||
} else { | ||
@@ -26,3 +28,3 @@ for (let i = 0; i < len; i++) { | ||
if (digit > 0) { | ||
result += singleUnitStrs[digit] + placeNameStrs[len - i - 1] | ||
result += bahtxtConst.singleUnitStrs[digit] + bahtxtConst.placeNameStrs[len - i - 1] | ||
} | ||
@@ -40,3 +42,3 @@ } | ||
*/ | ||
function grammarFix (str) { | ||
function bahtxtGrammarFix (str) { | ||
let result = str | ||
@@ -52,3 +54,3 @@ | ||
/** | ||
* Combine baht and satang | ||
* bahtxtCombine baht and satang | ||
* and also adding unit | ||
@@ -60,7 +62,7 @@ * | ||
*/ | ||
function combine (baht, satang) { | ||
function bahtxtCombine (baht, satang) { | ||
let result = '' | ||
if (baht === '' && satang === '') { | ||
result = defaultResult | ||
result = bahtxtConst.defaultResult | ||
} else if (baht !== '' && satang === '') { | ||
@@ -85,11 +87,11 @@ result = baht + 'บาท' + 'ถ้วน' | ||
// no null | ||
if (!num) return defaultResult | ||
if (!num) return bahtxtConst.defaultResult | ||
// no boolean | ||
if (typeof num === 'boolean') return defaultResult | ||
if (typeof num === 'boolean') return bahtxtConst.defaultResult | ||
// must be number only | ||
if (isNaN(Number(num))) return defaultResult | ||
if (isNaN(Number(num))) return bahtxtConst.defaultResult | ||
// not less than Number.MIN_SAFE_INTEGER | ||
if (num < Number.MIN_SAFE_INTEGER) return defaultResult | ||
if (num < Number.MIN_SAFE_INTEGER) return bahtxtConst.defaultResult | ||
// no more than Number.MAX_SAFE_INTEGER | ||
if (num > Number.MAX_SAFE_INTEGER) return defaultResult | ||
if (num > Number.MAX_SAFE_INTEGER) return bahtxtConst.defaultResult | ||
@@ -110,11 +112,11 @@ // set | ||
// proceed | ||
let baht = num2Word(bahtArr) | ||
let satang = num2Word(satangArr) | ||
let baht = bahtxtNum2Word(bahtArr) | ||
let satang = bahtxtNum2Word(satangArr) | ||
// grammar | ||
baht = grammarFix(baht) | ||
satang = grammarFix(satang) | ||
baht = bahtxtGrammarFix(baht) | ||
satang = bahtxtGrammarFix(satang) | ||
// combine | ||
const result = combine(baht, satang) | ||
const result = bahtxtCombine(baht, satang) | ||
@@ -127,3 +129,8 @@ return num >= 0 ? result : 'ลบ' + result | ||
module.exports = { | ||
bahttext | ||
bahttext, | ||
// export for testing only | ||
bahtxtNum2Word, | ||
bahtxtGrammarFix, | ||
bahtxtCombine | ||
} | ||
@@ -130,0 +137,0 @@ exports.default = { |
@@ -1,2 +0,6 @@ | ||
const { bahttext } = require('./index') | ||
const { | ||
bahttext, | ||
bahtxtGrammarFix: grammarFix, | ||
bahtxtCombine: combine | ||
} = require('./index') | ||
const defaultResult = 'ศูนย์บาทถ้วน' | ||
@@ -6,3 +10,48 @@ const testCases = require('../misc/testcases.json') | ||
describe('misc', () => { | ||
// TODO: to be implemented | ||
describe('num2Word', () => { | ||
test('test', () => { | ||
expect(true).toBeTruthy() | ||
}) | ||
}) | ||
describe('grammarFix', () => { | ||
test('replace "หนึ่งสิบ" with "สิบ"', () => { | ||
expect(grammarFix('หนึ่งสิบหก')).toBe('สิบหก') | ||
expect(grammarFix('หนึ่งสิบสี่')).toBe('สิบสี่') | ||
expect(grammarFix('ห้าร้อยหนึ่งสิบสาม')).toBe('ห้าร้อยสิบสาม') | ||
expect(grammarFix('สี่หมื่นหนึ่งสิบสาม')).toBe('สี่หมื่นสิบสาม') | ||
}) | ||
test('replace "สองสิบ" with "ยี่สิบ"', () => { | ||
expect(grammarFix('ห้าร้อยสองสิบหนึ่ง')).toBe('ห้าร้อยยี่สิบเอ็ด') | ||
expect(grammarFix('สองสิบสี่')).toBe('ยี่สิบสี่') | ||
expect(grammarFix('เก้าแสนหกหมื่นสามพันสามร้อยสองสิบสี่')).toBe('เก้าแสนหกหมื่นสามพันสามร้อยยี่สิบสี่') | ||
expect(grammarFix('เจ็ดหมื่นห้าพันสี่ร้อยสองสิบหนึ่ง')).toBe('เจ็ดหมื่นห้าพันสี่ร้อยยี่สิบเอ็ด') | ||
}) | ||
test('replace "สิบหนึ่ง" with "สิบเอ็ด"', () => { | ||
expect(grammarFix('หนึ่งสิบหนึ่ง')).toBe('สิบเอ็ด') | ||
}) | ||
}) | ||
describe('combine', () => { | ||
test('both baht and satang are empty', () => { | ||
expect(combine('', '')).toBe('ศูนย์บาทถ้วน') | ||
}) | ||
test('both baht and satang are not empty', () => { | ||
expect(combine('หนึ่งร้อยยี่สิบสาม', 'ห้าสิบหก')).toBe('หนึ่งร้อยยี่สิบสามบาทห้าสิบหกสตางค์') | ||
}) | ||
test('has only baht', () => { | ||
expect(combine('แปดแสนเจ็ดหมื่นสี่พันห้าร้อยหกสิบสาม', '')).toBe('แปดแสนเจ็ดหมื่นสี่พันห้าร้อยหกสิบสามบาทถ้วน') | ||
}) | ||
test('has only satang', () => { | ||
expect(combine('', 'ลบสามสิบหก')).toBe('ลบสามสิบหกสตางค์') | ||
}) | ||
}) | ||
describe('bahttext', () => { | ||
test('invalid number', () => { | ||
@@ -37,6 +86,4 @@ const zeroText = 'ศูนย์บาทถ้วน' | ||
}) | ||
}) | ||
describe('number', () => { | ||
test('imported from Google Sheet', () => { | ||
test('numbers are imported from Google Sheet', () => { | ||
for (let i = 0; i < testCases.length; i++) { | ||
@@ -43,0 +90,0 @@ const customMessage = JSON.stringify(testCases[i]) |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25804
4
214
97
0