Test accent

master
Frédéric Matte 2023-09-28 23:12:49 -04:00
parent f95cd16cf4
commit 4399839883
2 changed files with 8 additions and 0 deletions

View File

@ -1,4 +1,5 @@
const sortby = (properties) => (a, b) => { const sortby = (properties) => (a, b) => {
// '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}

View File

@ -50,6 +50,13 @@ test('sort by new descending', () => {
]) ])
}) })
test('sort with accent, should not change order', () => {
const data = [{ name: 'è' }, { name: 'é' }, { name: 'e' }]
const result = data.sort(sortby(['name']))
equal(result, [{ name: 'è' }, { name: 'é' }, { name: 'e' }])
})
import { runifmain, summaryreporter, errorreporter } from 'metaltest' import { runifmain, summaryreporter, errorreporter } from 'metaltest'
await runifmain(import.meta, () => test.run(summaryreporter(), errorreporter())) await runifmain(import.meta, () => test.run(summaryreporter(), errorreporter()))