A wrapper for the AniList API
npm i anilist-wrapper
or
yarn add anilist-wrapper
import { Client } from "anilist-wrapper";
//Public usage of the API (only queries)
const AniListClient = new Client();
//Private usage of the API (mutations and queries regarding user's data)
const AuthedAniListClient = new Client("your_access_token");
AnilistClient.fetchUser()
.then((user) => console.log(JSON.stringify(user)))
.catch((err) => console.log(err));
import { MediaListGroup, MediaListStatus } from "anilist-wrapper";
let lists: MediaListGroup[] = [];
let [animeWatching, animeCompleted, animeDropped, animePaused,
mangaReading, mangaCompleted, mangaDropped, mangaPaused] = lists;
await AnilistClient.fetchUserAnimeList()
.then((collection) => {
collection.lists!.map((l) => {
if (l.status === MediaListStatus.Current) {
animeWatching = l;
}
else if (l.status === MediaListStatus.Completed) {
animeCompleted = l;
}
else if (l.status === MediaListStatus.Dropped) {
animeDropped = l;
}
else if (l.status === MediaListStatus.Paused) {
animePaused = l;
}
});
})
.catch((err) => {
console.log(err);
});
await AnilistClient.fetchUserMangaList()
.then((collection) => {
collection.lists!.map((l) => {
if (l.status === MediaListStatus.Current) {
mangaReading = l;
}
else if (l.status === MediaListStatus.Completed) {
mangaCompleted = l;
}
else if (l.status === MediaListStatus.Dropped) {
mangaDropped = l;
}
else if (l.status === MediaListStatus.Paused) {
mangaPaused = l;
}
});
})
.catch((err) => {
console.log(err);
});
let animes = [] as Media[];
let mangas = [] as Media[];
await AnilistClient.searchAnime("Gintama", {
page: 1,
perPage: 10,
})
.then((data) => animes = data)
.catch((err) => console.log(err));
await AnilistClient.searchManga("Gintama", {
page: 1,
perPage: 10,
})
.then((data) => mangas = data)
.catch((err) => console.log(err));
Merges two Media objects, one without details (returned from .search) and the other one with details.
await AnilistClient.animeDetails(animes[0])
.then((details) => console.log(JSON.stringify(details)))
.catch((err) => console.log(err));
await AnilistClient.mangaDetails(mangas[0])
.then((details) => console.log(JSON.stringify(details)))
.catch((err) => console.log(err));
let characters = [] as Character[];
let nonDetailedCharacter = {} as Character;
let detailedCharacter = {} as Character;
await AnilistClient.searchCharacter("Gintoki", {
page: 1,
perPage: 10,
})
.then((charactersResponse) => {
characters = charactersResponse;
nonDetailedCharacter = characters[0];
})
.catch((err) => console.log(err));
Merges two Character objects, one without details (returned from .searchCharacter) and the other one with details.
await AnilistClient.characterDetails(nonDetailedCharacter)
.then(async (detailedCharacterResponse) => {
detailedCharacter = detailedCharacterResponse;
console.log(JSON.stringify(detailedCharacter));
})
.catch((err) => console.log(err));
import { SomeType } from "anilist-wrapper";
AnilistClient.fetch<SomeType>({query: `your query`, variables: {
somevariable,
anothervariable
}}).then(...).catch(...)
If the anime doesn't exist in any of the user's lists, parameter entryId is not needed, otherwise, if the anime exists, the parameter entryId is necesary, if it's not provided the request will return an error.
Returns: id of the entry.
await AniListClient.updateEntry({
mediaId: 108725,
status: MediaListStatus.Planning,
})
.then((entryId) => {
console.log(entryId);
})
.catch((err) => {
console.log(JSON.stringify(err));
});
await AniListClient.updateEntry({
entryId: 158644321,
status: MediaListStatus.Dropped,
score: 0,
})
.then((entryId) => {
console.log(entryId);
})
.catch((err) => {
console.log(JSON.stringify(err));
});
await AniListClient.deleteEntry(158644321)
.then((response) => {
console.log(JSON.stringify(response));
})
.catch((err) => {
console.log(JSON.stringify(err));
});