This commit is contained in:
n1474335 2022-11-25 12:26:53 +00:00
commit 23403f55a5
2 changed files with 16 additions and 2 deletions

View file

@ -103,3 +103,15 @@ export function hexadecimalSort(a, b) {
return a.localeCompare(b); return a.localeCompare(b);
} }
/**
* Comparison operation for sorting of lines by length
*
* @param {string} a
* @param {string} b
* @returns {number}
*/
export function lengthSort(a, b) {
return a.length - b.length;
}

View file

@ -7,7 +7,7 @@
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs"; import Utils from "../Utils.mjs";
import {INPUT_DELIM_OPTIONS} from "../lib/Delim.mjs"; import {INPUT_DELIM_OPTIONS} from "../lib/Delim.mjs";
import {caseInsensitiveSort, ipSort, numericSort, hexadecimalSort} from "../lib/Sort.mjs"; import {caseInsensitiveSort, ipSort, numericSort, hexadecimalSort, lengthSort} from "../lib/Sort.mjs";
/** /**
* Sort operation * Sort operation
@ -39,7 +39,7 @@ class Sort extends Operation {
{ {
"name": "Order", "name": "Order",
"type": "option", "type": "option",
"value": ["Alphabetical (case sensitive)", "Alphabetical (case insensitive)", "IP address", "Numeric", "Numeric (hexadecimal)"] "value": ["Alphabetical (case sensitive)", "Alphabetical (case insensitive)", "IP address", "Numeric", "Numeric (hexadecimal)", "Length"]
} }
]; ];
} }
@ -65,6 +65,8 @@ class Sort extends Operation {
sorted = sorted.sort(numericSort); sorted = sorted.sort(numericSort);
} else if (order === "Numeric (hexadecimal)") { } else if (order === "Numeric (hexadecimal)") {
sorted = sorted.sort(hexadecimalSort); sorted = sorted.sort(hexadecimalSort);
} else if (order === "Length") {
sorted = sorted.sort(lengthSort);
} }
if (sortReverse) sorted.reverse(); if (sortReverse) sorted.reverse();