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

mangadex-api

v5.0.1

Published

mangadex api wrapper with known apis

Downloads

124

Readme

Mangadex-api

NPM Version npm downloads License codecov

This is Mangadex website api wrapper.

WIP on V5 version

Installation

npm i mangadex-api

# or

yarn add mangadex-api

Example

// In V5 Mangadex switched id type from number to string.
// So if you need to convert it, call the convertLegacyId method.
// Soon will be added to usual methods, maybe.

Mangadex.convertLegacyId([12], 'group')
  .then((result) => {
    if (result.result === 'error') {
      console.log(
        `Got error on convertLegacyId request! ${result.errors
          .map((err) => err.title)
          .join(', ')}`
      )
      return
    }

    const { newId } = result.data.attributes

    console.log(`New group id: ${newId}`)
  })

Mangadex.manga
  .getManga(
    'c26269c7-0f5d-4966-8cd5-b79acb86fb7a',
    {
      // will fetch additionally scanlation_group, artist, author attributes
      withRelationShips: true
    }
  )
  .then(({ result, data, errors }) => {
    if (result === 'error') {
      // oh no! something went wrong!
      // here we can handle errors array.
    }

    const { title, originalLanguage } = data.attributes
    console.log(`Manga ${title.en} published in ${originalLanguage}`)

    Mangadex.manga
      .getMangaFeed('c26269c7-0f5d-4966-8cd5-b79acb86fb7a', {
        limit: 10
      })
      .then(({ results: chapters }) => {
        console.log(`Manga ${title.en} has ${chapters.length} chapters`)
        const { volume, chapter } = chapters[0].data.attributes
        console.log(`Latest chapter: Vol ${volume} Ch ${chapter}`)
      })
  })

Mangadex.chapter.getChapter(8857).then((chapter) => {
  if (chapter.result === 'error') {
    console.log(
      `Got errors on chapter request! ${chapter.errors
        .map((err) => err.title)
        .join(', ')}`
    )
    return
  }
  console.log(
    `Chapter title is "${chapter.data.attributes.title}" and it is ${chapter.data.attributes.chapter} chapter from ${chapter.volume} volume.`
  )
})

// currently requires authorization
Mangadex.manga.search({ title: 'senko' }).then(({ total }) => {
  console.log(`Found ${total} titles.`)
})
// Search with NSFW results
Mangadex.manga
  .search({
    title: 'gotoubun',
    contentRating: ['pornographic']
  })
  .then((result) => {
    console.log(`Found ${result.results.length} hentai manga (☞ ͡ ͡° ͜ ʖ ͡ ͡°)☞`)
  })

Mangadex.group.getGroup(12).then((group) => {
  if (group.result === 'error') {
    console.log(
      `Got errors from group request! ${group.errors
        .map((err) => err.title)
        .join(', ')}`
    )
    return
  }
  const { name, members } = group.data.attributes
  console.log(`Group ${name} has ${members} members`)
})

Authorization example

const { Mangadex } = require('mangadex-api')

const client = new Mangadex()

const loginResult = await client.auth.login('username', 'password')

if (loginResult.result === 'error') {
  // oh no! it's login error!
}

const result = await client.manga.search('To Be Winner')

console.log(result)

Cached session example

// first you must save your session somewhere

const loginResult = await client.auth.login('username', 'password')

if (loginResult.result === 'error') {
  // oh no! it's login error!
}

await client.agent.saveSession('/path/to/session'))

// now we can use it

await client.agent.loginWithSession('/path/to/session')

const me = await client.user.getMe()

console.log(me)

API

API section is available on the website.

Additional resources

  • mangadex-heroku is a GraphQL public endpoint. (not updated to V5 yet)
    Supports caching (in memory) and all public MD-API's that doesn't require authorization. (playground)
  • Example webapp that uses mangadex-heroku for API calls. (not updated to V5 yet)

Contact

My telegram and a group where you can ask your questions or suggest something.