SubscriptionFormatters.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* eslint-disable
  2. no-unused-vars,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * DS207: Consider shorter variations of null checks
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const dateformat = require('dateformat')
  13. const settings = require('@overleaf/settings')
  14. const currenySymbols = {
  15. EUR: '€',
  16. USD: '$',
  17. GBP: '£',
  18. SEK: 'kr',
  19. CAD: '$',
  20. NOK: 'kr',
  21. DKK: 'kr',
  22. AUD: '$',
  23. NZD: '$',
  24. CHF: 'Fr',
  25. SGD: '$',
  26. }
  27. module.exports = {
  28. formatPrice(priceInCents, currency) {
  29. if (currency == null) {
  30. currency = 'USD'
  31. }
  32. let string = priceInCents + ''
  33. if (string.length === 2) {
  34. string = `0${string}`
  35. }
  36. if (string.length === 1) {
  37. string = `00${string}`
  38. }
  39. if (string.length === 0) {
  40. string = '000'
  41. }
  42. const cents = string.slice(-2)
  43. const dollars = string.slice(0, -2)
  44. const symbol = currenySymbols[currency]
  45. return `${symbol}${dollars}.${cents}`
  46. },
  47. formatDate(date) {
  48. if (date == null) {
  49. return null
  50. }
  51. return dateformat(date, 'dS mmmm yyyy')
  52. },
  53. }