Skip to content

Commit fef75c1

Browse files
iankit3hudochenkov
authored andcommitted
Add removeStroke option (TrySound#56)
1 parent 004ac18 commit fef75c1

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ Default: `false` - path will be relative to source file if it was specified.
6262
Default: `false` - with `true` removes all `fill` attributes before applying specified.
6363
Passed RegExp filters files by ID.
6464

65+
#### options.removeStroke
66+
67+
Default: `false` - with `true` removes all `stroke` attributes before applying specified.
68+
Passed RegExp filters files by ID.
69+
70+
6571
#### options.encode(svg)
6672

6773
Processes SVG after applying parameters. Default will be ommited if passed `false`.

lib/load.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const render = require("./render.js");
33
const { transform, encode, addXmlns } = require("./defaults.js");
44
const {
55
removeFill,
6+
removeStroke,
67
applyRootParams,
78
applySelectedParams
89
} = require("./processors.js");
@@ -22,6 +23,7 @@ function read(id) {
2223
module.exports = function load(id, params, selectors, opts) {
2324
const processors = [
2425
removeFill(id, opts),
26+
removeStroke(id,opts),
2527
applyRootParams(params),
2628
applySelectedParams(selectors)
2729
];

lib/processors.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ function removeFill(id, opts) {
1616
};
1717
}
1818

19+
function removeStrokeAttrib(element) {
20+
delete element.attribs.stroke;
21+
}
22+
23+
function removeStroke(id, opts) {
24+
return dom => {
25+
if (matchId(opts.removeStroke, id)) {
26+
selectAll("[stroke]", dom).forEach(removeStrokeAttrib);
27+
}
28+
};
29+
}
30+
1931
function applyParams(params) {
2032
return ({ attribs }) => {
2133
Object.keys(params).forEach(name => {
@@ -42,6 +54,7 @@ function applySelectedParams(selectors) {
4254

4355
module.exports = {
4456
removeFill,
57+
removeStroke,
4558
applyRootParams,
4659
applySelectedParams
4760
};

test/fixtures/stroke-icon.svg

Lines changed: 3 additions & 0 deletions
Loading

test/fixtures/stroke.svg

Lines changed: 3 additions & 0 deletions
Loading

test/options.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,33 @@ test("should remove fill attributes with removeFill: RegExp", () => {
195195
}
196196
);
197197
});
198+
199+
test("should remove stroke attributes with removeStroke: true", () => {
200+
return compare(
201+
`background: svg-load('fixtures/stroke.svg', stroke="#fff");`,
202+
`background: url("data:image/svg+xml;charset=utf-8,<svg xmlns=\'http://www.w3.org/2000/svg\' stroke='#fff'> <path/> </svg>");`,
203+
{
204+
from: "input.css",
205+
removeStroke: true,
206+
encode: false
207+
}
208+
);
209+
});
210+
211+
test("should remove stroke attributes with removeStroke: RegExp", () => {
212+
return compare(
213+
`
214+
background: svg-load('fixtures/stroke.svg', stroke="#fff");
215+
background: svg-load('fixtures/stroke-icon.svg', stroke="#fff");
216+
`,
217+
`
218+
background: url("data:image/svg+xml;charset=utf-8,<svg xmlns=\'http://www.w3.org/2000/svg\' stroke='#fff'> <path stroke='#000'/> </svg>");
219+
background: url("data:image/svg+xml;charset=utf-8,<svg xmlns=\'http://www.w3.org/2000/svg\' stroke='#fff'> <rect/> </svg>");
220+
`,
221+
{
222+
from: "input.css",
223+
removeStroke: /-icon/,
224+
encode: false
225+
}
226+
);
227+
});

0 commit comments

Comments
 (0)