2019-05-29 05:21:06 -04:00
|
|
|
const dateformat = require('dateformat')
|
|
|
|
|
|
|
|
const currenySymbols = {
|
|
|
|
EUR: '€',
|
|
|
|
USD: '$',
|
|
|
|
GBP: '£',
|
|
|
|
SEK: 'kr',
|
|
|
|
CAD: '$',
|
|
|
|
NOK: 'kr',
|
|
|
|
DKK: 'kr',
|
|
|
|
AUD: '$',
|
|
|
|
NZD: '$',
|
|
|
|
CHF: 'Fr',
|
2021-04-27 03:52:58 -04:00
|
|
|
SGD: '$',
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
formatPrice(priceInCents, currency) {
|
2022-05-17 06:10:19 -04:00
|
|
|
if (!currency) {
|
2019-05-29 05:21:06 -04:00
|
|
|
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) {
|
2022-05-17 06:10:19 -04:00
|
|
|
if (!date) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
return dateformat(date, 'dS mmmm yyyy')
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|