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

v0.12.4

Published

An UNOFFICIAL wrapper for the anilist api written in typescript

Downloads

1,461

Readme

Anilist Wrapper

An UNOFFICIAL wrapper for the anilist api written in typescript that tries to follow the builder pattern to give a more consistent interface to create objects.

You can visit the official graphql docs for anilist here to find out everything you can do[^*].

Table of Contents

Status

To see the current status of the wrapper check the todo list.

Warning As of v0.12 the only way to create queries is query.<queryName>

Installation

npm i anilist

Usage

Creating a query

const query = anilist.query.media();

Query arguments

The queries can accept either an object of MediaArguments or a string.

If you pass in a string it will be transformed into { search: string } internally.

const queryByName = anilist.query.media("Kamisama Ni Natta Hi");
/*
query {
    Media(type: ANIME, search: "Kamisama Ni Natta Hi") {
        id
    }
}
*/

const queryById = anilist.query.media({
    id: 118419
});
/*
query {
    Media(type: ANIME, id: 118419) {
        id
    }
}
*/

Creating the query

Page Query

if you build the query and fetch it without telling which fields to return it will default to returning { media: { id } } with { page: 1, perPage: 10 }

const query = anilist.pageQuery()

await query.fetch()
/*
{
  media: [
    { id: 1 },  { id: 5 }, 
    { id: 6 },  { id: 7 }, 
    { id: 8 },  { id: 15 },
    { id: 16 }, { id: 17 },
    { id: 18 }, { id: 19 } 
  ]
}
*/

query.withMedia(media => media.withTitles())

await query.fetch()
/*
{
  media: [
    { title: { romaji: 'Cowboy Bebop' } },
    { title: { romaji: 'Cowboy Bebop: Tengoku no Tobira' } },
    { title: { romaji: 'TRIGUN' } },
    { title: { romaji: 'Witch Hunter ROBIN' } },
    { title: { romaji: 'Bouken Ou Beet' } },
    { title: { romaji: 'Eyeshield 21' } },
    { title: { romaji: 'Hachimitsu to Clover' } },
    { title: { romaji: 'Hungry Heart: Wild Striker' } },
    { title: { romaji: 'Initial D FOURTH STAGE' } },
    { title: { romaji: 'MONSTER' } }
  ]
}
*/

Other Queries

Fetching without building the query

If you build the query and try to fetch it without telling which fields to return it will default to returning id to avoid errors.

const query = anilist.query.media("Kamisama Ni Natta Hi");

await query.fetch();
/*
{ id: 118419 }
*/

query.withEpisodes();

await query.fetch();
/*
{ episodes: 12 }
*/
Creating a complete search query

As the library follows the builder pattern you can just nest functions until you have every field you want.

const query = anilist.query.media("Kamisama Ni Natta Hi")
        .withId()
        .withSiteUrl()
        .withTitles()
        .withStatus();

await query.fetch();
/*
{
  id: 118419,
  siteUrl: 'https://anilist.co/anime/118419',
  title: {
    romaji: 'Kamisama ni Natta Hi'
  },
  status: 'FINISHED'
}
*/
Relations

All relations that use edges and nodes will have the following structure

anilist.query.media().withRelations({
  edges: (edge) => edge.withId().withNode((node) => node.withId()),
  nodes: (node) => node.withId(),
  pageInfo: (page) => page.withTotal(),
  // And optionally they will have an args object
})
Passing arguments at run time

Instead of passing the query arguments on query creation you can use <query.media>.prototype.arguments to change them every time you want to run fetch. This will avoid creating a new query instance every time you change something on it.

const query = anilist.query.media();

await query.fetch()
/*
{ id: 1 }
*/

query.arguments({
  search: "Kamisama Ni Natta",
  type: "MANGA"
}).withId().withTitles("romaji", "native")

await query.fetch()
/*
{
  id: 135190,
  title: { romaji: 'Kamisama ni Natta Hi', native: '神様になった日' }
}
*/

OAuth

The library provides 2 helpers methods for OAuth and i will explain them here

Remember: All options can be passed to the client constructor so you don't have to pass them in every function

createOAuthURI

This method returns the url with all required properties

Implicit Grant URI

// 
const uri = anilist.createOAuthURI({
  clientId: /* the id (can be an number or string) */,
  responseType: "token"
});

Authorization Code Grant

const uri = const uri = anilist.createOAuthURI({
  clientId: /* the id (can be an number or string) */,
  responseType: "code"
})

getAccessToken

This helper method allows you to convert the Authorization Code Grant into an access token

const response = anilist.getAccessToken(codeGrant, {
  clientId: /* the id (can be an number or string) */,
  clientSecret: /* the client secret */,
  redirectUri: /* the redirect uri, this is required for this step*/,
})

[^*]: Not everything is supported yet, please refer to the todo list to see what has full implementation or open an issue to talk about it