-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
43 lines (33 loc) · 911 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
35
36
37
38
39
40
41
42
43
'use strict'
var icons = require('./icons.json')
var idRegEx = /^(.*)\.png$/
var widths = icons.map(function (icon) {
return icon.width
})
var ids = icons.map(function (icon) {
return icon.name.match(idRegEx)[1]
})
function getIconForSize (size) {
var width = getWidthForSize(size)
if (!width) {
return null
}
return icons[widths.indexOf(width)] || null
}
function getWidthForSize (size) {
if (typeof size === 'number') return size
var width = Number(size)
if (!isNaN(width)) return width
width = widths[ids.indexOf(size)]
if (width) return width
return widths[ids.indexOf(size.match(idRegEx)[1])]
}
module.exports = function (options) {
options = options || {}
var size = options.size
if (!size) return icons
return getIconForSize(size)
}
module.exports.icons = icons
module.exports.getIconForSize = getIconForSize
module.exports.getWidthForSize = getWidthForSize