overleaf/services/web/app/src/Features/Subscription/SubscriptionFormatters.js
Thomas 2d8e832be7 Subscription code decaf cleanup (#7918)
GitOrigin-RevId: 43adff9af7ca347808980823ac641db05129a79b
2022-05-18 08:04:31 +00:00

44 lines
822 B
JavaScript

const dateformat = require('dateformat')
const currenySymbols = {
EUR: '€',
USD: '$',
GBP: '£',
SEK: 'kr',
CAD: '$',
NOK: 'kr',
DKK: 'kr',
AUD: '$',
NZD: '$',
CHF: 'Fr',
SGD: '$',
}
module.exports = {
formatPrice(priceInCents, currency) {
if (!currency) {
currency = 'USD'
}
let string = priceInCents + ''
if (string.length === 2) {
string = `0${string}`
}
if (string.length === 1) {
string = `00${string}`
}
if (string.length === 0) {
string = '000'
}
const cents = string.slice(-2)
const dollars = string.slice(0, -2)
const symbol = currenySymbols[currency]
return `${symbol}${dollars}.${cents}`
},
formatDate(date) {
if (!date) {
return null
}
return dateformat(date, 'dS mmmm yyyy')
},
}