utils.coffee 624 B

12345678910111213141516171819202122
  1. moment = require('lib/moment')
  2. exports.isDev = (req) ->
  3. # We are on DEV when Host has string like
  4. # 'dev.' or 'staging.' or '.local' or '.dev' or 'localhost'
  5. re = /(^dev\.|^staging\.|\.local$|\.dev$|localhost)/
  6. return re.test(req.headers.Host)
  7. exports.prettyDate = (date) ->
  8. moment.utc(date).local().format('MMM Do YYYY')
  9. exports.halfDate = (date) ->
  10. moment.utc(date).local().format('MMM D')
  11. exports.isItFresh = (date) ->
  12. if moment.utc().eod() < moment.utc(date).add('days', 30).eod()
  13. return true
  14. return false
  15. exports.capitalize = (str) ->
  16. str ?= ''
  17. str.charAt(0).toUpperCase() + str.slice(1)