A comprehensive TypeScript-based AniList API wrapper utilizing GraphQL.
- ๐ Full TypeScript support with comprehensive type definitions
- ๐ Complete GraphQL query handling
- ๐งฉ Modular architecture for easy extension
- ๐ Comprehensive documentation
- โก Efficient rate limiting
- ๐งช Thoroughly tested with Vitest
npm install anilist-wrapper
import { AniListClient } from 'anilist-wrapper';
// Create a new client
const client = new AniListClient();
// Get anime by ID
async function getAnime() {
const anime = await client.anime.getById(1);
console.log(anime.title.english);
}
// Search for anime
async function searchAnime() {
const results = await client.anime.search({ search: 'Attack on Titan' });
console.log(`Found ${results.data.length} results`);
}
getAnime();
searchAnime();
The wrapper is organized into modules for different types of content:
-
anime
- Anime-related queries -
manga
- Manga-related queries -
character
- Character-related queries -
staff
- Staff-related queries -
user
- User-related queries -
search
- General search functionality
For authenticated requests, you need to provide an OAuth token:
// Create a client with authentication
const client = new AniListClient({ token: 'YOUR_TOKEN_HERE' });
// Or set the token later
client.setToken('YOUR_TOKEN_HERE');
// Get the current user's information
const user = await client.user.getCurrentUser();
console.log(`Logged in as: ${user.name}`);
const trending = await client.anime.getTrending();
console.log('Trending anime:');
trending.data.forEach(anime => {
console.log(`- ${anime.title.english || anime.title.romaji}`);
});
const characters = await client.character.search({ search: 'Luffy' });
console.log(`Found ${characters.data.length} characters`);
characters.data.forEach(character => {
console.log(`- ${character.name.full}`);
});
const query = `
query {
GenreCollection
}
`;
const result = await client.rawQuery(query);
console.log('Available genres:', result.GenreCollection);
The wrapper includes a rate limiter to prevent hitting API limits:
import { AniListClient, RateLimiter } from 'anilist-wrapper';
const client = new AniListClient();
const rateLimiter = new RateLimiter(60); // 60 requests per minute
// Queue up requests through the rate limiter
const animePromise = rateLimiter.add(() =>
client.anime.search({ search: 'One Piece' })
);
const mangaPromise = rateLimiter.add(() =>
client.manga.search({ search: 'Naruto' })
);
// Wait for all requests to complete
const [animeResults, mangaResults] = await Promise.all([
animePromise,
mangaPromise
]);
The main client for interacting with the AniList API.
const client = new AniListClient({
token: 'YOUR_TOKEN_HERE', // Optional
baseUrl: 'https://graphql.anilist.co' // Optional, default shown
});
-
setToken(token: string)
- Set the authentication token -
rawQuery<T>(query: string, variables?: Record<string, any>)
- Execute a raw GraphQL query
Module for anime-related queries.
-
getById(id: number)
- Get anime by ID -
search(options: AnimeFilterOptions, pagination?: PaginationOptions)
- Search for anime -
getTrending(pagination?: PaginationOptions)
- Get trending anime -
getPopular(pagination?: PaginationOptions)
- Get popular anime -
getUpcoming(pagination?: PaginationOptions)
- Get upcoming anime -
getAiring(pagination?: PaginationOptions)
- Get currently airing anime
Module for manga-related queries.
-
getById(id: number)
- Get manga by ID -
search(options: MangaFilterOptions, pagination?: PaginationOptions)
- Search for manga -
getTrending(pagination?: PaginationOptions)
- Get trending manga -
getPopular(pagination?: PaginationOptions)
- Get popular manga -
getUpcoming(pagination?: PaginationOptions)
- Get upcoming manga -
getReleasing(pagination?: PaginationOptions)
- Get currently releasing manga
Module for character-related queries.
-
getById(id: number)
- Get character by ID -
search(options: CharacterFilterOptions, pagination?: PaginationOptions)
- Search for characters -
getPopular(pagination?: PaginationOptions)
- Get popular characters -
getByMedia(mediaId: number, pagination?: PaginationOptions)
- Get characters for a specific anime or manga
Module for user-related queries.
-
getById(id: number)
- Get user by ID -
getByName(name: string)
- Get user by username -
search(options: UserFilterOptions, pagination?: PaginationOptions)
- Search for users -
getCurrentUser()
- Get the current authenticated user
Module for staff-related queries.
-
getById(id: number)
- Get staff by ID -
search(options: StaffFilterOptions, pagination?: PaginationOptions)
- Search for staff -
getPopular(pagination?: PaginationOptions)
- Get popular staff -
getByMedia(mediaId: number, pagination?: PaginationOptions)
- Get staff for a specific anime or manga
Module for general search functionality.
-
searchAll(query: string, pagination?: PaginationOptions)
- Search for all types of content
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please make sure to update tests as appropriate.
This project is licensed under the MIT License - see the LICENSE file for details.