-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.js
84 lines (69 loc) · 1.9 KB
/
hooks.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const { hooks } = require('@adonisjs/ignitor')
hooks.after.providersBooted(( ) => {
const View = use('View')
View.global('currentYear', function () {
return new Date().getFullYear();
})
View.global('isArrayObjectContains', function (arrObject, id) {
return arrObject.some(e => e.id == id)
})
View.global('getMatchedTranslation', function (arrObject, id) {
return arrObject.filter(e => {
return e.id == id
})[0]
})
View.global('convertToDate', function (datetime) {
return datetime.split(' ')[0];
})
View.global('convertToDateTime', function (datetime) {
return new Date(datetime).toLocaleString(undefined, {
day: 'numeric',
month: 'numeric',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
})
})
View.global('convertToTimeStamp', function (datetime) {
return (new Date(new Date(datetime).toString().split('GMT')[0]+' UTC').toISOString().split('.')[0])
})
View.global('printSupportedLanguagesID', function (arrObject) {
let temp = '';
arrObject.map(e => {
temp += e.id + ' '
})
return temp;
})
View.global('printSupportedLanguages', function (arrObject) {
let temp = '';
arrObject.map(e => {
temp += e.name + '|'
})
return temp;
})
View.global('printObjectID', function (arrObject) {
let temp = '';
arrObject.map(e => {
temp += e.id + ' '
})
return temp;
})
View.global('printObjectName', function (arrObject, separator) {
let temp = '';
arrObject.map(e => {
e.languages.map(j => {
if(j.id == 'en'){
temp += j.pivot.name + separator
}
})
})
return temp;
})
View.global('activeRoute', function(url, routeName) {
var arr = url.split('/')
return arr[1] == routeName ? 'active' : ''
})
View.global('count', function (array) {
return array instanceof Array ? array.length : 0
})
})