fix(sorting): sort numeric names naturally

This commit is contained in:
Yuri Karamian
2026-08-15 16:18:22 +02:00
parent 87c879bcac
commit c4a91b8f1c
4 changed files with 149 additions and 11 deletions
+32
View File
@@ -0,0 +1,32 @@
import assert from 'node:assert/strict';
import test from 'node:test';
const { compareNaturalNames } = await import(
new URL('../src/lib/utils/natural-sort.ts', import.meta.url)
);
test('sorts numeric name segments by numeric value', () => {
const names = ['10g', '11g', '12g', '5g', '6g', '7g', '8g', '9g'];
assert.deepEqual(names.sort(compareNaturalNames), [
'5g',
'6g',
'7g',
'8g',
'9g',
'10g',
'11g',
'12g'
]);
});
test('sorts numbers naturally wherever they appear in a name', () => {
const names = ['Class 10b', 'Class 2b', 'Class 10a', 'Class 2a'];
assert.deepEqual(names.sort(compareNaturalNames), [
'Class 2a',
'Class 2b',
'Class 10a',
'Class 10b'
]);
});