feat: 正则排序支持顺序/倒序/原顺序(前端 > 2.15.10)

This commit is contained in:
xream 2025-03-28 12:24:48 +08:00
parent 80955aa339
commit e0c6cc4453
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 17 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.19.10", "version": "2.19.11",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {

View File

@ -284,7 +284,15 @@ function SortOperator(order = 'asc') {
} }
// sort by regex // sort by regex
function RegexSortOperator(expressions) { function RegexSortOperator(input) {
const order = input.order || 'asc';
let expressions = input.expressions;
if (Array.isArray(input)) {
expressions = input;
}
if (!Array.isArray(expressions)) {
expressions = [];
}
return { return {
name: 'Regex Sort Operator', name: 'Regex Sort Operator',
func: (proxies) => { func: (proxies) => {
@ -295,8 +303,13 @@ function RegexSortOperator(expressions) {
if (oA && !oB) return -1; if (oA && !oB) return -1;
if (oB && !oA) return 1; if (oB && !oA) return 1;
if (oA && oB) return oA < oB ? -1 : 1; if (oA && oB) return oA < oB ? -1 : 1;
if ((!oA && !oB) || (oA && oB && oA === oB)) if (order === 'original') {
return a.name < b.name ? -1 : 1; // fallback to normal sort return 0;
} else if (order === 'desc') {
return a.name < b.name ? 1 : -1;
} else {
return a.name < b.name ? -1 : 1;
}
}); });
}, },
}; };