-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mod.ts
49 lines (43 loc) · 943 Bytes
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* This module is browser compatible.
*
* XKDC API Wraper.
*
* https://github.com/UltiRequiem/xkcd
*
* https://ulti.js.org/xkcd
*
* Copyright (c) Eliaz Bobadilla.
*
* Released under the MIT License.
*
* @module
*/
export const XKDC_URL = "https://xkcd.com";
export interface XKCDResponse {
month: string;
num: number;
link: string;
year: string;
news: string;
safe_title: string;
transcript: string;
alt: string;
img: string;
title: string;
day: string;
}
/**
* Returns the metadata of the XKDC comic with the desired ID.
*/
export async function xkcd(id: number | string): Promise<XKCDResponse> {
const response = await fetch(`${XKDC_URL}/${id}/info.0.json`);
return response.json();
}
/**
* Returns the metadata of the latest XKDC comic.
*/
export async function latestXkcd(): Promise<XKCDResponse> {
const response = await fetch(`${XKDC_URL}/info.0.json`);
return response.json();
}