Last active
November 9, 2023 18:02
-
-
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`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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