SubscriptionFormatters.coffee 636 B

1234567891011121314151617181920212223242526272829303132
  1. dateformat = require 'dateformat'
  2. settings = require "settings-sharelatex"
  3. currenySymbols =
  4. EUR: "€"
  5. USD: "$"
  6. GBP: "£"
  7. SEK: "kr"
  8. CAD: "$"
  9. NOK: "kr"
  10. DKK: "kr"
  11. AUD: "$"
  12. NZD: "$"
  13. CHF: "Fr"
  14. SGD: "$"
  15. module.exports =
  16. formatPrice: (priceInCents, currency = "USD") ->
  17. string = priceInCents + ""
  18. string = "0" + string if string.length == 2
  19. string = "00" + string if string.length == 1
  20. string = "000" if string.length == 0
  21. cents = string.slice(-2)
  22. dollars = string.slice(0, -2)
  23. symbol = currenySymbols[currency]
  24. return "#{symbol}#{dollars}.#{cents}"
  25. formatDate: (date) ->
  26. dateformat date, "dS mmmm yyyy"