bahttext 2.3.2 → 2.3.4

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.
@@ -0,0 +1,77 @@
1
+ ---
2
+ description: bahttext project context and conventions
3
+ globs:
4
+ alwaysApply: true
5
+ ---
6
+
7
+ # bahttext Project
8
+
9
+ A JavaScript library to convert numbers to Thai Baht pronunciation text. Compatible with Google Sheets BAHTTEXT function. See [README.md](../../README.md) for full documentation (API, usage examples).
10
+
11
+ ## Project Structure
12
+
13
+ ```
14
+ bahttext/
15
+ ├── src/
16
+ │ ├── index.js # Main source (all logic)
17
+ │ ├── index.d.ts # TypeScript declarations
18
+ │ └── index.test.js # Jest tests
19
+ ├── misc/ # Test data from Google Sheets
20
+ ├── example/ # CommonJS, ES6, HTML examples
21
+ ├── doc/ # Multi-language README translations
22
+ └── coverage/ # Test coverage reports
23
+ ```
24
+
25
+ ## Technology Stack
26
+
27
+ - JavaScript (ES6) with JSDoc type annotations
28
+ - Jest for testing (with 80% coverage threshold)
29
+ - Standard.js for linting
30
+ - Stryker for mutation testing
31
+ - TypeScript (declaration generation only)
32
+ - semantic-release for versioning
33
+ - Zero runtime dependencies
34
+
35
+ ## Code Conventions
36
+
37
+ - Single source file architecture (`src/index.js`)
38
+ - Public function: `bahttext(input)` - accepts number or numeric string
39
+ - Helper functions: `numberToWords`, `handleNumericInput`, `handleStringInput`, `formatSatang`
40
+ - Uses lookup tables for Thai words (ONES, TENS, SUB_HUNDRED, DIGIT)
41
+ - CommonJS module exports with default export
42
+ - Use JSDoc for type annotations with @param, @returns, @public, @private
43
+
44
+ ## Testing Conventions
45
+
46
+ - Test file: `src/index.test.js`
47
+ - Use Jest with describe/test pattern
48
+ - Import from `'@jest/globals'`: `const { test, expect, describe } = require('@jest/globals')`
49
+ - Test cases imported from Google Sheets (`misc/testcases.json`)
50
+ - Export private functions for unit testing
51
+ - Group tests by function name using describe blocks
52
+
53
+ ## Verification Steps
54
+
55
+ Before committing changes, run these verification steps:
56
+
57
+ 1. **Linting**: `npm run standard` - Check code style with Standard.js
58
+ 2. **Unit Tests**: `npm run test` - Verify all tests pass
59
+ 3. **Code Coverage**: `npm run coverage.check` - Check 80% coverage threshold
60
+ 4. **Build**: `npm run build` - Generate TypeScript declarations
61
+ 5. **Full Validation**: `npm run validate` - Run all checks (standard + coverage + build)
62
+
63
+ ## Error Handling
64
+
65
+ - Return default "ศูนย์บาทถ้วน" for invalid input (null, undefined, boolean, array, object, non-numeric string)
66
+ - Validate input type (number or numeric string only)
67
+ - Handle safe integer range boundaries (Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER)
68
+ - Never throw errors from public API
69
+
70
+ ## Post-Work
71
+
72
+ After implementing a feature:
73
+
74
+ 1. **Update README.md** - Document new functionality or API changes (update both Thai and English versions)
75
+ 2. **Update test cases** - Add test cases to `misc/testcases.json` if needed
76
+ 3. **Update examples** - Update `example/` files if API changes
77
+ 4. **Git commit** - Use semantic-release pattern (feat:, fix:, docs:, etc.)
@@ -0,0 +1,59 @@
1
+ ---
2
+ description: Development commands and workflows for bahttext project
3
+ globs: bahttext/**
4
+ ---
5
+
6
+ # bahttext Development Commands
7
+
8
+ ## Test Data Management
9
+
10
+ Fetch test cases from Google Sheets:
11
+
12
+ ```bash
13
+ brew install curl
14
+ brew install jq
15
+ npm install -g csvtojson
16
+ curl -L -o ./misc/testcases.csv https://docs.google.com/spreadsheets/d/e/2PACX-1vTb8PIKzgo07rn9UpcjqE0YrdMAmf4fyDbL2plUieLCyrn_5O3vDvece7UfkaArWQLUSsaw92jVpY_z/pub?gid=0&single=true&output=csv
17
+ csvtojson ./misc/testcases.csv | jq > ./misc/testcases.json
18
+ ```
19
+
20
+ ## Dependency Management
21
+
22
+ Update dependencies:
23
+
24
+ ```bash
25
+ npm update --save
26
+ npm audit fix --force
27
+ ```
28
+
29
+ ## Mutation Testing
30
+
31
+ Setup and run mutation tests:
32
+
33
+ ```bash
34
+ npm install -g stryker-cli
35
+ stryker init
36
+ export STRYKER_DASHBOARD_API_KEY=<the_project_api_token>
37
+ echo $STRYKER_DASHBOARD_API_KEY
38
+ npx stryker run
39
+ ```
40
+
41
+ ## Demo Testing
42
+
43
+ Test demo examples:
44
+
45
+ ```bash
46
+ node ./example/commonjs.js
47
+ ts-node ./example/es6.ts
48
+ (cd example && node remoteCommonjs.js)
49
+ (cd example && ts-node remoteEs6.ts)
50
+ ```
51
+
52
+ ## Publishing
53
+
54
+ Build and publish:
55
+
56
+ ```bash
57
+ npm run build
58
+ npm publish --dry-run
59
+ ```
package/README.md CHANGED
@@ -3,50 +3,36 @@
3
3
  [![Version - npm](https://img.shields.io/npm/v/bahttext.svg)](https://www.npmjs.com/package/bahttext)
4
4
  [![Download - npm](https://img.shields.io/npm/dt/bahttext.svg)](https://www.npmjs.com/package/bahttext)
5
5
  [![License - npm](https://img.shields.io/npm/l/bahttext.svg)](http://opensource.org/licenses/MIT)
6
- [![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/)
6
+ [![install size](https://packagephobia.com/badge?p=bahttext)](https://packagephobia.com/result?p=bahttext)
7
+ [![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)
7
8
  [![Codecov](https://img.shields.io/codecov/c/github/jojoee/bahttext.svg)](https://codecov.io/github/jojoee/bahttext)
8
9
  [![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)
9
10
 
10
- [![continuous integration](https://github.com/jojoee/bahttext/workflows/continuous%20integration/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/continuous-integration.yml)
11
- [![release](https://github.com/jojoee/bahttext/workflows/release/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/release.yml)
12
- [![runnable](https://github.com/jojoee/bahttext/workflows/runnable/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/runnable.yml)
13
- [![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)
11
+ [![continuous-integration](https://github.com/jojoee/bahttext/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/jojoee/bahttext/actions/workflows/continuous-integration.yml)
12
+ [![release](https://github.com/jojoee/bahttext/actions/workflows/release.yml/badge.svg)](https://github.com/jojoee/bahttext/actions/workflows/release.yml)
13
+ [![runnable](https://github.com/jojoee/bahttext/actions/workflows/runnable.yml/badge.svg)](https://github.com/jojoee/bahttext/actions/workflows/runnable.yml)
14
14
 
15
- Only `TH` and `EN` languages are maintained, the rest is auto-generated by ChatGPT API. Language:
16
- [ไทย](https://github.com/jojoee/bahttext/blob/master/README.md),
17
- [English](https://github.com/jojoee/bahttext/blob/master/README-en.md),
18
- [中国大陆](https://github.com/jojoee/bahttext/blob/master/doc/README-cn.md),
19
- [대한민국](https://github.com/jojoee/bahttext/blob/master/doc/README-kr.md),
20
- [Việt Nam](https://github.com/jojoee/bahttext/blob/master/doc/README-vn.md),
21
- [日本](https://github.com/jojoee/bahttext/blob/master/doc/README-jp.md),
22
- [Россия](https://github.com/jojoee/bahttext/blob/master/doc/README-ru.md),
23
- [Español](https://github.com/jojoee/bahttext/blob/master/doc/README-la.md),
24
- [Français](https://github.com/jojoee/bahttext/blob/master/doc/README-fr.md)
15
+ Change number to Thai pronunciation string, test
16
+ against [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en), [Demo page](https://jojoee.github.io/bahttext/)
25
17
 
26
- เปลี่ยนตัวเลข เป็นคำอ่านภาษาไทย,
27
- โมดูลตัวนี้ได้ทำการทดสอบกับ [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en), [Demo page](https://jojoee.github.io/bahttext/)
28
- เรียบร้อยแล้ว
29
-
30
- ## ติดตั้ง
18
+ ## Installation
31
19
 
32
20
  ```
33
21
  // CommonJS
34
22
  npm install bahttext
35
23
  const { bahttext } = require('bahttext')
36
24
 
37
- // Bower
38
- bower install bahttext
39
- <script src="bower_components/bahttext/src/index.js"></script>
40
-
41
25
  // githack
42
26
  <script src="https://raw.githack.com/jojoee/bahttext/master/src/index.js"></script>
43
27
 
44
28
  // ES6
45
29
  npm install bahttext
46
30
  import { bahttext } from "bahttext"
31
+
32
+ // TypeScript declarations included
47
33
  ```
48
34
 
49
- ## ตัวอย่างการใช้งาน
35
+ ## Example usage
50
36
 
51
37
  ```javascript
52
38
  bahttext(8.00) // แปดบาทถ้วน
@@ -75,22 +61,26 @@ bahttext(-1.04) // ลบหนึ่งบาทสี่สตางค์
75
61
  bahttext(-574.45) // ลบห้าร้อยเจ็ดสิบสี่บาทสี่สิบห้าสตางค์
76
62
  bahttext(-345.23) // ลบสามร้อยสี่สิบห้าบาทยี่สิบสามสตางค์
77
63
  bahttext(-0.20) // ลบยี่สิบสตางค์
64
+
65
+ // String input
66
+ bahttext("123.45") // หนึ่งร้อยยี่สิบสามบาทสี่สิบห้าสตางค์
67
+ bahttext("0.1") // สิบสตางค์
68
+ bahttext("-5.50") // ลบห้าบาทห้าสิบสตางค์
78
69
  ```
79
70
 
80
- ## ฟีเจอร์
71
+ ## Note
81
72
 
82
- - สามารถใช้งานได้ทุก เบราว์เซอร์
83
- - สามารถใช้งานได้ตั้งแต่ Node.js version 6+
73
+ - Compatible with all browsers
74
+ - Node.js version support: 18+
84
75
  - 0 Dependencies
85
- - หน้าตัวอย่างการใช้งาน
86
- - สนับสนุนการใช้งานกับตัวเลขติดลบ
87
-
88
- ## ภาษาอื่นๆ
89
-
90
- - Python: [jojoee/pybaht](https://github.com/jojoee/pybaht)
76
+ - Demo page
77
+ - Support negative number
78
+ - Accepts both number and string input
79
+ - TypeScript declarations included
80
+ - Invalid input returns "ศูนย์บาทถ้วน"
91
81
 
92
- ## อ้างอิง
82
+ ## Reference
93
83
 
94
84
  - [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en)
95
85
  - [Microsoft Office's BAHTTEXT function](https://support.office.com/en-us/article/BAHTTEXT-function-5ba4d0b4-abd3-4325-8d22-7a92d59aab9c)
96
- - แรงบัลดาลใจจาก [earthchie/BAHTTEXT.js](https://github.com/earthchie/BAHTTEXT.js)
86
+ - Inspired by [earthchie/BAHTTEXT.js](https://github.com/earthchie/BAHTTEXT.js)
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "bahttext",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "description": "Change number to Thai pronunciation string",
5
5
  "main": "src/index.js",
6
- "typings": "src/index.d.ts",
6
+ "types": "src/index.d.ts",
7
7
  "scripts": {
8
8
  "jest": "jest",
9
9
  "jest.watch": "jest --watch",
@@ -34,6 +34,9 @@
34
34
  "url": "https://github.com/jojoee/bahttext/issues"
35
35
  },
36
36
  "homepage": "https://github.com/jojoee/bahttext#readme",
37
+ "engines": {
38
+ "node": ">=18"
39
+ },
37
40
  "devDependencies": {
38
41
  "@stryker-mutator/core": "^8.7.1",
39
42
  "@stryker-mutator/jest-runner": "^8.7.1",
package/src/index.js CHANGED
@@ -16,7 +16,11 @@ const TENS = [
16
16
  ...[EMPTY, YEE, ...THREE_TO_NINE].map(t => t + DIGIT[1]) // "สิบ" family
17
17
  ]
18
18
  // 0-99 lookup (fast satang conversion)
19
- const SUB_HUNDRED = TENS.flatMap(t => ONES.map(o => t + o))
19
+ const SUB_HUNDRED = TENS.reduce(
20
+ (acc, t) => acc.concat(ONES.map(o => t + o)),
21
+ []
22
+ )
23
+
20
24
  // Special case: 1 should read "หนึ่ง" not "เอ็ด"
21
25
  SUB_HUNDRED[1] = ONE
22
26
 
package/.eslintignore DELETED
File without changes
package/README-en.md DELETED
@@ -1,95 +0,0 @@
1
- # bahttext
2
-
3
- [![Version - npm](https://img.shields.io/npm/v/bahttext.svg)](https://www.npmjs.com/package/bahttext)
4
- [![Download - npm](https://img.shields.io/npm/dt/bahttext.svg)](https://www.npmjs.com/package/bahttext)
5
- [![License - npm](https://img.shields.io/npm/l/bahttext.svg)](http://opensource.org/licenses/MIT)
6
- [![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/)
7
- [![Codecov](https://img.shields.io/codecov/c/github/jojoee/bahttext.svg)](https://codecov.io/github/jojoee/bahttext)
8
- [![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)
9
-
10
- [![continuous integration](https://github.com/jojoee/bahttext/workflows/continuous%20integration/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/continuous-integration.yml)
11
- [![release](https://github.com/jojoee/bahttext/workflows/release/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/release.yml)
12
- [![runnable](https://github.com/jojoee/bahttext/workflows/runnable/badge.svg?branch=master)](https://github.com/jojoee/bahttext/actions/workflows/runnable.yml)
13
- [![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)
14
-
15
- Only `TH` and `EN` languages are maintained, the rest is auto-generated by ChatGPT API. Language:
16
- [ไทย](https://github.com/jojoee/bahttext/blob/master/README.md),
17
- [English](https://github.com/jojoee/bahttext/blob/master/README-en.md),
18
- [中国大陆](https://github.com/jojoee/bahttext/blob/master/doc/README-cn.md),
19
- [대한민국](https://github.com/jojoee/bahttext/blob/master/doc/README-kr.md),
20
- [Việt Nam](https://github.com/jojoee/bahttext/blob/master/doc/README-vn.md),
21
- [日本](https://github.com/jojoee/bahttext/blob/master/doc/README-jp.md),
22
- [Россия](https://github.com/jojoee/bahttext/blob/master/doc/README-ru.md),
23
- [Español](https://github.com/jojoee/bahttext/blob/master/doc/README-la.md),
24
- [Français](https://github.com/jojoee/bahttext/blob/master/doc/README-fr.md)
25
-
26
- Change number to Thai pronunciation string, test
27
- against [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en), [Demo page](https://jojoee.github.io/bahttext/)
28
-
29
- ## Installation
30
-
31
- ```
32
- // CommonJS
33
- npm install bahttext
34
- const { bahttext } = require('bahttext')
35
-
36
- // Bower
37
- bower install bahttext
38
- <script src="bower_components/bahttext/src/index.js"></script>
39
-
40
- // githack
41
- <script src="https://raw.githack.com/jojoee/bahttext/master/src/index.js"></script>
42
-
43
- // ES6
44
- npm install bahttext
45
- import { bahttext } from "bahttext"
46
- ```
47
-
48
- ## Example usage
49
-
50
- ```javascript
51
- bahttext(8.00) // แปดบาทถ้วน
52
- bahttext(5678.00) // ห้าพันหกร้อยเจ็ดสิบแปดบาทถ้วน
53
- bahttext(63147.89) // หกหมื่นสามพันหนึ่งร้อยสี่สิบเจ็ดบาทแปดสิบเก้าสตางค์
54
- bahttext(51000001.00) // ห้าสิบเอ็ดล้านหนึ่งบาทถ้วน
55
- bahttext(317.10) // สามร้อยสิบเจ็ดบาทสิบสตางค์
56
- bahttext(422.26) // สี่ร้อยยี่สิบสองบาทยี่สิบหกสตางค์
57
- bahttext(11.11) // สิบเอ็ดบาทสิบเอ็ดสตางค์
58
- bahttext(191415.11) // หนึ่งแสนเก้าหมื่นหนึ่งพันสี่ร้อยสิบห้าบาทสิบเอ็ดสตางค์
59
- bahttext(1.01) // หนึ่งบาทหนึ่งสตางค์
60
- bahttext(5678.46) // ห้าพันหกร้อยเจ็ดสิบแปดบาทสี่สิบหกสตางค์
61
- bahttext(0.67) // หกสิบเจ็ดสตางค์
62
- bahttext(-3.00) // ลบสามบาทถ้วน
63
- bahttext(-232.00) // ลบสองร้อยสามสิบสองบาทถ้วน
64
- bahttext(-44444.00) // ลบสี่หมื่นสี่พันสี่ร้อยสี่สิบสี่บาทถ้วน
65
- bahttext(-5678934.00) // ลบห้าล้านหกแสนเจ็ดหมื่นแปดพันเก้าร้อยสามสิบสี่บาทถ้วน
66
- bahttext(-201.00) // ลบสองร้อยหนึ่งบาทถ้วน
67
- bahttext(-317.10) // ลบสามร้อยสิบเจ็ดบาทสิบสตางค์
68
- bahttext(-5723.00) // ลบห้าพันเจ็ดร้อยยี่สิบสามบาทถ้วน
69
- bahttext(-11.00) // ลบสิบเอ็ดบาทถ้วน
70
- bahttext(-45621.21) // ลบสี่หมื่นห้าพันหกร้อยยี่สิบเอ็ดบาทยี่สิบเอ็ดสตางค์
71
- bahttext(-191415.11) // ลบหนึ่งแสนเก้าหมื่นหนึ่งพันสี่ร้อยสิบห้าบาทสิบเอ็ดสตางค์
72
- bahttext(-282622.22) // ลบสองแสนแปดหมื่นสองพันหกร้อยยี่สิบสองบาทยี่สิบสองสตางค์
73
- bahttext(-1.04) // ลบหนึ่งบาทสี่สตางค์
74
- bahttext(-574.45) // ลบห้าร้อยเจ็ดสิบสี่บาทสี่สิบห้าสตางค์
75
- bahttext(-345.23) // ลบสามร้อยสี่สิบห้าบาทยี่สิบสามสตางค์
76
- bahttext(-0.20) // ลบยี่สิบสตางค์
77
- ```
78
-
79
- ## Note
80
-
81
- - Compatible with all browsers
82
- - Node.js version support: 6+
83
- - 0 Dependencies
84
- - Demo page
85
- - Support negative number
86
-
87
- ## Other languages
88
-
89
- - Python: [jojoee/pybaht](https://github.com/jojoee/pybaht)
90
-
91
- ## Reference
92
-
93
- - [Google Sheets BAHTTEXT function](https://support.google.com/docs/answer/9982303?hl=en)
94
- - [Microsoft Office's BAHTTEXT function](https://support.office.com/en-us/article/BAHTTEXT-function-5ba4d0b4-abd3-4325-8d22-7a92d59aab9c)
95
- - Inspired by [earthchie/BAHTTEXT.js](https://github.com/earthchie/BAHTTEXT.js)
package/src/index.d.ts DELETED
@@ -1,45 +0,0 @@
1
- declare namespace _default {
2
- export { bahttext };
3
- }
4
- export default _default;
5
- /**
6
- * Convert number → Thai Baht text (supports number or numeric string)
7
- * Mirrors behaviour of previous implementation but with faster core.
8
- *
9
- * @public
10
- * @param {number|string} input
11
- * @returns {string}
12
- */
13
- export function bahttext(input: number | string): string;
14
- /**
15
- * @private
16
- * Handle numeric input and extract baht/satang values
17
- * @param {number} input - numeric input (positive or negative)
18
- * @returns {{baht: number, bahtStr: string, satang: number, isNegative: boolean} | false}
19
- */
20
- export function handleNumericInput(input: number): {
21
- baht: number;
22
- bahtStr: string;
23
- satang: number;
24
- isNegative: boolean;
25
- } | false;
26
- /**
27
- * @private
28
- * Handle string input and extract baht/satang values
29
- * @param {string} input - string input (numeric string, positive or negative)
30
- * @returns {{baht: number, bahtStr: string, satang: number, isNegative: boolean} | false}
31
- */
32
- export function handleStringInput(input: string): {
33
- baht: number;
34
- bahtStr: string;
35
- satang: number;
36
- isNegative: boolean;
37
- } | false;
38
- /**
39
- * @private
40
- * Format satang portion of the output
41
- * @param {number} baht - baht amount
42
- * @param {number} satang - satang amount
43
- * @returns {string} formatted satang string
44
- */
45
- export function formatSatang(baht: number, satang: number): string;