Repository URL to install this package:
|
Version:
1.2.19 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatPrice = formatPrice;
exports.default = void 0;
// Format a price to standard fixed
const toFloat = x => parseFloat(x).toFixed(2);
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';
}
}
var _default = formatPrice;
exports.default = _default;