Small function to check if a font is available to use on a web page. No external libraries required, just plain JS.
How it works
It works by first calculating the widths of the generic font families monospace, serif and sans-serif for the letters wi repeated 99 times. w because it's a wide and i because it should have a different width in monospaced and proportional fonts.
To check if a font is available, the CSS font-family of the test node is set to the font with either monospace, serif or sans-serif set as the fallback. The widths are then compared to the pre-calculated widths of the fallback and if the widths don't match, it means the fallback wasn't used and the font is available. If the widths match, another fallback is used until all 3 fallbacks have been attempted.