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

batoto.js

v3.1.3

Published

Scrape data from bato.to

Downloads

42

Readme

Install

npm install batoto.js

example

Always check if valid property is true. Doesn't matter what you are using this package for.

const { getByID, getChapterByID, searchByKeyword } = require("batoto.js"); //Javascript
//import { getByID, getChapterByID, searchByKeyword } from "batoto.js"; //Typescript

async function getFirstChapter(title) {
  //searching by manga name
  let search = await searchByKeyword(title, 1);

  //check if there are results.
  if (!search.valid) {
    // No results found.
    return [];
  }

  //finished searching. top result is index 0
  let topResult = search.results[0];

  // get information about the search by its id. this includes chapters
  let topManga = await getByID(topResult.id);
  if (!topResult.valid) {
    // "Error getting the manga with the specified id."
    return [];
  }
  // got manga and all chapters

  // get list of images from the chapter. this might take a second to load
  let chapter = await getChapterByID(topManga.chapters[0].id);
  if (!chapter.valid) {
    // Error getting the chapters with the specified chapter ID.
    return [];
  }
  return chapter.pages;
}
// returns empty array if no results were found or there is an error.
// returns string arrray if there are pages for a chapter.
getFirstChapter("Demon Slayer");

Express server

Demo

const {
  getByID,
  getChapterByID,
  searchByKeyword,
  getRandom,
} = require("batoto.js");
const express = require("express");
const app = express();

app.get("/getRandom", async function (req, res) {
  const random = await getRandom();
  if (random == null) {
    return res.status(404).send({ error: "Couldnt get results." });
  }
  return res.status(200).send(random);
});
// http://localhost:8080/getRandom

app.get("/searchByKeyword/:keyword", async function (req, res) {
  const keyword = req.params.keyword;

  const search = await searchByKeyword(keyword, { page: 1 });
  if (!search.valid) {
    return res.status(404).send({ error: "No results found." });
  }
  return res.status(200).send({ results: search.results, pages: search.pages });
});
// http://localhost:8080/searchByKeyword/demon%20slayer

app.get("/getByID/:id", async function (req, res) {
  const id = req.params.id;

  let manga = await getByID(id);
  if (!manga.valid) {
    return res.status(404).send({ error: "No manga with this id" });
  }
  const chapters = manga.chapters;
  chapters.forEach((x) => {
    x.id = x.id.replace(/\//g, "%2F");
  });
  manga.chapters = chapters;
  // You need to replace the '/' in the chapter id to %2F - this is to prevent endpoint problems with getChapterByID
  return res.status(200).send(manga);
});
// http://localhost:8080/getByID/82182-kimetsu-no-yaiba-official

app.get("/getChapterByID/:id", async function (req, res) {
  const id = req.params.id.replace(/%2F/g, "/");
  // turning %2F back to / because the function expects the id with /

  const chapter = await getChapterByID(id);
  if (!chapter.valid) {
    return res.status(404).send({ error: "Failed to get chapter" });
  }
  return res.status(200).send(chapter);
});
// http://localhost:8080/getChapterByID/82182-kimetsu-no-yaiba-official%2F1582807-ch_1

const PORT = 8080;
app.listen(PORT, (error) => {
  if (!error)
    console.log(
      "Server is Successfully Running, and App is listening on port " + PORT
    );
  else console.log("Error occurred, server can't start", error);
});

from here you can integrate this into anything you like. An api, a discord bot, and more.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2023 TzurS11. This project is MIT licensed.