@modern-kit/utils
Version:
18 lines (15 loc) • 666 B
JavaScript
import { formatNumberWithCommas } from '../formatNumberWithCommas/index.mjs';
import { formatValueWithSymbol } from '../formatValueWithSymbol/index.mjs';
import { isNumber } from '../../validator/isNumber/index.mjs';
function formatCurrencyUSD(value, options = {}) {
const { decimal = 0 } = options;
const valueToUse = isNumber(value) ? value : Number(value);
const negativeSign = valueToUse < 0 ? "-" : "";
const absoluteValue = Math.abs(valueToUse);
return `${negativeSign}${formatValueWithSymbol(
formatNumberWithCommas(absoluteValue.toFixed(decimal)),
{ prefix: "$" }
)}`;
}
export { formatCurrencyUSD };
//# sourceMappingURL=index.mjs.map