npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

anilist-api-client

v1.1.2

Published

A TypeScript-based wrapper for interacting with anime and manga data from AniList.

Downloads

267

Readme

AnilistAPI Client Module Documentation

Introduction

AnimeMangaWrapper is an npm module designed to interact with the AniList API, allowing users to search for anime and manga information. It offers dynamic features such as multilingual support (EN/FR), search by title or ID, and flexible configuration.


Installation

Ensure that Node.js is installed on your machine.

Installation Command:

npm install anilist-api-client

Usage

Importing the Module

In a JavaScript or TypeScript project, you can import the module as follows:

JavaScript:

const { AnilistAPIClient } = require('anime-api-client');

TypeScript:

import { AnilistAPIClient } from 'anime-api-client';

Classes and Methods

The module is divided into two main subclasses: Anime and Manga.

Main Class: AnilistAPIClient

This class serves as the main interface for accessing module functionality.

Subclass: Anime

Enables interaction with anime-related data.

Primary Methods:

getByTitle(title: string): Promise<any>

Searches for an anime by its title.

  • Parameters:

    • title (string): The title of the anime.
  • Returns:

    • A promise containing the data of the found anime.
Example:
const anime = await AnilistAPIClient.anime.getByTitle('Naruto');
console.log(anime);
getById(id: number): Promise<any>

Searches for an anime by its ID.

  • Parameters:

    • id (number): The ID of the anime.
  • Returns:

    • A promise containing the data of the found anime.
Example:
const anime = await AnilistAPIClient.anime.getById(20);
console.log(anime);

Subclass: Manga

Enables interaction with manga-related data.

Primary Methods:

getByTitle(title: string): Promise<any>

Searches for a manga by its title.

  • Parameters:

    • title (string): The title of the manga.
  • Returns:

    • A promise containing the data of the found manga.
Example:
const manga = await AnilistAPIClient.manga.getByTitle('One Piece');
console.log(manga);
getById(id: number): Promise<any>

Searches for a manga by its ID.

  • Parameters:

    • id (number): The ID of the manga.
  • Returns:

    • A promise containing the data of the found manga.
Example:
const manga = await AnilistAPIClient.manga.getById(1);
console.log(manga);

Error Handling

The module integrates advanced error handling with clear messages.

Example: Search Without Title

If a missing title or ID is provided, an error is thrown:

try {
  const anime = await AnilistAPIClient.anime.getByTitle('');
} catch (error) {
  console.error(error.message); // "A title is required to perform a search."
}

Example: API Error

In case of network errors or issues with the API:

try {
  const manga = await AnilistAPIClient.manga.getById(9999999);
} catch (error) {
  console.error(error.message); // "Error fetching data: ..."
}

Complete Usage Example

Here is an example demonstrating the main features of the module:

const { AnilistAPIClient } = require('anime-api-client');

(async () => {
  // Search for an anime by title
  try {
    const anime = await AnilistAPIClient.anime.getByTitle('Naruto');
    console.log('Found anime:', anime);
  } catch (error) {
    console.error('Error:', error.message);
  }

  try {
    const anime = await AnilistAPIClient.anime.getById(20);
    console.log('Found anime (EN):', anime);
  } catch (error) {
    console.error('Error:', error.message);
  }
})();

Discord Bot Integration Example

To use this module in a Discord bot, you can create a command that retrieves anime or manga information when triggered by users.

Discord bot example:

const { Client, GatewayIntentBits } = require('discord.js');
const { AnilistAPIClient } = require('anime-api-client');

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });

client.once('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('messageCreate', async (message) => {
  if (message.author.bot) return;

  const [command, ...args] = message.content.split(' ');

  if (command === '!anime') {
    const title = args.join(' ');
    if (!title) {
      return message.reply('Please provide the title of the anime.');
    }

    try {
      const anime = await AnilistAPIClient.anime.getByTitle(title);
      message.reply(`Found anime: ${anime.title.romaji} - ${anime.description}`);
    } catch (error) {
      message.reply(`Error: ${error.message}`);
    }
  }

  if (command === '!manga') {
    const title = args.join(' ');
    if (!title) {
      return message.reply('Please provide the title of the manga.');
    }

    try {
      const manga = await AnilistAPIClient.manga.getByTitle(title);
      message.reply(`Found manga: ${manga.title.romaji} - ${manga.description}`);
    } catch (error) {
      message.reply(`Error: ${error.message}`);
    }
  }
});

client.login('YOUR_DISCORD_BOT_TOKEN');

Development and Contribution

If you want to contribute to the module's development:

  1. Clone the repository:
    git clone https://github.com/gonzyui/Anilist-API-Client.git
  2. Install dependencies:
    npm install
  3. Build the project:
    npm run build
  4. Run tests:
    npm test

License

This project is licensed under the MIT License. You are free to use and modify it.