post-iconfonts
v1.1.0
Published
Converts an icon font to an SVG image
Downloads
1
Readme
post-iconfonts
Converts an icon font to an SVG image
Online Version
npm install --save-dev post-iconfonts
TL;DR
Generate a SVG image with,
import postIconfonts from 'post-iconfonts';
const font = readFileSync('font-awesome.otf');
const css = readFileSync('font-awesome.css', 'utf-8');
const svgString = postIconfonts(css, font, { precision: 5 });
Then add icons with,
<svg width="12" height="12"><use xlink:href="/icons.svg#fa-check" /></svg>
API
postIconfonts(cssString, fontBuffer, options);
cssString
must be a string. fontBuffer
can be an ArrayBuffer or a standard node.js Buffer.
The options is an object that takes the following:
size
(number, default 12) The height to make each glyph (shouldn't really affect anything)width
(number, default=size) The width of each glyph—effectively defines the aspect ratiofilterNames
(array, optional) Export only these CSS class names from the icon fonttransformNames
(function, optional) Function must take a name and return a new name (can be used to removefa-prefixes
from icons)precision
(number, default 6) The number of decimal places for path data commands—decrease to lower the file size and qualitywarnOnOversized
(boolean, default false) when true, the return value will be{ svg, oversizedGlyphs }
, wheresvg
is a string, andoversizedGlyphs
is an array of glyphs that did not fit in the size/width boundary