diff --git a/.gitignore b/.gitignore index 9a77af5..44fac6f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ lib .DS_Store playground.js coverage -app.js \ No newline at end of file +app.js +webpack.config.js \ No newline at end of file diff --git a/README.md b/README.md index 0955a8a..cd4b625 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/binary.js b/binary.js index b30407a..0a8e916 100644 --- a/binary.js +++ b/binary.js @@ -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); }; diff --git a/binary.test.js b/binary.test.js index 03a3449..5219a97 100644 --- a/binary.test.js +++ b/binary.test.js @@ -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); @@ -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); diff --git a/const/array/THAI2ARABICNumerals.js b/const/array/THAI2ARABICNumerals.js index e47d91f..fa75dae 100644 --- a/const/array/THAI2ARABICNumerals.js +++ b/const/array/THAI2ARABICNumerals.js @@ -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` }, -] \ No newline at end of file +module.exports = Array.from({ length: 10 }, (_, i) => ({ + th: String.fromCodePoint(3664 + i), + a: String.fromCodePoint(48 + i), +}));; \ No newline at end of file diff --git a/const/primitive/VERSION.js b/const/primitive/VERSION.js index 36ea38e..1153031 100644 --- a/const/primitive/VERSION.js +++ b/const/primitive/VERSION.js @@ -1 +1 @@ -module.exports = `1.6.0`; \ No newline at end of file +module.exports = `1.6.1`; \ No newline at end of file diff --git a/hexadecimal.js b/hexadecimal.js index d76f076..9584f17 100644 --- a/hexadecimal.js +++ b/hexadecimal.js @@ -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); }; diff --git a/hexadecimal.test.js b/hexadecimal.test.js index 84705ec..b171c6d 100644 --- a/hexadecimal.test.js +++ b/hexadecimal.test.js @@ -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); diff --git a/index.test.js b/index.test.js index 7e5a930..768263b 100644 --- a/index.test.js +++ b/index.test.js @@ -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`,() => { diff --git a/octal.js b/octal.js index 96c2831..ce92fd6 100644 --- a/octal.js +++ b/octal.js @@ -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); } diff --git a/octal.test.js b/octal.test.js index 096c311..25d7f38 100644 --- a/octal.test.js +++ b/octal.test.js @@ -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); diff --git a/package-lock.json b/package-lock.json index 13da354..45c0e58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bahtrext", - "version": "1.5.0", + "version": "1.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bahtrext", - "version": "1.5.0", + "version": "1.6.0", "license": "MIT", "dependencies": { "operation-strint": "^1.0.8", diff --git a/package.json b/package.json index 472495d..8fcd3bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bahtrext", - "version": "1.6.0", + "version": "1.6.1", "description": "BahtText Stringify", "main": "index.js", "scripts": {