diff options
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; |
