-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnunjucksFilters.js
46 lines (37 loc) · 904 Bytes
/
nunjucksFilters.js
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
35
36
37
38
39
40
41
42
43
44
45
46
function extractWords(str, i) {
var words = str.split(' ').filter(function(word) { return word.length > 0 })
return i || i === 0 ? words[i] : words
}
function skillRange(str) {
return str.indexOf('/') >= 0 ? parseInt(str.substring(str.indexOf('/') + 1)) : null
}
function skillLevel(str) {
return str.indexOf('/') >= 0 ? parseInt(str) : null
}
function humanizeDateMonth(str, noMonth) {
if(!str) return undefined
var monthsMap = ['',
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
]
var year = parseInt(str)
if(noMonth) return year
var month = monthsMap[parseInt(str.substr(5, 2))]
return month + ' ' + year
}
module.exports = {
extractWords: extractWords,
skillRange: skillRange,
skillLevel: skillLevel,
humanizeDateMonth: humanizeDateMonth
}