mirror of
https://github.com/svg/svgo.git
synced 2025-08-06 04:22:39 +03:00
fix(plugin): removeAttrs: warn without attrs (#1582)
This commit is contained in:
@@ -6,6 +6,19 @@ exports.active = false;
|
|||||||
exports.description = 'removes specified attributes';
|
exports.description = 'removes specified attributes';
|
||||||
|
|
||||||
const DEFAULT_SEPARATOR = ':';
|
const DEFAULT_SEPARATOR = ':';
|
||||||
|
const ENOATTRS = `Warning: The plugin "removeAttrs" requires the "attrs" parameter.
|
||||||
|
It should have a pattern to remove, otherwise the plugin is a noop.
|
||||||
|
Config example:
|
||||||
|
|
||||||
|
plugins: [
|
||||||
|
{
|
||||||
|
name: "removeAttrs",
|
||||||
|
params: {
|
||||||
|
attrs: "(fill|stroke)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove attributes
|
* Remove attributes
|
||||||
@@ -77,7 +90,11 @@ const DEFAULT_SEPARATOR = ':';
|
|||||||
* }>}
|
* }>}
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
// wrap into an array if params is not
|
if (typeof params.attrs == 'undefined') {
|
||||||
|
console.warn(ENOATTRS);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const elemSeparator =
|
const elemSeparator =
|
||||||
typeof params.elemSeparator == 'string'
|
typeof params.elemSeparator == 'string'
|
||||||
? params.elemSeparator
|
? params.elemSeparator
|
||||||
|
21
test/plugins/removeAttrs.06.svg
Normal file
21
test/plugins/removeAttrs.06.svg
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<circle fill="red" stroke-width="6" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
|
||||||
|
<circle fill="red" stroke="#000" stroke-width="6" stroke-dashoffset="5" stroke-opacity="0" cx="60" cy="60" r="50"/>
|
||||||
|
<circle stroke="#000" stroke-width="6" stroke-dashoffset="5" stroke-opacity="0" cx="60" cy="60" r="50"/>
|
||||||
|
<circle stroke="#FFF" stroke-width="6" stroke-dashoffset="5" stroke-opacity="0" cx="60" cy="60" r="25"/>
|
||||||
|
<path fill="red" stroke="red" d="M100,200 300,400 H100 V300 C100,100 250,100 250,200 S400,300 400,200 Q400,50 600,300 T1000,300 z"/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
@@@
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<circle fill="red" stroke-width="6" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
|
||||||
|
<circle fill="red" stroke="#000" stroke-width="6" stroke-dashoffset="5" stroke-opacity="0" cx="60" cy="60" r="50"/>
|
||||||
|
<circle stroke="#000" stroke-width="6" stroke-dashoffset="5" stroke-opacity="0" cx="60" cy="60" r="50"/>
|
||||||
|
<circle stroke="#FFF" stroke-width="6" stroke-dashoffset="5" stroke-opacity="0" cx="60" cy="60" r="25"/>
|
||||||
|
<path fill="red" stroke="red" d="M100,200 300,400 H100 V300 C100,100 250,100 250,200 S400,300 400,200 Q400,50 600,300 T1000,300 z"/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
@@@
|
||||||
|
|
||||||
|
{}
|
After Width: | Height: | Size: 1.2 KiB |
Reference in New Issue
Block a user