0.0.24 • Published 3 years ago

anilist-wrapper v0.0.24

Weekly downloads
42
License
MIT
Repository
github
Last release
3 years ago

anilist-wrapper

A wrapper for the AniList API

npm version

Install

npm i anilist-wrapper

or

yarn add anilist-wrapper

Usage

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");

Queries

Getting personal information and stats of the authenticated user

AnilistClient.fetchUser()
  .then((user) => console.log(JSON.stringify(user)))
  .catch((err) => console.log(err));

Fetching the anime and manga lists of the authenticated user

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);
  });

Searching anime and manga

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));

Getting more details of anime and manga

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));

Searching characters

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));

Getting more details of a character

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));

Making your own custom function

import { SomeType } from "anilist-wrapper";

AnilistClient.fetch<SomeType>({query: `your query`, variables: {
  somevariable,
  anothervariable
}}).then(...).catch(...)

Mutations

Adding and Updating an entry

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));
  });

Deleting an entry

await AniListClient.deleteEntry(158644321)
  .then((response) => {
    console.log(JSON.stringify(response));
  })
  .catch((err) => {
    console.log(JSON.stringify(err));
  });

License

[MIT](https://github.com/system32uwu/anilist-wrapper/blob/main/LICENSE.md)

0.0.24

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.23

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8-rc.13

3 years ago

0.0.8-rc.12

3 years ago

0.0.8-rc.11

3 years ago

0.0.8-rc.10

3 years ago

0.0.8-rc.6

3 years ago

0.0.8-rc.7

3 years ago

0.0.8-rc.8

3 years ago

0.0.8-rc.9

3 years ago

0.0.8-rc.5

3 years ago

0.0.8-rc.4

3 years ago

0.0.8-rc.1

3 years ago

0.0.8-rc.2

3 years ago

0.0.8-rc.3

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago