Remove attributes and styles from SVGs
npm install remove-svg-properties
> Remove attributes and styles from SVGs
Install with npm
```
npm install remove-svg-properties --save
`javascript`
var rsp = require(‘remove-svg-properties’);
rsp.remove(options);
Values below are defaults
- src: Glob string with path to source SVGs
- out: Output directory for colorless SVGs
- stylesheets: true Set to false if you don't want to remove the <style> tagstrue
- attributes: Set to false if you don't want to remove attributestrue
- inline: Set to false if you don't want to remove inline style properties[]
- properties: Array of properties to be removed. See Properties section below for more information.[]
- namespaces: Array of namespace names to be removed.false
- stylesToInline: When set to true, <style> contents will be added as inline styles, which avoids stylesheet collisions when adding multiple inline SVGs to an HTML document.true
- log: When set to false, console logging is disabled.
#### Properties
Using the properties option you can specify a list of attributes and CSS-properties which will be removed.PROPS_FILL
Also, the plugin defines a few common, ready-to-use property-sets:
- PROPS_STROKE
- fill
- fill-opacity
- fill-rule
- PROPS_FONT
- stroke
- stroke-dasharray
- stroke-dashoffset
- stroke-linecap
- stroke-linejoin
- stroke-miterlimit
- stroke-opacity
- stroke-width
-
- font-family
- font-size
- font-size-adjust
- font-stretch
- font-style
- font-variant
- font-weight
So, an example configuration could be: [rsp.PROPS_FILL, 'class']
This would remove all the properties listed in PROPS_FILL above and all the class attributes.
#### Namespaces
SVG elements can have namespaced attributes, usually added by SVG editing software like Adobe Illustrator.
If you configure the namespaces property to be something like ['i', 'sketch'], the plugini:something
would remove every and sketch:something property.
A would be converted to only.
Usage with an example configuration object:
`javascript`
rsp.remove({
src: './src/*.svg',
out: './dest',
stylesheets: false,
properties: [rsp.PROPS_STROKE, rsp.PROPS_FILL, 'color'],
namespaces: ['i', 'sketch', 'inkscape']
});
This would take all the SVG files from ./src and put them into ./dest while removing all the stroke and fill related properties as well as the color property. Those properties are only removed from attributes and inline styles, not from