We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I've written a small CLI slimmer. As you can see, I'm not an advanced JS-coder, but perhaps it helps others.
node svgSlim.js pictogramm.svg > new.svg <othertool> | node svgSlim.js > new.svg <othertool> | node svgSlim.js /dev/stdin > new.svg <othertool> | node svgSlim.js - > new.svg cat pictogramm.svg | node svgSlim.js > new.svg < pictogramm.svg node svgSlim.js > new.svg
'use strict'; function MergeRecursive(obj1, obj2) { // based on https://stackoverflow.com/a/383245 - (c) users Markus etc. under CC BY-SA 3.0 for (let p in obj2) { try { // property in destination object set; update its value if (obj2[p].constructor == Object) { obj1[p] = MergeRecursive(obj1[p], obj2[p]); } else { obj1[p] = obj2[p]; } } catch(e) { // property in destination object not set; create it and set its value obj1[p] = obj2[p]; } } return obj1; } const defaultConfig = { "rules": { "collapse-g": true, "collapse-textwrap": true, "combine-path": [ false, { "disregardFill": false, "disregardOpacity": false } ], "combine-transform": true, "compute-path": true, "rm-attribute": [ true, { "keepAria": false, "keepEvent": false } ], "rm-comments": true, "rm-doctype": true, "rm-hidden": true, "rm-irregular-nesting": [ true, { "ignore": [] } ], "rm-irregular-tag": [ true, { "ignore": [] } ], "rm-px": true, "rm-unnecessary": [ true, { "tags": [ "desc", "discard", "foreignObject", "video", "audio", "iframe", "canvas", "metadata", "script", "title", "unknown", "image" ] } ], "rm-version": true, "rm-viewbox": true, "rm-xml-decl": true, "rm-xmlns": true, "shorten-animate": [ true, { "remove": false } ], "shorten-class": true, "shorten-color": [ true, { "rrggbbaa": false } ], "shorten-decimal-digits": true, "shorten-defs": true, "shorten-filter": true, "shorten-id": true, "shorten-shape": true, "shorten-style-attr": true, "shorten-style-tag": [ true, { "deepShorten": true } ], }, "params": { "sizeDigit": 2, "angelDigit": 2, "trifuncDigit": 3, "opacityDigit": 3, "thinning": 0, "straighten": 0, "mergePoint": 0, "exchangeStyle": false, "rmAttrEqDefault": true }, "browsers": ["defaults"] }; const userConfig = { "params": { "sizeDigit": 5, "angelDigit": 5, "trifuncDigit": 5 } }; const fs = require('fs'); const svgSlimming = require('svg-slim'); const fileOrStdin = require('file-or-stdin'); const args = process.argv.slice(2); async function main() { const svgFN = (args[0] === '-') ? '/dev/stdin' : args[0]; try { const svgcode = await fileOrStdin(svgFN, 'utf8'); try { const config = MergeRecursive(defaultConfig, userConfig); const result = await svgSlimming(svgcode, config) console.log(result); } catch(e) { console.error('Error while slimming. ' + e); } } catch(e) { console.error('File not found. ' + e); } return; } main();
The text was updated successfully, but these errors were encountered:
No branches or pull requests
summary
I've written a small CLI slimmer. As you can see, I'm not an advanced JS-coder, but perhaps it helps others.
usage
code
The text was updated successfully, but these errors were encountered: