UNPKG

iconit

Version:

A CLI to help you build icon libraries (JSON & Sprites) with ease.

25 lines (21 loc) 621 B
import path from 'path'; import cheerio from 'cheerio'; import { minify } from 'html-minifier'; function buildIconsObject(svgFiles, getSvg) { return svgFiles .map(svgFile => { const name = path.basename(svgFile, '.svg'); const svg = getSvg(svgFile); const contents = getSvgContents(svg); return { name, contents }; }) .reduce((icons, icon) => { icons[icon.name] = icon.contents; return icons; }, {}); } function getSvgContents(svg) { const $ = cheerio.load(svg); return minify($('svg').html(), { collapseWhitespace: true }); } export default buildIconsObject;