don't reemplement localeCompare (#695)

This commit is contained in:
Konstantin Vyatkin 2019-10-29 13:09:49 -04:00 committed by Josh Johnson
parent 2b8acc5f37
commit 2a03d9be12

View file

@ -105,20 +105,18 @@ export const strToEl = (() => {
};
})();
export const sortByAlpha = (a, b) => {
const labelA = `${a.label || a.value}`.toLowerCase();
const labelB = `${b.label || b.value}`.toLowerCase();
if (labelA < labelB) {
return -1;
}
if (labelA > labelB) {
return 1;
}
return 0;
};
export const sortByAlpha =
/**
* @param {{ label?: string, value: string }} a
* @param {{ label?: string, value: string }} b
* @returns {number}
*/
({ value, label = value }, { value: value2, label: label2 = value2 }) =>
label.localeCompare(label2, [], {
sensitivity: 'base',
ignorePunctuation: true,
numeric: true,
});
export const sortByScore = (a, b) => a.score - b.score;