mirror of
https://github.com/keeweb/keeweb.git
synced 2024-06-27 07:45:08 +02:00
29 lines
844 B
JavaScript
29 lines
844 B
JavaScript
'use strict';
|
|
|
|
var LastChar = String.fromCharCode(0xffffffff);
|
|
|
|
var ciCompare = (window.Intl && window.Intl.Collator) ?
|
|
new Intl.Collator(undefined, { sensitivity: 'base' }).compare : function(x, y) {
|
|
return x.toLocaleLowerCase().localeCompare(y.toLocaleLowerCase());
|
|
};
|
|
|
|
var Comparators = {
|
|
stringComparator: function(field, asc) {
|
|
if (asc) {
|
|
return function (x, y) { return ciCompare(x[field] || LastChar, y[field] || LastChar); };
|
|
} else {
|
|
return function (x, y) { return ciCompare(y[field], x[field]); };
|
|
}
|
|
},
|
|
|
|
dateComparator: function(field, asc) {
|
|
if (asc) {
|
|
return function (x, y) { return x[field] - y[field]; };
|
|
} else {
|
|
return function (x, y) { return y[field] - x[field]; };
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = Comparators;
|