SubscriptionFormatters.coffee 553 B

12345678910111213141516171819202122232425
  1. dateformat = require 'dateformat'
  2. settings = require "settings-sharelatex"
  3. currenySymbols =
  4. EUR: "€"
  5. USD: "$"
  6. GBP: "£"
  7. module.exports =
  8. formatPrice: (priceInCents, currency = "USD") ->
  9. string = priceInCents + ""
  10. string = "0" + string if string.length == 2
  11. string = "00" + string if string.length == 1
  12. string = "000" if string.length == 0
  13. cents = string.slice(-2)
  14. dollars = string.slice(0, -2)
  15. symbol = currenySymbols[currency]
  16. return "#{symbol}#{dollars}.#{cents}"
  17. formatDate: (date) ->
  18. dateformat date, "dS mmmm yyyy"