-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
34 lines (26 loc) · 832 Bytes
/
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
'use strict';
var path = require('path');
var extensions = require('./index.json');
var unknown = extensions[''];
function isString(value) {
return (typeof value === 'string') ||
(Object.prototype.toString.call(value) === '[object String]');
}
function getIcon(filename, type) {
// Extract extension from the filename
var ext = isString(filename) ? path.extname(filename).toLowerCase() : '';
// Validate type - it should be 'svg' or '.svg'
type = isString(type) ? type.toLowerCase() : '';
if (type.charAt(0) === '.') {
type = type.substr(1, type.length);
}
if (['svg'].indexOf(type) >= 0) {
type = '.' + type;
} else {
type = '';
}
return (extensions[ext] || unknown) + type;
}
module.exports.getIcon = getIcon;
module.exports.unknown = unknown;
module.exports.extensions = extensions;