| 1 |
import { fas } from '@fortawesome/free-solid-svg-icons'; |
| 2 |
import { far } from '@fortawesome/free-regular-svg-icons'; |
| 3 |
import { fab } from '@fortawesome/free-brands-svg-icons'; |
| 4 |
|
| 5 |
/** |
| 6 |
* @param {object} icon FontAwesome icon to convert |
| 7 |
*/ |
| 8 |
function convertIcon(icon) { |
| 9 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 10 |
const [width, height, ligatures, unicode, svgPathData] = icon.icon; |
| 11 |
|
| 12 |
return { |
| 13 |
xOffset: 0, |
| 14 |
yOffset: 0, |
| 15 |
width, |
| 16 |
height, |
| 17 |
svgPathData |
| 18 |
}; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* @param {object} icon FontAwesome icon to name |
| 23 |
* @returns {string} PatternFly name of the icon |
| 24 |
*/ |
| 25 |
function getIconName(icon) { |
| 26 |
if (icon.iconName === '500px') { |
| 27 |
return 'five-hundred-px'; |
| 28 |
} |
| 29 |
if (icon.prefix === 'far') { |
| 30 |
return `outlined-${icon.iconName}`; |
| 31 |
} |
| 32 |
|
| 33 |
return icon.iconName; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* @param {object} icons Icons like { faIconName: { faIconDef } } |
| 38 |
*/ |
| 39 |
function convertIcons(icons) { |
| 40 |
delete icons.faFontAwesomeLogoFull; |
| 41 |
|
| 42 |
return Object.values(icons) |
| 43 |
.map((icon) => ({ |
| 44 |
name: getIconName(icon), |
| 45 |
data: convertIcon(icon) |
| 46 |
})) |
| 47 |
.reduce((acc, cur) => { |
| 48 |
acc[cur.name] = cur.data; |
| 49 |
return acc; |
| 50 |
}, {}); |
| 51 |
} |
| 52 |
|
| 53 |
const faIcons = { |
| 54 |
...convertIcons(fas), |
| 55 |
...convertIcons(fab), |
| 56 |
...convertIcons(far) |
| 57 |
}; |
| 58 |
|
| 59 |
export default faIcons; |