diff options
| author | Brendan F <EpicWolverine@users.noreply.github.com> | 2023-07-12 23:33:47 -0700 |
|---|---|---|
| committer | Brendan F <EpicWolverine@users.noreply.github.com> | 2023-07-12 23:33:47 -0700 |
| commit | 1f1451735b51ad3a66e7b73d307f66bba938e193 (patch) | |
| tree | 6c7b73e7448928456656d9f7ffb5cdb0da329d15 /src | |
| parent | c5a1f7e581ce844d63e0311d1d57cf5dda3cf48e (diff) | |
Ignore non-alphanumeric chars in search
Diffstat (limited to 'src')
| -rw-r--r-- | src/helpers/searchSong.ts | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/helpers/searchSong.ts b/src/helpers/searchSong.ts index 01f6304..4246480 100644 --- a/src/helpers/searchSong.ts +++ b/src/helpers/searchSong.ts @@ -2,12 +2,15 @@ import { songs } from "../constants"; import { Song } from "../types/song"; export function searchSong(searchTerm: string): Song[] { - searchTerm = searchTerm.toLowerCase(); + function fuzzyMatch(input: string){ + return input.toLowerCase().replace(/[^0-9a-z ]/gi, ''); + } + searchTerm = fuzzyMatch(searchTerm); return songs .filter((song: Song) => { - const songName = song.name.toLowerCase(); - const songArtist = song.artist.toLowerCase(); + const songName = fuzzyMatch(song.name); + const songArtist = fuzzyMatch(song.artist); if (songArtist.includes(searchTerm) || songName.includes(searchTerm)) { return song; |
