如何获得真棒字体图标 5 的 unicode?

how to get unicode for font awesome icon 5?

我使用 font awesomeson 图标选择器插件来 select 图标,但我想要带有此图标的 unicode。

使用的插件:

https://itsjavi.com/fontawesome-iconpicker/

你知道通过图标名称获取 unicode 吗?从插件 iconpicker 我会得到图标名称,但我想要 unicode 而不是名称

我该怎么做?

您可以从 FontAwesome 的 public 仓库下载并解析 icons.json 文件。然后,将其上传到您的应用程序中,并创建一个实用程序来搜索所选图标的 unicode。

我在这个回答中包含了一个简短的例子,说明如何让它发挥作用。

function getIconUnicode(iconName) {
  const fontAwesomeSource = {
    "500px": { "unicode": "f26e" },
    "accessible-icon": { "unicode": "f368" }
    ...
  };

  // if iconName is in the format of "fas fa-address-book"
  // it should be parsed in order to reflect the name present in the JSON

  const selectedIcon = iconName.split(' ')[1].split('-').splice(1).join('-');

  const unicodeValue = fontAwesomeSource[selectedIcon].unicode;

  return unicodeValue;
}

// example taken from the GitHub repo of the plugin
$('.my').on('iconpickerSelected', function(event){
  console.log(getIconUnicode(event.iconpickerValue));
});