Skip to content

Commit

Permalink
fix: don't insert 0 at start or end of attribute if whitespace (#2036)
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco authored Jun 14, 2024
1 parent e73d13a commit 5481fc2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/03-plugins/cleanupNumericValues.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ svgo:
default: true
---

Rounds numeric values, and removes the unit when it's `px` as this is the default.
Rounds numeric values, removes the unit when it's `px` as this is the default, and removes redundant spaces around and between numbers.
3 changes: 2 additions & 1 deletion plugins/cleanupNumericValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const fn = (_root, params) => {
if (node.attributes.viewBox != null) {
const nums = node.attributes.viewBox.split(/\s,?\s*|,\s*/g);
node.attributes.viewBox = nums
.filter((value) => value.length != 0)
.map((value) => {
const num = Number(value);
return Number.isNaN(num)
Expand All @@ -54,7 +55,7 @@ export const fn = (_root, params) => {
continue;
}

const match = value.match(regNumericValues);
const match = regNumericValues.exec(value);

// if attribute value matches regNumericValues
if (match) {
Expand Down
5 changes: 5 additions & 0 deletions test/plugins/cleanupNumericValues.03.svg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox=" 0 0 150 100 "/>

@@@

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 100"/>

0 comments on commit 5481fc2

Please sign in to comment.