mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
fix: don't insert 0 at start or end of attribute if whitespace (#2036)
This commit is contained in:
@ -18,4 +18,4 @@ svgo:
|
|||||||
default: true
|
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.
|
||||||
|
@ -39,6 +39,7 @@ export const fn = (_root, params) => {
|
|||||||
if (node.attributes.viewBox != null) {
|
if (node.attributes.viewBox != null) {
|
||||||
const nums = node.attributes.viewBox.split(/\s,?\s*|,\s*/g);
|
const nums = node.attributes.viewBox.split(/\s,?\s*|,\s*/g);
|
||||||
node.attributes.viewBox = nums
|
node.attributes.viewBox = nums
|
||||||
|
.filter((value) => value.length != 0)
|
||||||
.map((value) => {
|
.map((value) => {
|
||||||
const num = Number(value);
|
const num = Number(value);
|
||||||
return Number.isNaN(num)
|
return Number.isNaN(num)
|
||||||
@ -54,7 +55,7 @@ export const fn = (_root, params) => {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const match = value.match(regNumericValues);
|
const match = regNumericValues.exec(value);
|
||||||
|
|
||||||
// if attribute value matches regNumericValues
|
// if attribute value matches regNumericValues
|
||||||
if (match) {
|
if (match) {
|
||||||
|
5
test/plugins/cleanupNumericValues.03.svg.txt
Normal file
5
test/plugins/cleanupNumericValues.03.svg.txt
Normal file
@ -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"/>
|
After Width: | Height: | Size: 141 B |
Reference in New Issue
Block a user