I need list of all class name of Font-Awesome

前端 未结 18 3082
傲寒
傲寒 2020-12-12 13:44

I build app that will present a lot of icons so I need list of all Font-Awesome class name like [\"fa-dropbox\",\"fa-rocket\",\"fa-globe\", ....] so on is ther

18条回答
  •  没有蜡笔的小新
    2020-12-12 14:16

    Another little script for posterity.

    Update 02/2018 (version 5.x)

    Latest working version, based on edit from Blasius Secondus (thanks).

    Open the fonts cheat sheet and run the following snippet in the developper console: https://fontawesome.com/cheatsheet

    var names = new Set();
    var icons = document.getElementsByClassName('icon');
    for (const icon of icons) {
      const name = icon.getElementsByTagName('dd')[0].innerText;
      names.add(name);
    }
    console.log(JSON.stringify(Array.from(names)));
    

    If you want them sorted by section (solid/regular/brand):

    var groups = {};
    var sections = document.getElementsByClassName('cheatsheet-set');
    for (const section of sections) {
      const names = [];
      groups[section.id] = names;
      var icons = section.getElementsByClassName('icon');
      for (const icon of icons) {
        const name = icon.getElementsByTagName('dd')[0].innerText;
        names.push(name);
      }
    }
    console.log(groups); // Feel free to stringify/manipulate
    

    Original answer

    Simply open the latest cheatsheet: http://fortawesome.github.io/Font-Awesome/cheatsheet/

    Then in your browser, open the developer console and run:

    var names = [];
    $('.row .col-md-4').each(function() {
      var s = $(this).text();
      var m = s.match(/fa-.*/);
      if (m && m[0] && s.indexOf('(alias)') < 0) {
        names.push(m[0]);
      }
    });
    console.log( JSON.stringify( names ) );
    

    If you want the list instead of an array, replace the last line by

    console.log( names.join(' ') );
    

    (You can use any separator you want instead of space ' ')

    The advantage of this method is that you will only get the visual icons (not the fa-spin and friends), and not the duplicate aliases.

提交回复
热议问题