15 lines
472 B
TypeScript
15 lines
472 B
TypeScript
type ArtistItem = { id: string; artist: { id: string } }
|
|
|
|
/** Returns an artist only when every target item is present and shares it. */
|
|
export function stationArtistId(
|
|
items: ArtistItem[],
|
|
targetIds: ReadonlySet<string>
|
|
) {
|
|
const targets = items.filter((item) => targetIds.has(item.id))
|
|
const artistId = targets[0]?.artist.id
|
|
return targets.length === targetIds.size &&
|
|
targets.every((item) => item.artist.id === artistId)
|
|
? artistId
|
|
: undefined
|
|
}
|