Updates the documentation to clarify explicitly that the plugin impacts whitespace. Internally, it's because we parse all numbers in the attribute into an array, then rewrite it back.
Bug Fix
I also fix a bug that I discovered while testing the issue reported. When an attribute like " 0 0 150 100 " comes up, SVGO inserts a 0 to the start and end of the attribute, completely changing the meaning.
This was because when we do the split, the array we get back starts with an empty string and ends with an empty string, which were then converted to 0, resulting in "0 0 0 150 100 0" instead of "0 0 150 100".
seth@seth-pc-tux:~$ node
Welcome to Node.js v20.11.0.
Type ".help" for more information.
> Number("")
0
Now we filter them out before parsing.
Performance
Just applying a recommendation from SonarLint, use RegExp#exec instead of String#match.
Docs
Updates the documentation to clarify explicitly that the plugin impacts whitespace. Internally, it's because we parse all numbers in the attribute into an array, then rewrite it back.
Bug Fix
I also fix a bug that I discovered while testing the issue reported. When an attribute like
" 0 0 150 100 "
comes up, SVGO inserts a0
to the start and end of the attribute, completely changing the meaning.This was because when we do the split, the array we get back starts with an empty string and ends with an empty string, which were then converted to
0
, resulting in"0 0 0 150 100 0"
instead of"0 0 150 100"
.Now we filter them out before parsing.
Performance
Just applying a recommendation from SonarLint, use
RegExp#exec
instead ofString#match
.Related