From 4399839883ecc5cf42ab2d60b9e977b99389fb34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Matte?= Date: Thu, 28 Sep 2023 23:12:49 -0400 Subject: [PATCH] Test accent --- index.js | 1 + lib/sortby.test.js | 7 +++++++ 2 files changed, 8 insertions(+) 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