Skip to content

Commit

Permalink
fix(plugin): removeAttrs: warn without attrs (#1582)
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored Sep 23, 2021
1 parent 6e23b9c commit 8af10de
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
19 changes: 18 additions & 1 deletion plugins/removeAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ exports.active = false;
exports.description = 'removes specified attributes';

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
Expand Down Expand Up @@ -77,7 +90,11 @@ const DEFAULT_SEPARATOR = ':';
* }>}
*/
exports.fn = (root, params) => {
// wrap into an array if params is not
if (typeof params.attrs == 'undefined') {
console.warn(ENOATTRS);
return null;
}

const elemSeparator =
typeof params.elemSeparator == 'string'
? params.elemSeparator
Expand Down
21 changes: 21 additions & 0 deletions test/plugins/removeAttrs.06.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8af10de

Please sign in to comment.