How do I retrieve a Fontello icon's code programatically

351 Views Asked by At

In the fontello.css file, I can see the code of an icon, such as:

.icon-user:before { content: '\e811'; }

It's the e811 part that I need to retrieve, to embed the icon inside an SVG chart.

I'd like to be able to retrieve the code of all my icons programmatically. There is a config.json file but this "e811" code is not in it. Here is what is given for that same icon:

{
  "uid": "8b80d36d4ef43889db10bc1f0dc9a862",
  "css": "user",
  "code": 59409,
  "src": "fontawesome"
}

How do I retrieve the 4-letter code of icons programmatically? Thanks

1

There are 1 best solutions below

0
Louis Ameline On BEST ANSWER

I figured it, the code in the config.json file is a decimal version of the code in the css file. You need to convert it with code.toString(16)

For example (59409).toString(16) == 'e811'.
Which can also be written 59409..toString(16) == 'e811' by the way.

Side note

Actually the manual conversion of the code is not even necessary, this native javascript function does it for us: String.fromCharCode(code)