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

[plugin] sortAttrs: add xmlns order option (#984)

This commit is contained in:
dale tan
2018-06-15 04:28:59 -04:00
committed by Lev Solntsev
parent 0835859766
commit 54f92ce2de
2 changed files with 23 additions and 5 deletions

View File

@ -30,7 +30,8 @@ exports.fn = function(item, params) {
var attrs = [],
sorted = {},
orderlen = params.order.length + 1;
orderlen = params.order.length + 1,
xmlnsOrder = params.xmlnsOrder || 'front';
if (item.elem) {
@ -41,10 +42,12 @@ exports.fn = function(item, params) {
attrs.sort(function(a, b) {
if (a.prefix != b.prefix) {
// xmlns attributes implicitly have the prefix xmlns
if (a.prefix == 'xmlns')
return -1;
if (b.prefix == 'xmlns')
return 1;
if (xmlnsOrder == 'front') {
if (a.prefix == 'xmlns')
return -1;
if (b.prefix == 'xmlns')
return 1;
}
return a.prefix < b.prefix ? -1 : 1;
}