https://github.com/caub/svgz
Experimental replacement for SVGO
https://github.com/caub/svgz
jsdom svgo
Last synced: 12 months ago
JSON representation
Experimental replacement for SVGO
- Host: GitHub
- URL: https://github.com/caub/svgz
- Owner: caub
- Created: 2017-06-19T14:35:59.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-24T12:23:09.000Z (about 8 years ago)
- Last Synced: 2025-03-22T22:17:52.738Z (over 1 year ago)
- Topics: jsdom, svgo
- Language: JavaScript
- Homepage:
- Size: 46.9 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## SVG processor and minifier [](https://travis-ci.org/caub/svgz)
similar to [SVGO](https://github.com/svg/svgo) (most plugins are based from svgo)
```js
const svgz = require('svgz');
const fs = require('fs');
const svgBuf = fs.readFileSync('./test.svg');
// const result = svgz(svgBuf); // call it with default options
// const result = svgz(svgBuf, {indent:'\t', decimals:3}); // call it with different global options
// and with specific plugins options:
const result = svgz(svgBuf, {
indent: '\t',
decimals: 3,
plugins: {
addDefaultFonts: {families: ['sans-serif']},
removeMetadata: false // disable this one
}
});
fs.writeFileSync('./test.min.svg', result);
```
### Plugins
| name | description | active |
| --- | --- | :---: |
| removeMetadata | removes `` elements | :heavy_check_mark: |
| cleanupIds | removes unused id's attributes | :heavy_check_mark: |
| cleanupViewBox | moves the viewBox origin to 0 0 (and adjust transform on children) | |
| moveElemsAttrsToGroup | moves up attributes (except transform) to a group wrapper | :heavy_check_mark: |
| moveGroupAttrsToElems | moves some group attributes to the content elements | :heavy_check_mark: |
| collapseGroups | collapses/unwrap useless groups | :heavy_check_mark: |
| convertPathData | optimizes path data: writes in shorter form, applies transformations | :heavy_check_mark: |
| convertTransform | collapses multiple transformations and optimizes it | :heavy_check_mark: |
| cleanupNumericValues | rounds numeric values to the fixed precision, removes default ‘px’ units, and empty attributes | :heavy_check_mark: |
| addDefaultFonts | ensure fallbacks font-family, useful when using web-fonts | |
### Todos:
- improve jsdom's getComputedSyle to work with [presentational attributes](https://www.w3.org/TR/SVG2/styling.html#PresentationAttributes) (`