Repository URL to install this package:
|
Version:
1.1.5 ▾
|
// Format a price to standard fixed
const toFloat = (x) => parseFloat(x).toFixed(2);
/**
* @todo currency from a config
* @todo remove the try catches from here
*/
function formatPrice(price, currencycode = '$') {
try {
const asFloat = toFloat(price);
// ...
if (!asFloat) {
return price;
}
const value = String(asFloat);
if (value.includes(currencycode)) {
return value;
}
else {
return `${currencycode}${asFloat}`;
}
}
catch (error) {
return 'N/A';
}
}
export { formatPrice };
export default formatPrice;
//# sourceMappingURL=formatPrice.js.map