17 lines
514 B
TypeScript
17 lines
514 B
TypeScript
import { languages, Manga } from '../types';
|
|
|
|
export const getMangaTitle = (manga: Manga) => {
|
|
const languageToUse = languages.find((lang) => manga.attributes.title[lang]);
|
|
|
|
if (languageToUse) {
|
|
return manga.attributes.title[languageToUse];
|
|
}
|
|
|
|
// If no language is found, use the first one returned by the API
|
|
const fallbackLanguage = Object.keys(manga.attributes.title)?.[0];
|
|
if (fallbackLanguage) {
|
|
return manga.attributes.title[fallbackLanguage] as string;
|
|
}
|
|
|
|
return 'UNKNOWN TITLE';
|
|
};
|