overleaf/services/web/app/coffee/Features/Subscription/SubscriptionFormatters.coffee

32 lines
636 B
CoffeeScript
Raw Normal View History

2014-02-12 10:23:40 +00:00
dateformat = require 'dateformat'
settings = require "settings-sharelatex"
currenySymbols =
EUR: ""
USD: "$"
GBP: "£"
SEK: "kr"
CAD: "$"
NOK: "kr"
DKK: "kr"
AUD: "$"
NZD: "$"
CHF: "Fr"
SGD: "$"
2014-02-12 10:23:40 +00:00
module.exports =
formatPrice: (priceInCents, currency = "USD") ->
2014-02-12 10:23:40 +00:00
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}"
2014-02-12 10:23:40 +00:00
formatDate: (date) ->
dateformat date, "dS mmmm yyyy"