Skip to content

Instantly share code, notes, and snippets.

@alexstrat
Created December 17, 2019 09:49
Show Gist options
  • Save alexstrat/d5ce0a2f23e4f549ca65f3bc47483b0f to your computer and use it in GitHub Desktop.
Save alexstrat/d5ce0a2f23e4f549ca65f3bc47483b0f to your computer and use it in GitHub Desktop.
import { readFileSync, writeFileSync } from 'fs';
import { load } from 'cheerio';
import { html as beautify } from 'js-beautify';
const content = readFileSync('./static/Icons.svg', 'utf8');
const $ = load(content);
$('svg').find('symbol').each((i, symbol) => {
const id = $(symbol).attr('id')!.split('--')[1];
symbol.tagName = 'svg';
$(symbol).removeAttr('id');
writeFileSync(`./resources/icons/${id}.svg`, beautify($.html(symbol), {
indent_size: 2,
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment