switch to custom sort comparitor

This commit is contained in:
Cal 2024-10-09 15:09:30 -06:00
parent 84140f4e4f
commit 7a598a439a

View File

@ -836,6 +836,14 @@ function randValuesCallback(from, to, args) {
return value; return value;
} }
function customSortComparitor(a, b) {
if (typeof a != typeof b) {
a = typeof a;
b = typeof b;
}
return a > b ? 1 : a < b ? -1 : 0;
}
function sortArrayObjectCallback(args, value) { function sortArrayObjectCallback(args, value) {
let parsedValue; let parsedValue;
if (typeof value == 'string') { if (typeof value == 'string') {
@ -850,13 +858,13 @@ function sortArrayObjectCallback(args, value) {
} }
if (Array.isArray(parsedValue)) { if (Array.isArray(parsedValue)) {
// always sort lists by value // always sort lists by value
parsedValue.sort() parsedValue.sort(customSortComparitor)
} else if (typeof parsedValue == 'object') { } else if (typeof parsedValue == 'object') {
let keysort = args.keysort; let keysort = args.keysort;
if (isFalseBoolean(keysort)) { if (isFalseBoolean(keysort)) {
parsedValue = Object.keys(parsedValue).sort(function(a,b){return parsedValue[a]-parsedValue[b]}); parsedValue = Object.keys(parsedValue).sort(function(a,b){return customSortComparitor(parsedValue[a], parsedValue[b])});
} else { } else {
parsedValue = Object.keys(parsedValue).sort(); parsedValue = Object.keys(parsedValue).sort(customSortComparitor);
} }
} }
return JSON.stringify(parsedValue); return JSON.stringify(parsedValue);