Skip to content

Commit

Permalink
refac
Browse files Browse the repository at this point in the history
  • Loading branch information
PingHuskar committed Oct 20, 2024
1 parent 40a33e0 commit 98c6779
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 54 deletions.
2 changes: 1 addition & 1 deletion __test__/BT.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BT } from "../index.mjs";
import BT from "../function/BT.mjs";
import op from "operation-strint";

test(`BT CEIL`, () => {
Expand Down
4 changes: 2 additions & 2 deletions __test__/BTTB.test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BT } from "../index.mjs";
import { TB } from "../index.mjs";
import BT from "../function/BT.mjs";
import TB from "../function/TB.mjs";

test("Reverse BahtText", () => {
expect(TB(BT(`123`))).toBe(`123.00`);
Expand Down
2 changes: 1 addition & 1 deletion __test__/IsValidTB.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsValidTB } from "../index.mjs";
import IsValidTB from "../function/IsValidTB.mjs";

test(`IsValidTB`, () => {
expect(IsValidTB(`แปดสิบแปดบาท`)).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion __test__/IsValidText.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsValidText } from "../index.mjs";
import IsValidText from "../function/IsValidText.mjs";

test(`IsValidText`, () => {
expect(
Expand Down
2 changes: 1 addition & 1 deletion __test__/LNBT.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LNBT } from "../index.mjs";
import LNBT from "../function/LNBT.mjs";

test(`LNBT`, () => {
expect(LNBT(`Googolplex`)).toBe(`Don't Try This`);
Expand Down
4 changes: 2 additions & 2 deletions __test__/PrintSatangs.test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrintSatangs } from "../index.mjs";
import { FULLBAHT } from "../const/index.mjs";
import PrintSatangs from "../function/PrintSatangs.mjs";
import FULLBAHT from "../const/primitive/FULLBAHT.mjs";

test("PrintSatangs", () => {
expect(PrintSatangs(`67`)[0]).toBe(`หกสิบเจ็ดสตางค์`);
Expand Down
2 changes: 1 addition & 1 deletion __test__/SEP.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SEP } from "../index.mjs";
import SEP from "../function/SEP.mjs";

test(`sep`, () => {
expect(SEP(`11`, `;;;`)).toBe(`สิบ;;;เอ็ด`);
Expand Down
2 changes: 1 addition & 1 deletion __test__/SatangNum.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SatangNum } from "../index.mjs";
import SatangNum from "../function/SatangNum.mjs";

test("SatangNum", () => {
expect(SatangNum("ถ้วน")).toBe("00");
Expand Down
4 changes: 2 additions & 2 deletions __test__/datatype.test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FULLBAHT } from "../const/index.mjs";
import BAHT from "../const/index.mjs";
import FULLBAHT from "../const/primitive/FULLBAHT.mjs";
import BAHT from "../const/primitive/BAHT.mjs";
import {
NumText,
BT,
Expand Down
2 changes: 1 addition & 1 deletion __test__/repeat.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { repeat } from "../index.mjs";
import repeat from "../function/repeat.mjs";

test("repeat", () => {
expect(repeat(`ค`, [3])).toBe(`คคค`);
Expand Down
4 changes: 2 additions & 2 deletions compare.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {BT} from "./index.mjs"
import { toDec } from "./octal.mjs";
import BT from "./function/BT.mjs"
import toDec from "./octal/toDec.mjs";
import THBText from "thai-baht-text";

let a = 29999999999999999;
Expand Down
2 changes: 1 addition & 1 deletion compare.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {BT} from "./index.mjs"
import BT from "./function/BT.mjs";
import THBText from "thai-baht-text"
import { bahttext } from "bahttext";
import { convert } from "numbaht";
Expand Down
2 changes: 1 addition & 1 deletion function/ABT.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import THBText from "thai-baht-text";
import NEG from "./NEG.mjs";
import BF from "./BF.mjs";
import { MAX_SAFE_INTEGER } from "../const/index.mjs";
import MAX_SAFE_INTEGER from "../const/primitive/MAX_SAFE_INTEGER.mjs";

const ABT = (money, ed = false, allow_neg = false) => {
let retVal = undefined;
Expand Down
2 changes: 1 addition & 1 deletion function/BT.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isOctal, toDec } from "../octal.mjs";
import { isOctal, toDec } from "../octal/index.mjs";
import MoneyInvalid from "../snippet/MoneyInvalid.mjs";
import BahtText from "./BahtText.mjs";
import READAS from "../const/primitive/READAS.mjs";
Expand Down
2 changes: 1 addition & 1 deletion function/IsValidTB.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BT from "./BT.mjs";
import TB from "./TB.mjs";
import { FULLBAHT } from "../const/index.mjs";
import FULLBAHT from "../const/primitive/FULLBAHT.mjs";

const IsValidTB = (str) => {
const BTTB = BT(TB(str)).replace(/\s/g, "");
Expand Down
2 changes: 1 addition & 1 deletion function/NEG.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { negative } from "../const/index.mjs"
import negative from "../const/primitive/negative.mjs";
import BF from "./BF.mjs"

const NEG = (money, ed = false, f = BF, neg = negative) => {
Expand Down
4 changes: 2 additions & 2 deletions function/SatangNum.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FULLBAHT } from "../const/index.mjs"
import {OneToTenTextRegex} from "../const/index.mjs"
import FULLBAHT from "../const/primitive/FULLBAHT.mjs";
import OneToTenTextRegex from "../const/regex/OneToTenTextRegex.mjs";
import ElevenToNineteenRegex from "../const/regex/ElevenToNineteenRegex.mjs"
import TwentyToNinetyNine from "../const/regex/TwentyToNinetyNine.mjs"
import FTHAISATANGWORDS from "../const/array/FTHAISATANGWORDS.mjs"
Expand Down
8 changes: 4 additions & 4 deletions function/hundredThousandToOne.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import REVERSETHAIDIGITWORDS from "../const/array/REVERSETHAIDIGITWORDS.mjs";
import {THAINUMBERWORDS} from "../const/index.mjs";
import {SPECIALONE} from "../const/index.mjs";
import {SPECIALTWO} from "../const/index.mjs";
import {TEN} from "../const/index.mjs";
import THAINUMBERWORDS from "../const/array/THAINUMBERWORDS.mjs";
import SPECIALONE from "../const/primitive/SPECIALONE.mjs";
import SPECIALTWO from "../const/primitive/SPECIALTWO.mjs";
import TEN from "../const/primitive/TEN.mjs";

import padWithLeadingZeros from "../snippet/padWithLeadingZeros.mjs";
const hundredThousandToOne = (digits, ed = false) => {
Expand Down
27 changes: 0 additions & 27 deletions octal.mjs

This file was deleted.

7 changes: 7 additions & 0 deletions octal/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import isOctal from "./isOctal.mjs";
import toDec from "./toDec.mjs";

export {
isOctal,
toDec,
};
8 changes: 8 additions & 0 deletions octal/isOctal.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import octalRegex1 from "../const/regex/octalRegex1.mjs";
import octalRegex2 from "../const/regex/octalRegex2.mjs";

const isOctal = (money) => {
if (typeof money !== `string`) return undefined;
return octalRegex1.test(money) || octalRegex2.test(money);
};
export default isOctal;
3 changes: 2 additions & 1 deletion octal.test.mjs → octal/octal.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isOctal,toDec } from "./octal.mjs";
import isOctal from "./isOctal.mjs";
import toDec from "./toDec.mjs";

test(`isOctal`, () => {
expect(isOctal(`077`)).toBe(true)
Expand Down
15 changes: 15 additions & 0 deletions octal/toDec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import op from "operation-strint";

const toDec = (num) => {
let val = `0`;
if (!isOctal(num)) return num;
num = num.replace(/^0+o?/, ``);
let pos = -1;
for (let i of num.split("").reverse()) {
let thispos_val = op.multiply(op.pow(`8`, `${pos + 1}`), i);
val = op.sum(val, thispos_val);
pos++;
}
return val;
};
export default toDec;

0 comments on commit 98c6779

Please sign in to comment.