aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/searchSong.ts
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-06-07 21:25:28 -0700
committerPinapelz <yukais@pinapelz.com>2026-06-07 21:25:28 -0700
commit01e417ed08a8327169e6488a557c46b6a7b97a08 (patch)
tree499cabb53a48e79f1f2f6379b6c4c8506b619798 /src/helpers/searchSong.ts
parent4e54dfe40b0c20c5b4d4c20b288a8eb8a3805280 (diff)
bundle song list statically, improve search timeHEADmaster
Diffstat (limited to 'src/helpers/searchSong.ts')
-rw-r--r--src/helpers/searchSong.ts27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/helpers/searchSong.ts b/src/helpers/searchSong.ts
index 9ce36cf..62091b6 100644
--- a/src/helpers/searchSong.ts
+++ b/src/helpers/searchSong.ts
@@ -1,25 +1,26 @@
-import { fetchSongs } from "./fetchSongs";
+import { songs } from "../../server/data/songs";
import { Song } from "../types/song";
-export async function searchSong(searchTerm: string): Promise<Song[]> {
- function fuzzyMatch(input: string){
- return input.toLowerCase().replace(/[^0-9a-z ]/gi, '');
- }
- searchTerm = fuzzyMatch(searchTerm);
+function fuzzyMatch(input: string): string {
+ return input.toLowerCase().replace(/[^0-9a-z ]/gi, "");
+}
- const songs = await fetchSongs();
+export function searchSong(searchTerm: string): Song[] {
+ const normalizedSearch = fuzzyMatch(searchTerm);
return songs
.filter((song: Song) => {
const songName = fuzzyMatch(song.name);
const songArtist = fuzzyMatch(song.artist);
- if (songArtist.includes(searchTerm) || songName.includes(searchTerm)) {
- return song;
- }
+ return (
+ songArtist.includes(normalizedSearch) ||
+ songName.includes(normalizedSearch)
+ );
})
- .sort((a, b) =>
- a.artist.toLowerCase().localeCompare(b.artist.toLocaleLowerCase())
- || a.name.toLowerCase().localeCompare(b.name.toLocaleLowerCase())
+ .sort(
+ (a, b) =>
+ a.artist.toLowerCase().localeCompare(b.artist.toLowerCase()) ||
+ a.name.toLowerCase().localeCompare(b.name.toLowerCase())
);
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage