import svgpath from 'svgpath' import svgParse from 'parse-svg-path' import glob from 'glob' import fs from 'fs' import { basename } from 'path' const addFloats = (n1, n2) => { return Math.round((parseFloat(n1) + parseFloat(n2)) * 1000) / 1000 } const optimizePath = (path) => { let transformed = svgpath(path) .rel() .round(3) .toString() return svgParse(transformed).map(function (a) { return a.join(' ') }).join(' ') } const optimizeIcons = (path) => { glob(path, {}, function(er, files) { files.forEach(function(file) { let svgFile = fs.readFileSync(file), svgFileContent = svgFile.toString() svgFileContent = svgFileContent.replace(/><\/(polyline|line|rect|circle|path)>/g, '/>'). replace(/rx="([^"]+)"\s+ry="\1"/g, 'rx="$1"'). replace(/\s?\/>/g, ' />'). replace(/\n\s*<(line|circle|path|polyline|rect)/g, "\n <$1"). replace(/polyline points="([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s([0-9.]+)"/g, 'line x1="$1" y1="$2" x2="$3" y2="$4"'). replace(/