1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

All: Fixed sync interval sorting order

This commit is contained in:
Laurent Cozic
2018-02-21 19:58:28 +00:00
parent e1fd9c6922
commit 14a93a9f26
4 changed files with 40 additions and 7 deletions

View File

@ -0,0 +1,31 @@
const ObjectUtils = {};
ObjectUtils.sortByValue = function(object) {
const temp = [];
for (let k in object) {
if (!object.hasOwnProperty(k)) continue;
temp.push({
key: k,
value: object[k],
});
}
temp.sort(function(a, b) {
let v1 = a.value;
let v2 = b.value;
if (typeof v1 === 'string') v1 = v1.toLowerCase();
if (typeof v2 === 'string') v2 = v2.toLowerCase();
if (v1 === v2) return 0;
return v1 < v2 ? -1 : +1;
});
const output = {};
for (let i = 0; i < temp.length; i++) {
const item = temp[i];
output[item.key] = item.value;
}
return output;
}
module.exports = ObjectUtils;