-
Notifications
You must be signed in to change notification settings - Fork 0
/
font-awesome-mustache.js
48 lines (40 loc) · 1.24 KB
/
font-awesome-mustache.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
const fontAwesomeSVGReducer = (acc, icon) => {
if (icon.icon) {
// eslint-disable-next-line no-unused-vars
const [width, height, _ligatures, _unicode, svgPathData] = icon.icon;
acc[icon.iconName] = {
viewBox: `0 0 ${width} ${height}`,
path: svgPathData,
toString: () => svgPathData,
};
}
return acc;
};
const renderFontAwesome = (fontAwesomeModule) => {
const blockFunction = function () {
return function (text, render) {
const iconName = render(text).trim();
const icon = blockFunction[iconName];
if (!icon) {
throw new Error(`icon not found: ${iconName}`);
}
return render(
`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="${icon.viewBox}">` +
`<path fill="currentColor" d="${icon.path}"></path>` +
`</svg>`
);
};
};
return Object.values(fontAwesomeModule).reduce(
fontAwesomeSVGReducer,
blockFunction
);
};
const fab = renderFontAwesome(
require("@fortawesome/free-brands-svg-icons").fab
);
const far = renderFontAwesome(
require("@fortawesome/free-regular-svg-icons").far
);
const fas = renderFontAwesome(require("@fortawesome/free-solid-svg-icons").fas);
module.exports = { fas, far, fab };