bahtrext
Version:
BahtText Stringify
32 lines (28 loc) • 919 B
JavaScript
import { isOctal, toDecOctal as toDec } from '../base/octal';
import { isBin, toDecBin as toBin } from '../base/binary';
import { isHex, toHex } from '../base/hexadecimal';
import MoneyInvalid from '../snippet/MoneyInvalid';
import BahtText from './BahtTextv2';
import INFINITY from '../const/primitive/INFINITY';
import ISINFSTR from "./ISINFSTR";
import { ed, OL, rounding } from '../const/defaultConfig';
export default (money, config = { ed, OL, rounding }) => {
if (ISINFSTR(money)) return INFINITY;
const { ed, OL, rounding } = config;
if (OL && isOctal(money)) {
money = toDec(money);
} else if (isBin(money)) {
money = toBin(money);
} else if (isHex(money)) {
money = toHex(money);
}
const rBahtText = BahtText(
money,
{
ed,
rounding,
ClErr: () => MoneyInvalid,
}
);
return rBahtText;
};