overleaf/services/web/app/coffee/Features/Subscription/SubscriptionFormatters.coffee
James Allen 0f1c732d15 Merge pull request #1130 from sharelatex/ja-subscription-dashboard
Refactor subscription dashboard

GitOrigin-RevId: 3573822b8b48c7181c661b2c253d7713f4a4328c
2018-11-19 16:01:59 +00:00

33 lines
No EOL
660 B
CoffeeScript

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