Skip to content

Commit

Permalink
1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PingHuskar committed Jan 7, 2025
1 parent 57e08ce commit dd34292
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ lib
.DS_Store
playground.js
coverage
app.js
app.js
webpack.config.js
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
5. This Number System not working well with large numbers. Is there a better way to read numbers in Thai?

## Changes
- 1.6.1 - allow literal separator (,)
- 1.6.0 - add Hexadecimal
- 1.5.0 - add Binary Literal
- 1.4.3 - 1.4.4 - Refactor
Expand Down
2 changes: 2 additions & 0 deletions binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const op = require(`operation-strint`);

const isBin = (money) => {
if (typeof money !== `string`) return undefined;
if (/__/i.test(money)) return false;
money = money.replace(/(?<=[01])_(?=[01])/g, "");
return binaryRegex.test(money);
};

Expand Down
7 changes: 7 additions & 0 deletions binary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { isBin, toBin } = require(`./binary`);

test(`isBin true`, () => {
expect(isBin(`0b101010`)).toBe(true);
expect(isBin(`0b1_0101_0`)).toBe(true);
expect(isBin(`0b1`)).toBe(true);
expect(isBin(`0B1`)).toBe(true);
expect(isBin(`0b0`)).toBe(true);
Expand All @@ -11,6 +12,12 @@ test(`isBin true`, () => {

test(`isBin false`, () => {
expect(isBin(`0b`)).toBe(false);
expect(isBin(`0b1_`)).toBe(false);
expect(isBin(`0b0_`)).toBe(false);
expect(isBin(`0b_0_`)).toBe(false);
expect(isBin(`0b_1`)).toBe(false);
expect(isBin(`0b0_1010__111`)).toBe(false);
expect(isBin(`0b01_101010_`)).toBe(false);
expect(isBin(`0b1013010`)).toBe(false);
expect(isBin(`077`)).toBe(false);
expect(isBin(`000077`)).toBe(false);
Expand Down
16 changes: 4 additions & 12 deletions const/array/THAI2ARABICNumerals.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
module.exports = [
{ th: `๐`, a: `0` },
{ th: `๑`, a: `1` },
{ th: `๒`, a: `2` },
{ th: `๓`, a: `3` },
{ th: `๔`, a: `4` },
{ th: `๕`, a: `5` },
{ th: `๖`, a: `6` },
{ th: `๗`, a: `7` },
{ th: `๘`, a: `8` },
{ th: `๙`, a: `9` },
]
module.exports = Array.from({ length: 10 }, (_, i) => ({
th: String.fromCodePoint(3664 + i),
a: String.fromCodePoint(48 + i),
}));;
2 changes: 1 addition & 1 deletion const/primitive/VERSION.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = `1.6.0`;
module.exports = `1.6.1`;
2 changes: 2 additions & 0 deletions hexadecimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const op = require(`operation-strint`);

const isHex = (money) => {
if (typeof money !== `string`) return undefined;
if (/__/i.test(money)) return false;
money = money.replace(/(?<=[\da-f])_(?=[\da-f])/gi, "");
return hexadecRegex.test(money);
};

Expand Down
11 changes: 11 additions & 0 deletions hexadecimal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ test(`isHex true`, () => {
expect(isHex(`0X1F`)).toBe(true);
expect(isHex(`0x0F`)).toBe(true);
expect(isHex(`0X0E`)).toBe(true);
expect(isHex(`0x101_A010`)).toBe(true);
expect(isHex(`0x1_F`)).toBe(true);
expect(isHex(`0X1_F`)).toBe(true);
expect(isHex(`0x0_F`)).toBe(true);
expect(isHex(`0X0_E`)).toBe(true);
expect(
isHex(`0X001010101010A01C01010F1011E001010010010100100001010010001001`)
).toBe(true);
});

test(`isHex false`, () => {
expect(isHex(`0x101__A010`)).toBe(false);
expect(isHex(`0x1__F`)).toBe(false);
expect(isHex(`0X1__F`)).toBe(false);
expect(isHex(`0x0_F_`)).toBe(false);
expect(isHex(`0X_0_E`)).toBe(false);

expect(isHex(`0xVb`)).toBe(false);
expect(isHex(`0xb10W13010`)).toBe(false);
expect(isHex(`0x7G7`)).toBe(false);
Expand Down
6 changes: 6 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ test('NumText', () => {
test("BF", () => {
expect(BF()).toBe(undefined);
expect(BF(283)).toBe(`Invalid Type`);
expect(BF(`๑๒๓๔๕๖๗๘๐๙`)).toBe(
`หนึ่งพันสองร้อยสามสิบสี่ล้านห้าแสนหกหมื่นเจ็ดพันแปดร้อยเก้าบาทถ้วน`
);
expect(BF(`๑๒๓๔๕๖๗๘๐๙๑`)).toBe(
`หนึ่งหมื่นสองพันสามร้อยสี่สิบห้าล้านหกแสนเจ็ดหมื่นแปดพันเก้าสิบเอ็ดบาทถ้วน`
);
});

test(`BT CEIL`,() => {
Expand Down
7 changes: 7 additions & 0 deletions octal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ const {octalRegex1, octalRegex2} = require('./const')
const op = require(`operation-strint`)
const isOctal = (money) => {
if (typeof(money) !== `string`) return undefined;
if (/__/i.test(money)) return false;
if (/^0o.+/i.test(money)) {
money = money.replace(/(?<=[0-7])_(?=[0-7])/g, "");
}
else if (/_/i.test(money)) {
return false;
}
return octalRegex1.test(money) || octalRegex2.test(money);
}

Expand Down
5 changes: 5 additions & 0 deletions octal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ const {

test(`isOctal`, () => {
expect(isOctal(`077`)).toBe(true)
expect(isOctal(`07_7`)).toBe(false)
expect(isOctal(`077_`)).toBe(false)
expect(isOctal(`000077`)).toBe(true);
expect(isOctal(`0o77`)).toBe(true);
expect(isOctal(`0o77_`)).toBe(false);
expect(isOctal(`0o_77_`)).toBe(false);
expect(isOctal(`0o7__7`)).toBe(false);
expect(isOctal(`0000877`)).toBe(!true);
expect(isOctal(`000o77`)).toBe(!true);
expect(isOctal(`000oo77`)).toBe(!true);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bahtrext",
"version": "1.6.0",
"version": "1.6.1",
"description": "BahtText Stringify",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit dd34292

Please sign in to comment.