-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (52 loc) · 1.28 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
'use strict'
const db = require('./lib/icons/icon-tables.js')
/**
*
* @param {String} name
* @return {Icon}
* @private
*/
const bestMatch = name => {
if (name.endsWith('/')) {
return db.matchName(name.slice(0, -1), true)
}
const matches = [
db.matchName(name, true),
db.matchName(name),
db.matchInterpreter(name),
db.matchLanguage(name),
db.matchScope(name)
]
const match = []
for (let i = 0; i < matches.length; ++i) {
if (matches[i]) {
match.push(matches[i])
}
}
match.sort((a, b) => b.priority - a.priority)
return match[0]
}
class FileIcons {
/**
*
* @param {String} name
* @param {Object} options
* @return {String|String[]}
*/
getClass(name, options) {
const outOptions = {
color: true,
array: false
}
if (options) {
for (const i in options) {
outOptions[i] = options[i]
}
}
const { color, array } = outOptions
const icon = bestMatch(name)
const fallback = array ? ['icon', 'default-icon'] : 'icon default-icon'
return icon ? icon.getClass(color ? 0 : null, array) : fallback
}
}
module.exports = new FileIcons()