aniki
Version:
Aniki is an easy-to-use NPM module that gets information about your favorite anime and manga.
123 lines (122 loc) • 4.74 kB
TypeScript
/**
* @file This file contain the MangaKitsu class, used to get Manga informations from the Kitsu.app API.
*/
import { IKitsuChapter, IKitsuChapters, IKitsuManga, IKitsuMangaFind, IKitsuMangaList, IKitsuMangaSingle, TKitsuHandleError } from "./interfaces/index.js";
/**
* @class
* @description MangaKitsu is a class that's using the Kitsu.app API, with this class you can find Mangas informations in different ways
* @example
* Basic usage:
* ```js
* // CJS
* const { MangaKitsu } = require("aniki")
* // JS ESM or TS
* import { MangaKitsu } from "aniki";
*
* const manga = new MangaKitsu();
*
* // Normal
* manga.find({ query: "Oshi no Ko" }).then(a => console.log(a.data[0]));
*
* // Find by an id
* manga.findById(3600).then(a => console.log(a.data));
*
* // Handling errors
*
* manga.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 functions
*
* async function getManga(query) {
* // ...
* const a = await manga.find({ query: query })
*
* // Tip to avoid multiple awaits
* const a = manga.find({query: ""});
* const b = manga.list({});
* const [A, B] = await Promise.all([a, b])
* }
*
* ```
* @since 1.0.2
*/
declare class MangaKitsu {
private defaultHandleError;
/**
* @method
* @param {IKitsuMangaFind} 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 mangas with different parameters.
* @returns {Promise<IKitsuManga | undefined>} - Returns a Promise with the IKitsuManga inteface.
* @example
* ```js
* manga.find({ query: "Oshi no ko", offset: 0 }).then(a => console.log(a)); // offset is optional.
* ```
* @since 1.0.2
*/
find(params: IKitsuMangaFind, handleError?: TKitsuHandleError): Promise<IKitsuManga | undefined>;
/**
* @method
* @param {number | `${number}`} id - The ID of the manga.
* @param {TKitsuHandleError} [handleError] - Used for handling errors from the method and the API.
* @description Get an Manga with the ID.
* @returns {Promise<IKitsuMangaSingle | undefined>} - Return a Promise.
* @example
* ```js
* manga.findById(30).then(r => console.log(r.data.id));
*
* // Or
* manga.findById("30").then(r => console.log(r.data.id));
* ```
* @since 1.3.0
*/
findById(id: number | `${number}`, handleError?: TKitsuHandleError): Promise<IKitsuMangaSingle | undefined>;
/**
*
* @method
* @param {IKitsuMangaList} params - The parameters for the request.
* @param {TKitsuHandleError} [handleError] - Used for handling errors from the method and the API.
* @description Get an list of Mangas, you can choose the page, and the number of Mangas per page.
* @returns {Promise<IKitsuManga | undefined>} - Return a Promise.
* @example
* ```js
* Manga.list({ offset: 0, perPage: 10 }).then(a => console.log(a));
* ```
* @since 1.0.2
*
*/
list(params: IKitsuMangaList, handleError?: TKitsuHandleError): Promise<IKitsuManga | undefined>;
/**
* @method
* @param {number | `${number}`} id - The parameters to find a specific chapter of a manga using the chapter ID.
* @param {TKitsuHandleError} [handleError] - Used for handling errors from the method and the API.
* @description Get an chapter with the ID.
* @returns {Promise<IKitsuChapter | undefined>} - Return a IKitsuChapter Promise interface or undefined if it has no result.
* @example
* ```js
* manga.chapter(30).then(r => console.log(r.data.attributes.titles.en));
* ```
* @since 1.3.0
*/
chapter(id: number | `${number}`, handleError?: TKitsuHandleError): Promise<IKitsuChapter | undefined>;
/**
* @method
* @param {number | `${number}`} mangaId - The parameters to find all chapters of an manga using its ID.
* @param {TKitsuHandleError} [handleError] - Used for handling errors from the method and the API.
* @returns {Promise<IKitsuChapters | undefined>} Return a IKitsuChapters Promise interface or undefined if it has no result.
* @example
* ```js
* manga.chapters(7442).then(r => console.log(r.data.attributes.titles.en));
* ```
* @since 1.3.5
*/
chapters(mangaId: number | `${number}`, handleError?: TKitsuHandleError): Promise<IKitsuChapters | undefined>;
}
export { MangaKitsu };
export default MangaKitsu;