Create one collator per run

master
Frédéric Matte 2025-05-29 02:49:16 -04:00
parent f4157d9262
commit 9a93035409
1 changed files with 20 additions and 17 deletions

View File

@ -1,10 +1,12 @@
const sortby = (...properties) => (a, b) => {
const sortby = (...properties) => {
// 'base' treat accent as there base character // 'base' treat accent as there base character
const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' }) const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' })
// if items is {prop1:value1, prop2:value2} // if items is {prop1:value1, prop2:value2}
// then sort(['prop1', 'desc', 'prop2']) // then sort(['prop1', 'desc', 'prop2'])
// will sort by prop1 desc and prop2 // will sort by prop1 desc and prop2
return (a, b) => {
for (let i = 0; i < properties.length; i++) { for (let i = 0; i < properties.length; i++) {
const property = properties[i] const property = properties[i]
@ -27,6 +29,7 @@ const sortby = (...properties) => (a, b) => {
} }
return 0 return 0
}
} }
export { sortby } export { sortby }