Files
overleaf-cep/services/web/app/src/Features/Subscription/SubscriptionFormatters.js
T
M Fahru 2ef5db2938 Merge pull request #22340 from overleaf/mf-clean-up-currency-format-test
[web] Clean up localized currency format test (`local-ccy-format-v2`)

GitOrigin-RevId: 30d671479522b87ee9205994508b745d2b0ae4c3
2025-01-14 09:05:49 +00:00

39 lines
994 B
JavaScript

const dateformat = require('dateformat')
const { formatCurrency } = require('../../util/currency')
/**
* @param {number} priceInCents - price in the smallest currency unit (e.g. dollar cents, CLP units, ...)
* @param {CurrencyCode?} currency - currency code (default to USD)
* @param {string} [locale] - locale string
* @returns {string} - formatted price
*/
function formatPriceLocalized(priceInCents, currency = 'USD', locale) {
const isNoCentsCurrency = ['CLP', 'JPY', 'KRW', 'VND'].includes(currency)
const priceInCurrencyUnit = isNoCentsCurrency
? priceInCents
: priceInCents / 100
return formatCurrency(priceInCurrencyUnit, currency, locale)
}
function formatDateTime(date) {
if (!date) {
return null
}
return dateformat(date, 'mmmm dS, yyyy h:MM TT Z', true)
}
function formatDate(date) {
if (!date) {
return null
}
return dateformat(date, 'mmmm dS, yyyy', true)
}
module.exports = {
formatPriceLocalized,
formatDateTime,
formatDate,
}