-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd34292
commit 6cf3e41
Showing
29 changed files
with
330 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ lib | |
playground.js | ||
coverage | ||
app.js | ||
webpack.config.js | ||
webpack.config.js | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
const NEG = require(`./NEG`) | ||
const BF = require(`./BF`) | ||
const NEG = require(`./NEG`); | ||
const BF = require(`./BF`); | ||
const MAX_SAFE_INTEGER = require("../const/primitive/MAX_SAFE_INTEGER"); | ||
const THBText = require("thai-baht-text"); | ||
|
||
module.exports = (money, ed = false, allow_neg = false) => { | ||
let retVal = undefined; | ||
if (!money) return retVal; | ||
switch (typeof money) { | ||
case "number": | ||
if (money > MAX_SAFE_INTEGER) { | ||
console.warn(`Consider use BahtRext`); | ||
} | ||
const THBText = require("thai-baht-text"); | ||
if (money < 0) { | ||
retVal = `ลบ${THBText(-money)}`; | ||
} else { | ||
retVal = THBText(money); | ||
} | ||
break; | ||
case "string": | ||
if (allow_neg) { | ||
retVal = NEG(money, ed); | ||
} else { | ||
retVal = BF(money, ed); | ||
} | ||
break; | ||
if (!money) return undefined; | ||
|
||
if (typeof money === "number") { | ||
if (money > MAX_SAFE_INTEGER) { | ||
console.warn(`Consider using BahtRext`); | ||
} | ||
return money < 0 ? `ลบ${THBText(-money)}` : THBText(money); | ||
} | ||
return retVal; | ||
}; | ||
|
||
if (typeof money === "string") { | ||
return allow_neg ? NEG(money, ed) : BF(money, ed); | ||
} | ||
|
||
return undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
const THAI2ARABICNumerals = require(`../const/array/THAI2ARABICNumerals`); | ||
const BT = require(`./BT`); | ||
|
||
module.exports = (flexmoney, ed = false, InvalidType = `Invalid Type`, OL = false) => { | ||
module.exports = ( | ||
flexmoney, | ||
ed = false, | ||
InvalidType = `Invalid Type`, | ||
OL = false | ||
) => { | ||
if (!flexmoney) return undefined; | ||
if (typeof flexmoney !== "string") return InvalidType; | ||
let money = flexmoney; | ||
for (const THAI2ARABICNumeral of THAI2ARABICNumerals) { | ||
money = money.replace( | ||
RegExp(THAI2ARABICNumeral.th, `g`), | ||
THAI2ARABICNumeral.a | ||
); | ||
} | ||
|
||
let money = THAI2ARABICNumerals.reduce( | ||
(acc, { th, a }) => acc.replace(new RegExp(th, `g`), a), | ||
flexmoney | ||
); | ||
|
||
return BT(money, ed, OL); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
module.exports = (match, skips) => { | ||
for (const skip of skips) { | ||
if (skip.test(match)) return true; | ||
} | ||
return false; | ||
}; | ||
module.exports = (match, skips) => skips.some((skip) => skip.test(match)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const SPLITPATTERN = require(`../const/regex/SPLITPATTERN`) | ||
const SPLITPATTERN = require(`../const/regex/SPLITPATTERN`); | ||
|
||
module.exports = (money, rounding) => { | ||
if (rounding === ``) return SPLITPATTERN.test(money); | ||
return /\d*(\.\d+)?/.test(money); | ||
}; | ||
return rounding === `` ? SPLITPATTERN.test(money) : /\d*(\.\d+)?/.test(money); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
const BT = require(`./BT`) | ||
const TB = require(`./TB`) | ||
const FULLBAHT = require(`../const/primitive/FULLBAHT`) | ||
const BT = require(`./BT`); | ||
const TB = require(`./TB`); | ||
const FULLBAHT = require(`../const/primitive/FULLBAHT`); | ||
|
||
module.exports = (str) => { | ||
const BTTB = BT(TB(str)).replace(/\s/g, ""); | ||
return str === BTTB.replace(FULLBAHT, ""); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.