-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
34 lines (28 loc) · 851 Bytes
/
Copy pathhelpers.js
File metadata and controls
34 lines (28 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var url = require('url')
, qs = require('querystring')
, moment = require('moment')
function helpers () {
return function (req, res, next) {
res.locals.req = req
res.locals.isActive = function (link) {
return req.url.indexOf(link) !== -1 ? 'active' : ''
}
res.locals.formatDatetime = formatDatetime
res.locals.datetimeFormatString = datetimeFormatString
res.locals.moment = moment
if (typeof req.flash !== 'undefined') {
res.locals.info = req.flash('info')
res.locals.errors = req.flash('errors')
res.locals.success = req.flash('success')
res.locals.warning = req.flash('warning')
}
next()
}
}
module.exports = helpers
function datetimeFormatString () {
return 'MM/DD/YY HH:mm'
}
function formatDatetime (date) {
return moment(date).format(datetimeFormatString());
}