Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

posthtml-vscode-sorting-attrs-logic

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml-vscode-sorting-attrs-logic - npm Package Compare versions

Comparing version 1.0.1 to 1.0.5

96

index.js
module.exports = function(opts) {
// Added Angular after data. See https://github.com/mdo/code-guide/issues/106
var orderList = (opts && opts.order) || [
"class",
"id",
"name",
"data-.+",
".ng-.+",
".ng.+",
"src",
"for",
"type",
"href",
"values",
"title",
"alt",
"role",
"aria-.+",
"$unknown$",
]
/** Following :
* https://codeguide.co/#html-lang
* https://stackoverflow.com/a/51389977/11135174
* Added Angular after data. See https://github.com/mdo/code-guide/issues/106
*/
const orderList = options.order || [
'id', 'class', 'name',
'data-.+', 'ng-.+', '[.+', '(.+', '*ng+',
'src', 'for', 'type', 'href', 'value',
'title', 'alt',
'role', 'aria-.+',
'$unknown$'
];
// A RegExp's for filtering and sorting
var orderListFilterRegExp = new RegExp("^(" + orderList.join("|") + ")$")
var orderListFilterRegExp = new RegExp("^(" + orderList.join("|") + ")$");
var orderListRegExp = orderList.map(function(item) {
return new RegExp("^" + item + "$")
})
return new RegExp("^" + item + "$");
});

@@ -31,19 +25,19 @@ return function(tree) {

if (!node.attrs) {
return node
return node;
}
var attrs = Object.keys(node.attrs)
var attrs = Object.keys(node.attrs);
if (attrs.length === 1 || orderList.length === 0) {
return node
return node;
}
var sortableAttrs = []
var sortedAttrs = []
var notSortedAttrs = []
var notSortedAttrsIndex = orderList.indexOf("$unknown$")
var finalAttrs = {}
var sortableAttrs = [];
var sortedAttrs = [];
var notSortedAttrs = [];
var notSortedAttrsIndex = orderList.indexOf("$unknown$");
var finalAttrs = {};
if (notSortedAttrsIndex === -1) {
notSortedAttrsIndex = orderList.length
notSortedAttrsIndex = orderList.length;
}

@@ -55,9 +49,9 @@

if (orderListFilterRegExp.test(attr)) {
return true
return true;
}
notSortedAttrs.push(attr)
notSortedAttrs.push(attr);
return false
})
return false;
});

@@ -71,32 +65,34 @@ sortedAttrs = orderListRegExp

.filter(function(attr) {
return regex.test(attr)
return regex.test(attr);
})
// alpha desc sort each group
.sort(function(a, b) {
return typeof a.localeCompare === "function" ? a.localeCompare(b) : a - b
return typeof a.localeCompare === "function"
? a.localeCompare(b)
: a - b;
})
)
);
})
// remove empty groups
.filter(function(group) {
return group.length > 0
})
return group.length > 0;
});
sortedAttrs
// put the non-sorted attributes in desired slot
.splice(notSortedAttrsIndex, 0, notSortedAttrs)
.splice(notSortedAttrsIndex, 0, notSortedAttrs);
sortedAttrs.forEach(function(group) {
group.forEach(function(attr) {
finalAttrs[attr] = node.attrs[attr] ? node.attrs[attr] : true
})
})
finalAttrs[attr] = node.attrs[attr] ? node.attrs[attr] : true;
});
});
node.attrs = finalAttrs
node.attrs = finalAttrs;
return node
})
return node;
});
return tree
}
}
return tree;
};
};
{
"name": "posthtml-vscode-sorting-attrs-logic",
"description": "It's sort HTML attribute based on the given order",
"version": "1.0.1",
"version": "1.0.5",
"author": "Raphaël Balet (ultrastark.ch)",

@@ -20,5 +20,5 @@ "repository": {

],
"dependencies": {},
"devDependencies": {
"mocha": "^5.2.0",
"posthtml-vscode-sorting-attrs": "^0.11.3",
"xo": "^0.23.0"

@@ -71,4 +71,3 @@ },

"homepage": "https://github.com/rbalet/posthtml-vscode-sorting-attrs#readme",
"main": "index.js",
"dependencies": {}
"main": "index.js"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc