UNPKG

bahtrext

Version:
22 lines (17 loc) 668 B
import hundredThousandToOne from './hundredThousandToOne'; import LeadingSpecialOneToOne from './LeadingSpecialOneToOne'; import { MILLION, BAHT, LAST6DIGITPATTERN } from '../const'; import defaultEd from "../const/defaultConfig/ed" export default (money, ed = defaultEd) => { if (!money) return ``; const newMoney = []; while (money) { const selectedupto6digit = money.match(LAST6DIGITPATTERN)[0]; newMoney.push(`${hundredThousandToOne(selectedupto6digit, ed)}${MILLION}`); money = money.replace(LAST6DIGITPATTERN, ""); } return `${LeadingSpecialOneToOne(newMoney.toReversed().join("")).replace( /ล้าน$/, `` )}${BAHT}`; };