mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-10 14:22:46 +02:00
21 lines
543 B
TypeScript
21 lines
543 B
TypeScript
import Fuse from 'fuse.js';
|
|
|
|
import { Song } from '/@/shared/types/domain-types';
|
|
|
|
export const searchSongs = (songs: Song[], searchTerm: string) => {
|
|
const fuse = new Fuse(songs, {
|
|
fieldNormWeight: 1,
|
|
ignoreLocation: true,
|
|
keys: [
|
|
'name',
|
|
'album',
|
|
{
|
|
getFn: (song) => song.artists.map((artist) => artist.name),
|
|
name: 'artist',
|
|
},
|
|
],
|
|
threshold: 0,
|
|
});
|
|
return fuse.search(searchTerm).map((item) => item.item);
|
|
};
|