Skip to content

Commit

Permalink
1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PingHuskar committed Apr 4, 2024
1 parent fcaf2ba commit 1aa48a6
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
5. This Number System not working well with large numbers.

## Fixes
- 1.2.0 - `เอ็ด`
- 1.2.1 - GoogleSheetsCellCharactersLimit
- 1.2.0 - Dynamic `เอ็ด`
- 1.1.7 - remove `Googolplex`
- 1.1.3 - add LNBT
- 1.1.1
Expand All @@ -44,7 +45,7 @@
- 1.0.6 - BT is main function

## Test Regex
- [ValidSATANGRegex](https://regex101.com/r/yVvsFN/1)
- [ValidSATANGRegex](https://regex101.com/r/yVvsFN/3)

## 😊 Plz Consider
- [Give A Star](https://github.com/PingHuskar/npm-bahtrext)
Expand Down
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const DEBUG = false;

const VERSION = `1.2.0`
const GoogleSheetsCellCharactersLimit = 50000
const VERSION = `1.2.1`

const SPECIALONE = `เอ็ด`;
const SPECIALTWO = `ยี่`;
Expand Down Expand Up @@ -198,7 +199,12 @@ const BahtText = (
const BT = (money, ed = false) => {
const rBahtText = BahtText(money, ed);;
if (!rBahtText) return undefined;
return rBahtText.split('"').at(-2);
const retText = rBahtText.split('"').at(-2);
if (!retText) return undefined;
if (retText.length > GoogleSheetsCellCharactersLimit) {
console.warn(`return string Exceed Google Sheets Cell Limit (${GoogleSheetsCellCharactersLimit})`);
}
return retText;
};

const THAI2ARABICNumerals = [
Expand Down Expand Up @@ -257,7 +263,7 @@ const BulkBahtText = (
};

const ValidSATANGRegex =
/((ยี่|สาม|สี่|ห้า|หก|เจ็ด|แปด|เก้า)?(สิบ))?(เอ็ด|สอง|สาม|สี่|ห้า|หก|เจ็ด|แปด|เก้า)?สตางค์|(หนึ่งสตางค์)|(ถ้วน)/gs;
/((ยี่|สาม|สี่|ห้า|หก|เจ็ด|แปด|เก้า)?(สิบ)(เอ็ด|สอง|สาม|สี่|ห้า|หก|เจ็ด|แปด|เก้า)?)สตางค์|(หนึ่ง|สอง|สาม|สี่|ห้า|หก|เจ็ด|แปด|เก้า|สิบ)สตางค์|(ถ้วน)/gs;

const NumText = (str, arr = THAINUMBERWORDS, flag = `g`) => {
if (!str) return undefined;
Expand Down
12 changes: 12 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const BR = require('./index');
const op = require('operation-strint');

test('NumText', () => {
expect(BR.NumText(`ไม่เอา123`)).toBe(`ไม่เอาหนึ่งสองสาม`);
Expand Down Expand Up @@ -28,6 +29,9 @@ test('BT', () => {
expect(BR.BT(`0.67`)).toBe(`หกสิบเจ็ดสตางค์`)
expect(BR.BT(`768,601,800,000,000`)).toBe(`เจ็ดร้อยหกสิบแปดล้านหกแสนหนึ่งพันแปดร้อยล้านบาทถ้วน`)
expect(BR.BT(`768_601_800_000_000`)).toBe(`เจ็ดร้อยหกสิบแปดล้านหกแสนหนึ่งพันแปดร้อยล้านบาทถ้วน`)
expect(BR.BT(`777777777777777777777777777777777777777777`)).toBe(
`เจ็ดแสนเจ็ดหมื่นเจ็ดพันเจ็ดร้อยเจ็ดสิบเจ็ดล้านเจ็ดแสนเจ็ดหมื่นเจ็ดพันเจ็ดร้อยเจ็ดสิบเจ็ดล้านเจ็ดแสนเจ็ดหมื่นเจ็ดพันเจ็ดร้อยเจ็ดสิบเจ็ดล้านเจ็ดแสนเจ็ดหมื่นเจ็ดพันเจ็ดร้อยเจ็ดสิบเจ็ดล้านเจ็ดแสนเจ็ดหมื่นเจ็ดพันเจ็ดร้อยเจ็ดสิบเจ็ดล้านเจ็ดแสนเจ็ดหมื่นเจ็ดพันเจ็ดร้อยเจ็ดสิบเจ็ดล้านเจ็ดแสนเจ็ดหมื่นเจ็ดพันเจ็ดร้อยเจ็ดสิบเจ็ดบาทถ้วน`
);
});

test("ABT", () => {
Expand Down Expand Up @@ -243,4 +247,12 @@ test('repeat',() => {
expect(`ปิดสวิตซ์ ${BR.repeat(`ป`, [3])} ป่าหี่`).toBe(
`ปิดสวิตซ์ ปปป ป่าหี่`
);
})

test(`sum bt`, ()=> {
expect(BR.BT(op.sum(`12`, `25`))).toBe(`สามสิบเจ็ดบาทถ้วน`);
expect(BR.BT(op.sum(`12`, `12`))).toBe(`ยี่สิบสี่บาทถ้วน`);
})
test(`minus bt`, ()=> {
expect(BR.BT(op.minus(`12`, `12`))).toBe(`ศูนย์บาทถ้วน`);
})
70 changes: 67 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"name": "bahtrext",
"version": "1.2.0",
"version": "1.2.1",
"description": "Better BahtText",
"main": "index.js",
"scripts": {
"test": "jest"
},
"author": "Chadin Chaipornpisuth",
"license": "ISC",
"repository": {
"type": "git",
"url": "git+https://github.com/PingHuskar/npm-bahtrext.git"
},
"keywords": [
"Thai",
"BahtText",
Expand All @@ -17,7 +21,8 @@
"devDependencies": {
"bahttext": "^2.3.0",
"jest": "^29.7.0",
"numbaht": "^0.1.1"
"numbaht": "^0.1.1",
"operation-strint": "^1.0.3"
},
"dependencies": {
"thai-baht-text": "^1.0.8"
Expand Down

0 comments on commit 1aa48a6

Please sign in to comment.