diff options
Diffstat (limited to 'src/lib/Data/Birthday/secondary.ts')
| -rw-r--r-- | src/lib/Data/Birthday/secondary.ts | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/src/lib/Data/Birthday/secondary.ts b/src/lib/Data/Birthday/secondary.ts index 95a18eaf..4b3880e6 100644 --- a/src/lib/Data/Birthday/secondary.ts +++ b/src/lib/Data/Birthday/secondary.ts @@ -1,37 +1,50 @@ -import root from '$lib/Utility/root'; +import root from "$lib/Utility/root"; export interface ACDBBirthday { - character_image: string; - name: string; - origin: string; + character_image: string; + name: string; + origin: string; } const isACDBBirthday = (entry: unknown): entry is ACDBBirthday => - typeof entry === 'object' && - entry !== null && - typeof (entry as { character_image?: unknown }).character_image === 'string' && - typeof (entry as { name?: unknown }).name === 'string' && - typeof (entry as { origin?: unknown }).origin === 'string'; + typeof entry === "object" && + entry !== null && + typeof (entry as { character_image?: unknown }).character_image === + "string" && + typeof (entry as { name?: unknown }).name === "string" && + typeof (entry as { origin?: unknown }).origin === "string"; -export const ACDBBirthdays = async (month: number, day: number): Promise<ACDBBirthday[]> => { - const response = await fetch(root(`/api/birthdays/secondary?month=${month}&day=${day}`), { - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0' - } - }); +export const ACDBBirthdays = async ( + month: number, + day: number, +): Promise<ACDBBirthday[]> => { + const response = await fetch( + root(`/api/birthdays/secondary?month=${month}&day=${day}`), + { + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "User-Agent": + "Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0", + }, + }, + ); - if (!response.ok) throw new Error(`Secondary birthdays request failed with ${response.status}.`); + if (!response.ok) + throw new Error( + `Secondary birthdays request failed with ${response.status}.`, + ); - const data: unknown = await response.json(); + const data: unknown = await response.json(); - if ( - typeof data !== 'object' || - data === null || - !Array.isArray((data as { characters?: unknown }).characters) - ) - throw new Error('Secondary birthdays response did not include a characters array.'); + if ( + typeof data !== "object" || + data === null || + !Array.isArray((data as { characters?: unknown }).characters) + ) + throw new Error( + "Secondary birthdays response did not include a characters array.", + ); - return (data as { characters: unknown[] }).characters.filter(isACDBBirthday); + return (data as { characters: unknown[] }).characters.filter(isACDBBirthday); }; |