[![NPM version](]( [![Build Status](]( [![Coverage Status](https://c

Usage no npm install needed!

<script type="module">
  import svgfilter from '';



NPM version Build Status Coverage Status Dependency Status

A readable/writable stream that manipulates SVG files. The primary use case is removing elements whose id attribute isn't on a whitelist. This is useful as a preprocessor to inkscape that only supports a single --export-id=... argument.


var SvgFilter = require('svgfilter'),
  fs = require('fs');

  .pipe(new SvgFilter({ keepId: ['foo', 'bar'] }))

As an experimental feature you can run inline JavaScript found in the SVG file itself by specifying the runScripts option. The JavaScript can manipulate the SVG DOM however it wants through the document global. The script also has access to the globals console, window, and svgFilter. The latter is the options object passed to the SvgFilter constructor, so it's possible to carry out specific instructions, eg. change the color of an icon.

Given blackCircle.svg:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="" height="48px" width="48px">
    <circle id="theCircle" cx="100" cy="50" r="40" stroke="black" />
        document.getElementById('theCircle').setAttribute('stroke', svgFilter.circleColor);
var SvgFilter = require('svgfilter'),
  fs = require('fs');

  .pipe(new SvgFilter({ runScript: true, circleColor: 'maroon' }))

This will produce an SVG file where the stroke attribute of the circle element has been changed to maroon. The runScript option can also specify the id of the script to run, or an array of ids.




3-clause BSD license -- see the LICENSE file for details.