How to use the findIconDefinition function from @fortawesome/fontawesome-svg-core

Find comprehensive JavaScript @fortawesome/fontawesome-svg-core.findIconDefinition code examples handpicked from public code repositorys.

1
2
3
4
5
6
7
8
9
10
const {fas} = require('@fortawesome/free-solid-svg-icons');

library.add(fas);

function drawFontAwesomeIcon(node, ctx, iconName, x, y, size, color = "white", prefix = "far") {
    let def = findIconDefinition({prefix: prefix, iconName: iconName});
    if (!def) return;
    let icn = icon(def, {
        transform: {
            // can't use scale here, as that apparently only affects CSS not the actual path data
fork icon6
star icon81
watch icon6

+ 13 other calls in file

515
516
517
518
519
520
521
522
523
524
525


function writeFaIcons(faIcons) {
    for (var key in faIcons) {
        var prefix = key.substring(0, 3);   // `fas`, `far`, `fab`
        var name = key.substring(4);
        var def = fontawesome.findIconDefinition({ prefix: prefix, iconName: name });
        writeFileProm('svg/fontawesome/' + key + '.svg', fontawesome.icon(def).html.toString());
    }
}

fork icon7
star icon28
watch icon0

153
154
155
156
157
158
159
160
161
this.$postLink = function () {
  _this.renderIcon();
};

this.renderIcon = function () {
  var found = fontawesomeSvgCore.findIconDefinition({
    iconName: _this.icon,
    prefix: _this.prefix
  });
fork icon0
star icon4
watch icon0

26
27
28
29
30
31
32
33
34
35
if (label.startsWith("far:") || label.startsWith("fas:") || label.startsWith("fab:")) {
    let split = label.split(":");
    let prefix = split[0];
    let iconName = split[1];

    let def = faCore.findIconDefinition({prefix: prefix, iconName: iconName});
    if (!def) {
        res.status(400).send("Unknown icon " + prefix + ":" + iconName);
        reject();
        return;
fork icon0
star icon3
watch icon0

792
793
794
795
796
797
798
799
800
801
802


function writeFaIcons(faIcons) {
  for (const key in faIcons) {
    const prefix = key.substring(0, 3);   // `fas`, `far`, `fab`
    const name = key.substring(4);
    const def = fontawesome.findIconDefinition({ prefix: prefix, iconName: name });
    try {
      writeFileProm(`svg/fontawesome/${key}.svg`, fontawesome.icon(def).html);
    } catch (error) {
      console.error(`Error: No FontAwesome icon for ${key}`);
fork icon0
star icon2
watch icon0

52
53
54
55
56
57
58
59
60
61
return `data:image/svg+xml;base64,${
    Buffer.from(
        SVG(
            getFontLogoIcon(job['icon'] || icon_resolver(job.job)) ||
            icon(
                findIconDefinition({iconName: job['icon'] || icon_resolver(job.job), prefix: 'fab'}) ||
                findIconDefinition({iconName: 'linux', prefix: 'fab'})
            ).html[0]
        )
        .each((_i, child) => {
fork icon0
star icon1
watch icon1

+ 7 other calls in file

-2
-1
const faCoffee = fontawesome.findIconDefinition({prefix: 'fas', iconName: 'coffee'})
console.log(`coffee unicode: ${faCoffee.icon[3]}`)
fork icon0
star icon1
watch icon0