-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (59 loc) · 2.07 KB
/
index.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
const CATEGORIES = {
commands: 'dstatus/command-package',
modules: 'dstatus/module',
people: 'dstatus/person',
websites: 'dstatus/website',
}
const CATEGORIES__P_TO_S = {
commands: 'command',
modules: 'module',
people: 'person',
websites: 'website'
}
const CATEGORIES__S_TO_P = Object.assign({}, ...Object.entries(CATEGORIES__P_TO_S).map(([a,b]) => ({ [b]: a })))
function getCat (st, usePlural) {
if (usePlural) return CATEGORIES__S_TO_P[st] || st
return CATEGORIES__P_TO_S[st] || st
}
exports.typeToCategory = function (type, usePlural = false) {
type = Array.isArray(type) ? type[0] : type
if (type === 'dstatus/command-package') return getCat('commands', usePlural)
if (type === 'dstatus/module') return getCat('modules', usePlural)
if (type === 'dstatus/person') return getCat('people', usePlural)
if (type === 'dstatus/website') return getCat('websites', usePlural)
return undefined
}
exports.categoryToType = function (category) {
category = categoryToPlural(category)
return CATEGORIES[category]
}
exports.getCategoriesArray = function (usePlural = false) {
return Object.keys(CATEGORIES).map(st => getCat(st, usePlural))
}
exports.getCategoriesMap = function (usePlural = false) {
var map = {}
for (let st in CATEGORIES) {
map[getCat(st, usePlural)] = CATEGORIES[st]
}
return map
}
const categoryToPlural =
exports.categoryToPlural = function (category) {
if (CATEGORIES__S_TO_P[category]) return CATEGORIES__S_TO_P[category]
if (category in CATEGORIES__P_TO_S) return category
return undefined
}
const categoryToSingular =
exports.categoryToSingular = function (category) {
if (CATEGORIES__P_TO_S[category]) return CATEGORIES__P_TO_S[category]
if (category in CATEGORIES__S_TO_P) return category
return undefined
}
exports.getFAIcon = function (category) {
category = categoryToSingular(category)
if (category === 'command') return 'fas fa-terminal'
if (category === 'module') return 'fas fa-cube'
if (category === 'person') return 'far fa-user'
if (category === 'website') return 'far fa-file-alt'
return 'fas fa-archive'
}