Skip to content

Instantly share code, notes, and snippets.

@manbearwiz
Last active November 9, 2023 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manbearwiz/d0a0dedb7d35b6c94546b76b47338d7b to your computer and use it in GitHub Desktop.
Save manbearwiz/d0a0dedb7d35b6c94546b76b47338d7b to your computer and use it in GitHub Desktop.
Parse a font svg, extract the escaped unicode characters, and output a map of the glyph name to its corresponding code. `cat icon-font.svg | node parseCodepoints > icon-font.codepoints`
const { WritableStream } = require('htmlparser2/lib/WritableStream');
const escape = (_, s) => s.codePointAt().toString(16);
const parserStream = new WritableStream({
onopentag(name, { unicode, 'glyph-name': glyphName }) {
if (name === 'glyph' && glyphName && unicode) {
process.stdout.write(`${glyphName} ${escape`${unicode}`}\n`);
}
},
});
process.stdin.pipe(parserStream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment