diff --git a/index.js b/index.js index af4c5e8..998c465 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const sortby = (properties) => (a, b) => { + // 'base' treat accent as there base character const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' }) // if items is {prop1:value1, prop2:value2} diff --git a/lib/sortby.test.js b/lib/sortby.test.js index 207cfde..162e3c0 100644 --- a/lib/sortby.test.js +++ b/lib/sortby.test.js @@ -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' await runifmain(import.meta, () => test.run(summaryreporter(), errorreporter())) \ No newline at end of file