mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-15 13:00:25 +02:00
Use a re-usable Intl.Collator instance for locale compare when possible (#1638)
* Use a re-usable Intl.Collator instance for locale compare
This commit is contained in:
@@ -71,6 +71,10 @@ const EXCLUDED_ALBUM_TAGS = new Set<string>([
|
||||
|
||||
const EXCLUDED_SONG_TAGS = new Set<string>(['disctotal', 'tracktotal']);
|
||||
|
||||
// Defining a re-usable Collator instance for performance reasons.
|
||||
const numericSortCollator = new Intl.Collator(undefined, { numeric: true });
|
||||
const collator = new Intl.Collator();
|
||||
|
||||
// Tags that use IDs as values as opposed to the tag value
|
||||
const ID_TAGS = new Set<string>(['albumversion', 'mood']);
|
||||
|
||||
@@ -780,16 +784,17 @@ export const NavidromeController: InternalControllerEndpoint = {
|
||||
.map((data) => ({
|
||||
name: data[0],
|
||||
options: data[1]
|
||||
.sort((a, b) =>
|
||||
a.name
|
||||
.toLocaleLowerCase()
|
||||
.localeCompare(b.name.toLocaleLowerCase(), undefined, {
|
||||
numeric: true,
|
||||
}),
|
||||
)
|
||||
.sort((a, b) => {
|
||||
return numericSortCollator.compare(
|
||||
a.name.toLocaleLowerCase(),
|
||||
b.name.toLocaleLowerCase(),
|
||||
);
|
||||
})
|
||||
.map((option) => ({ id: option.id, name: option.name })),
|
||||
}))
|
||||
.sort((a, b) => a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase()));
|
||||
.sort((a, b) =>
|
||||
collator.compare(a.name.toLocaleLowerCase(), b.name.toLocaleLowerCase()),
|
||||
);
|
||||
|
||||
const excludedAlbumTags = Array.from(EXCLUDED_ALBUM_TAGS.values());
|
||||
const excludedSongTags = Array.from(EXCLUDED_SONG_TAGS.values());
|
||||
|
||||
Reference in New Issue
Block a user