aniki
Version:
Aniki is an easy-to-use NPM module that gets information about your favorite anime and manga.
118 lines (116 loc) • 4.57 kB
TypeScript
/**
* @file This file contain the AnimeKitsu class, used to get anime informations from the Kitsu.app API.
*/
import { IKitsuAnime, IKitsuAnimeFind, IKitsuAnimeList, IKitsuAnimeSingle, IKitsuEpisode, IKitsuEpisodes, TKitsuHandleError } from "./interfaces/index.js";
/**
* @class
* @since 1.0.2
* @description AnimeKitsu is a class that's using the Kitsu.app API, with this class you can find animes informations in different ways
* @example
* Basic usage:
* ```js
* // CJS
* const { AnimeKitsu } = require("aniki")
* // JS ESM or TS
* import { AnimeKitsu } from "aniki";
*
* const anime = new AnimeKitsu();
*
* // Normal
* anime.find({ query: "Oshi no Ko" }).then(a => console.log(a.data[0]));
*
* // Find by an id
* anime.findById(3600).then(a => console.log(a.data));
*
* // Handling errors
*
* anime.find(
* { query: "Oshi no ko" },
* async ({ apiError, moduleError }, status) => {
* if (apiError) console.error(await apiError);
* if (moduleError) console.error(await moduleError);
* });
*
* // Best practice to avoid using .then() method is by using asynchronous function
*
* async function getAnime(query) {
* // ...
* const a = await anime.find({ query: query })
* // ...
* }
*
* ```
*/
declare class AnimeKitsu {
private defaultHandleError;
/**
* @method
* @param {IKitsuAnimeFind} params - The parameters for the request.
* @param {TKitsuHandleError} [handleError] - Used for handling errors from the method and the API.
* @description The find method is used to find animes with different parameters.
* @returns {Promise<IKitsuAnime | undefined>} - Returns a Promise with the IKitsuAnime inteface.
* @example
* ```js
* // Searching an anime
* anime.find({ query: "Oshi no ko", offset: 0 }).then(r=> console.log(r.data[0]))
* ```
* @since 1.0.2
*/
find(params: IKitsuAnimeFind, handleError?: TKitsuHandleError): Promise<IKitsuAnime | undefined>;
/**
* @method
* @param {number | `${number}`} id - The ID of the anime.
* @param {TKitsuHandleError} [handleError] - Used for handling errors from the method and the API.
* @description Get an anime with the ID.
* @returns {Promise<IKitsuAnimeSingle | undefined>} - Return a Promise.
* @example
* ```js
* anime.findById(30).then(r => console.log(r.data.id));
* ```
* @since 1.3.0
*/
findById(id: number | `${number}`, handleError?: TKitsuHandleError): Promise<IKitsuAnimeSingle | undefined>;
/**
*
* @method
* @param {IKitsuAnimeList} params - The parameters for the request.
* @param {TKitsuHandleError} [handleError] - Used for handling errors from the method and the API.
* @description Get an list of animes, you can choose the page, and the number of animes per page.
* @returns {Promise<IKitsuAnime | undefined>} - Return a Promise.
* @example
* ```js
* anime.list({ offset: 0, perPage: 10 }).then(a => console.log(a));
* ```
* @since 1.0.2
*
*/
list(params: IKitsuAnimeList, handleError?: TKitsuHandleError): Promise<IKitsuAnime | undefined>;
/**
* @method
* @param {number | `${number}`} id - The parameters to find a specific episode of an anime using the episode ID.
* @param {TKitsuHandleError} [handleError] - Used for handling errors from the method and the API.
* @description Get an episode with the ID.
* @returns {Promise<IKitsuEpisode | undefined>} - Return a IKitsuEpisode Promise interface or undefined if it has no result.
* @example
* ```js
* anime.episode(30).then(r => console.log(r.data.attributes.titles.en));
* ```
* @since 1.3.0
*/
episode(id: number | `${number}`, handleError?: TKitsuHandleError): Promise<IKitsuEpisode | undefined>;
/**
* @method
* @param {number | `${number}`} mediaId - The parameters to find all episodes of an anime using its ID.
* @param {TKitsuHandleError} [handleError] - Used for handling errors from the method and the API.
* @description Get an episode with the ID.
* @returns {Promise<IKitsuEpisodes | undefined>} - Return a IKitsuEpisode Promise interface or undefined if it has no result.
* @example
* ```js
* anime.episodes(7442).then(r => console.log(r.data.attributes.titles.en));
* ```
* @since 1.3.5
*/
episodes(mediaId: number | `${number}`, handleError?: TKitsuHandleError): Promise<IKitsuEpisodes | undefined>;
}
export { AnimeKitsu };
export default AnimeKitsu;