1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

Replace attributes iterators with for/of (#1431)

These iterators allows to directly manipulate passed value
which does not let us to get rid from legacy "attrs" field.

Object.entries makes it easier to get an access to both attribute
name and value.
This commit is contained in:
Bogdan Chadkin
2021-03-17 12:50:16 +03:00
committed by GitHub
parent 45d2b68a32
commit 8098ab7fb6
16 changed files with 192 additions and 208 deletions

View File

@ -49,13 +49,13 @@ exports.fn = function (item, params) {
.join(' ');
}
item.eachAttr(function (attr) {
for (const [name, value] of Object.entries(item.attributes)) {
// The `version` attribute is a text string and cannot be rounded
if (attr.name === 'version') {
return;
if (name === 'version') {
continue;
}
var match = attr.value.match(regNumericValues);
var match = value.match(regNumericValues);
// if attribute value matches regNumericValues
if (match) {
@ -85,8 +85,8 @@ exports.fn = function (item, params) {
units = '';
}
attr.value = num + units;
item.attributes[name] = num + units;
}
});
}
}
};