Comparing version 2.1.3 to 2.2.0
{ | ||
"name": "bahttext", | ||
"version": "2.1.3", | ||
"version": "2.2.0", | ||
"description": "Change number to Thai pronunciation string", | ||
"main": "src/index.js", | ||
"typings": "src/index.js", | ||
"typings": "src/index.d.ts", | ||
"scripts": { | ||
@@ -11,2 +11,3 @@ "jest": "jest", | ||
"coverage.check": "jest --coverage", | ||
"build": "tsc", | ||
"semantic-release": "semantic-release", | ||
@@ -17,3 +18,3 @@ "standard": "standard", | ||
"test.watch": "jest --watch", | ||
"validate": "npm run standard && npm run coverage.check" | ||
"validate": "npm run standard && npm run coverage.check && npm run build" | ||
}, | ||
@@ -48,3 +49,4 @@ "repository": { | ||
"thai-baht-text": "^1.0.8", | ||
"thai-baht-text-ts": "^1.1.0" | ||
"thai-baht-text-ts": "^1.1.0", | ||
"typescript": "*" | ||
}, | ||
@@ -51,0 +53,0 @@ "jest": { |
# bahttext | ||
[![Codecov](https://img.shields.io/codecov/c/github/jojoee/bahttext.svg)](https://codecov.io/github/jojoee/bahttext) | ||
[![Version - npm](https://img.shields.io/npm/v/bahttext.svg)](https://www.npmjs.com/package/bahttext) | ||
[![License - npm](https://img.shields.io/npm/l/bahttext.svg)](http://opensource.org/licenses/MIT) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release) [![Greenkeeper badge](https://badges.greenkeeper.io/jojoee/bahttext.svg)](https://greenkeeper.io/) | ||
![continuous integration](https://github.com/jojoee/bahttext/workflows/continuous%20integration/badge.svg?branch=master) | ||
![release](https://github.com/jojoee/bahttext/workflows/release/badge.svg?branch=master) | ||
![runnable](https://github.com/jojoee/bahttext/workflows/runnable/badge.svg?branch=master) | ||
![runnable old node](https://github.com/jojoee/bahttext/workflows/runnable%20old%20node/badge.svg?branch=master) | ||
[![Codecov](https://img.shields.io/codecov/c/github/jojoee/bahttext.svg)](https://codecov.io/github/jojoee/bahttext) | ||
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fjojoee%2Fbahttext%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/jojoee/bahttext/master) | ||
Language: [ไทย](https://github.com/jojoee/bahttext/blob/master/README.md), [English](https://github.com/jojoee/bahttext/blob/master/README-en.md) | ||
[![continuous integration](https://github.com/jojoee/bahttext/workflows/continuous%20integration/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/continuous-integration.yml) | ||
[![release](https://github.com/jojoee/bahttext/workflows/release/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/release.yml) | ||
[![runnable](https://github.com/jojoee/bahttext/workflows/runnable/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/runnable.yml) | ||
[![runnable old node](https://github.com/jojoee/bahttext/workflows/runnable%20old%20node/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/runnable-old-node.yml) | ||
Change number to Thai pronunciation string, test against [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en), [Demo page](https://jojoee.github.io/bahttext/) | ||
Only `TH` and `EN` languages are maintained, the rest is auto-generated by ChatGPT API. Language: | ||
[ไทย](https://github.com/jojoee/bahttext/blob/master/README.md), | ||
[English](https://github.com/jojoee/bahttext/blob/master/README-en.md), | ||
[中国大陆](https://github.com/jojoee/bahttext/blob/master/doc/README-cn.md), | ||
[대한민국](https://github.com/jojoee/bahttext/blob/master/doc/README-kr.md), | ||
[Việt Nam](https://github.com/jojoee/bahttext/blob/master/doc/README-vn.md), | ||
[日本](https://github.com/jojoee/bahttext/blob/master/doc/README-jp.md), | ||
[Россия](https://github.com/jojoee/bahttext/blob/master/doc/README-ru.md), | ||
[Español](https://github.com/jojoee/bahttext/blob/master/doc/README-la.md), | ||
[Français](https://github.com/jojoee/bahttext/blob/master/doc/README-fr.md) | ||
Change number to Thai pronunciation string, test | ||
against [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en), [Demo page](https://jojoee.github.io/bahttext/) | ||
## Installation | ||
@@ -69,38 +79,17 @@ | ||
## Note | ||
- [x] Compatible with all browsers | ||
- [x] Node.js version support: 6+ | ||
- [x] 0 Dependencies | ||
- [x] Unit test | ||
- [x] Remove duplication between test code and test-case-csv file | ||
- [x] [Demo page](https://jojoee.github.io/bahttext/) | ||
- [x] Support negative number | ||
- [x] Fix semantic-release | ||
- Compatible with all browsers | ||
- Node.js version support: 6+ | ||
- 0 Dependencies | ||
- Demo page | ||
- Support negative number | ||
## Other languages | ||
- Python: [jojoee/pybaht](https://github.com/jojoee/pybaht) | ||
## CMD | ||
## Reference | ||
``` | ||
brew install curl | ||
brew install jq | ||
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 | ||
# mutation test | ||
npm install -g stryker-cli | ||
stryker init | ||
export STRYKER_DASHBOARD_API_KEY=<the_project_api_token> | ||
echo $STRYKER_DASHBOARD_API_KEY | ||
npx stryker run | ||
``` | ||
## Reference | ||
- [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en) | ||
- [Microsoft Office's BAHTTEXT function](https://support.office.com/en-us/article/BAHTTEXT-function-5ba4d0b4-abd3-4325-8d22-7a92d59aab9c) | ||
- Inspired by [earthchie/BAHTTEXT.js](https://github.com/earthchie/BAHTTEXT.js) |
# bahttext | ||
[![Codecov](https://img.shields.io/codecov/c/github/jojoee/bahttext.svg)](https://codecov.io/github/jojoee/bahttext) | ||
[![Version - npm](https://img.shields.io/npm/v/bahttext.svg)](https://www.npmjs.com/package/bahttext) | ||
[![License - npm](https://img.shields.io/npm/l/bahttext.svg)](http://opensource.org/licenses/MIT) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release) [![Greenkeeper badge](https://badges.greenkeeper.io/jojoee/bahttext.svg)](https://greenkeeper.io/) | ||
![continuous integration](https://github.com/jojoee/bahttext/workflows/continuous%20integration/badge.svg?branch=master) | ||
![release](https://github.com/jojoee/bahttext/workflows/release/badge.svg?branch=master) | ||
![runnable](https://github.com/jojoee/bahttext/workflows/runnable/badge.svg?branch=master) | ||
![runnable old node](https://github.com/jojoee/bahttext/workflows/runnable%20old%20node/badge.svg?branch=master) | ||
[![Codecov](https://img.shields.io/codecov/c/github/jojoee/bahttext.svg)](https://codecov.io/github/jojoee/bahttext) | ||
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fjojoee%2Fbahttext%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/jojoee/bahttext/master) | ||
ภาษา: [ไทย](https://github.com/jojoee/bahttext/blob/master/README.md), [English](https://github.com/jojoee/bahttext/blob/master/README-en.md) | ||
[![continuous integration](https://github.com/jojoee/bahttext/workflows/continuous%20integration/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/continuous-integration.yml) | ||
[![release](https://github.com/jojoee/bahttext/workflows/release/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/release.yml) | ||
[![runnable](https://github.com/jojoee/bahttext/workflows/runnable/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/runnable.yml) | ||
[![runnable old node](https://github.com/jojoee/bahttext/workflows/runnable%20old%20node/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/runnable-old-node.yml) | ||
เปลี่ยนตัวเลข เป็นคำอ่านภาษาไทย, โมดูลตัวนี้ได้ทำการทดสอบกับ [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en), [Demo page](https://jojoee.github.io/bahttext/) เรียบร้อยแล้ว | ||
Only `TH` and `EN` languages are maintained, the rest is auto-generated by ChatGPT API. Language: | ||
[ไทย](https://github.com/jojoee/bahttext/blob/master/README.md), | ||
[English](https://github.com/jojoee/bahttext/blob/master/README-en.md), | ||
[中国大陆](https://github.com/jojoee/bahttext/blob/master/doc/README-cn.md), | ||
[대한민국](https://github.com/jojoee/bahttext/blob/master/doc/README-kr.md), | ||
[Việt Nam](https://github.com/jojoee/bahttext/blob/master/doc/README-vn.md), | ||
[日本](https://github.com/jojoee/bahttext/blob/master/doc/README-jp.md), | ||
[Россия](https://github.com/jojoee/bahttext/blob/master/doc/README-ru.md), | ||
[Español](https://github.com/jojoee/bahttext/blob/master/doc/README-la.md), | ||
[Français](https://github.com/jojoee/bahttext/blob/master/doc/README-fr.md) | ||
เปลี่ยนตัวเลข เป็นคำอ่านภาษาไทย, | ||
โมดูลตัวนี้ได้ทำการทดสอบกับ [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en), [Demo page](https://jojoee.github.io/bahttext/) | ||
เรียบร้อยแล้ว | ||
## ติดตั้ง | ||
``` | ||
// ติดตั้งด้วย CommonJS | ||
// CommonJS | ||
npm install bahttext | ||
const { bahttext } = require('bahttext') | ||
// ติดตั้งด้วย Bower | ||
// Bower | ||
bower install bahttext | ||
<script src="bower_components/bahttext/src/index.js"></script> | ||
// ติดตั้งด้วย githack | ||
// githack | ||
<script src="https://raw.githack.com/jojoee/bahttext/master/src/index.js"></script> | ||
// ติดตั้งด้วย ES6 | ||
// ES6 | ||
npm install bahttext | ||
@@ -68,38 +80,18 @@ import { bahttext } from "bahttext" | ||
## ฟีเจอร์ | ||
- [x] สามารถใช้งานได้ทุก เบราว์เซอร์ | ||
- [x] สามารถใช้งานได้ตั้งแต่ Node.js version 6+ | ||
- [x] 0 Dependencies | ||
- [x] ทำการทดสอบแบบ unit test | ||
- [x] ลดการซ้ำซ้อนของการเขียน ระหว่าง code และ ไฟล์ csv ในการทำการทดสอบ | ||
- [x] [หน้าตัวอย่างการใช้งาน](https://jojoee.github.io/bahttext/) | ||
- [x] สนับสนุนการใช้งานกับตัวเลขติดลบ | ||
- [x] แก้ไข semantic-release | ||
- สามารถใช้งานได้ทุก เบราว์เซอร์ | ||
- สามารถใช้งานได้ตั้งแต่ Node.js version 6+ | ||
- 0 Dependencies | ||
- หน้าตัวอย่างการใช้งาน | ||
- สนับสนุนการใช้งานกับตัวเลขติดลบ | ||
## ภาษาอื่นๆ | ||
- Python: [jojoee/pybaht](https://github.com/jojoee/pybaht) | ||
## CMD | ||
## อ้างอิง | ||
``` | ||
brew install curl | ||
brew install jq | ||
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 | ||
# mutation test | ||
npm install -g stryker-cli | ||
stryker init | ||
export STRYKER_DASHBOARD_API_KEY=<the_project_api_token> | ||
echo $STRYKER_DASHBOARD_API_KEY | ||
npx stryker run | ||
``` | ||
## อ้างอิง | ||
- [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en) | ||
- [Microsoft Office's BAHTTEXT function](https://support.office.com/en-us/article/BAHTTEXT-function-5ba4d0b4-abd3-4325-8d22-7a92d59aab9c) | ||
- แรงบัลดาลใจจาก [earthchie/BAHTTEXT.js](https://github.com/earthchie/BAHTTEXT.js) | ||
@@ -8,2 +8,3 @@ const bahtxtConst = { | ||
/** | ||
* @private | ||
* @param {number[]} nums | ||
@@ -36,2 +37,3 @@ * @returns {string} | ||
/** | ||
* @private | ||
* @todo improve performance | ||
@@ -51,2 +53,3 @@ * @param {string} str | ||
* | ||
* @private | ||
* @param {string} baht | ||
@@ -71,2 +74,3 @@ * @param {string} satang | ||
* | ||
* @public | ||
* @param {number} num | ||
@@ -73,0 +77,0 @@ * @returns {string} |
@@ -7,5 +7,20 @@ const { | ||
const defaultResult = 'ศูนย์บาทถ้วน' | ||
const testCases = require('../misc/testcases.json') | ||
const groupedTestCasesKey = 'categoryCase' | ||
const googleSheetTestCases = require('../misc/testcases.json').map(item => { | ||
item[groupedTestCasesKey] = `${item.category}-${item.case}` | ||
return item | ||
}) | ||
jest.autoMockOff() | ||
// TODO: move to somewhere else | ||
// TODO: write test | ||
function groupBy (arr, key) { | ||
return arr.reduce((acc, curr) => { | ||
acc[curr[key]] = (acc[curr[key]] || []).concat(curr) | ||
return acc | ||
}, {}) | ||
} | ||
const groupedTestCases = groupBy(googleSheetTestCases, groupedTestCasesKey) | ||
// TODO: to be implemented | ||
@@ -95,9 +110,12 @@ describe('num2Word', () => { | ||
test('numbers are imported from Google Sheet', () => { | ||
for (let i = 0; i < testCases.length; i++) { | ||
const customMessage = JSON.stringify(testCases[i]) | ||
const number = Number(testCases[i].number) | ||
expect(bahttext(number), customMessage).toBe(testCases[i].text) | ||
} | ||
}) | ||
// numbers are imported from Google Sheets | ||
for (const [groupedName, testCases] of Object.entries(groupedTestCases)) { | ||
test(`imported Google Sheets: ${groupedName}`, () => { | ||
for (let i = 0; i < testCases.length; i++) { | ||
const customMessage = JSON.stringify(testCases[i]) | ||
const number = Number(testCases[i].number) | ||
expect(bahttext(number), customMessage).toBe(testCases[i].text) | ||
} | ||
}) | ||
} | ||
}) |
25372
11
7
249
97