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

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

3
4
5
6
7
8
9
10
11
12
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

516
517
518
519
520
521
522
523
524
525
526
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

542
543
544
545
546
547
548
549
550
551
552
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);
    }
}



fork icon2
star icon10
watch icon0

174
175
176
177
178
179
180
181
182
183
var iconDefinition = {
  prefix: iconOptions.prefix,
  iconName: iconOptions.icon
};
var transform = angular.isString(_this.transform) ? fontawesomeSvgCore.parse.transform(_this.transform) : {};
var mask = angular.isString(_this.mask) ? fontawesomeSvgCore.icon(maskToIcon(_this.mask)) : null;
var params = {
  classes: classList(iconOptions),
  transform: transform,
  mask: mask,
fork icon0
star icon4
watch icon0

123
124
125
126
127
128
129
130
131
132
  pluginRss.convertHtmlToAbsoluteUrls
);

// Font Awesome single icon shortcode
eleventyConfig.addAsyncShortcode("fontawesome_icon", (prefix, iconName) => {
  const icon = fontawesome.icon({ prefix, iconName });
  return icon.html[0];
});

// Font Awesome filter for generating a sprite sheet
fork icon0
star icon2
watch icon1

+ 143 other calls in file

794
795
796
797
798
799
800
801
802
803
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}`);
    throw (error);
  }
fork icon0
star icon2
watch icon0

80
81
82
83
84
85
86
87
88
89
90
91
    'everything': './dist/docs/**',
    'info': './dist/docs/info.json'
}


/*function faSvg(icon, prefix, option){
    return fontawesome.icon({ prefix: ( prefix || "fas" ), iconName: icon },option).html[0]
}*/


/*
function escape_html(val) {
fork icon8
star icon1
watch icon1

51
52
53
54
55
56
57
58
59
60
function get_icon(job) {
    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]
            )
fork icon0
star icon1
watch icon0

+ 3 other calls in file

241
242
243
244
245
246
247
248
249
250
Array.from(faIcons).forEach(function(key) {
  const prefix = key.substring(0, 3);   // `fas`, `far`, `fab`
  const name = key.substring(4);
  const def = fontawesome.findIconDefinition({ prefix: prefix, iconName: name });
  try {
    fs.writeFileSync(`svg/fontawesome/${key}.svg`, fontawesome.icon(def).html.toString());
  } catch (error) {
    console.error(`Error: No FontAwesome icon for ${key}`);
    throw (error);
  }
fork icon0
star icon0
watch icon0

75
76
77
78
79
80
81
82
83
84
function getIcon(role) {
    switch (role) {
        case "Manager":
            return icon({ previx: 'fas', iconName: 'mug-hot' }).html
        case "Intern":
            return icon({ previx: 'fas', iconName: 'graduation-cap' }).html
        case "Engineer":
            return icon({ previx: 'fas', iconName: 'glasses' }).html
    }
}
fork icon0
star icon0
watch icon1

+ 11 other calls in file