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

shamela

v1.0.3

Published

Library to interact with the Maktabah Shamela v4 APIs

Downloads

34

Readme

Shamela

wakatime E2E Node.js CI GitHub License GitHub Release codecov Size typescript npm npm GitHub issues GitHub stars

A NodeJS library for accessing and downloading Maktabah Shamela v4 APIs. This library provides easy-to-use functions to interact with the Shamela API, download master and book databases, and retrieve book data programmatically.

Table of Contents

Installation

npm install shamela

or

yarn add shamela

or

pnpm install shamela

Environment Variables

Before using the library, you need to set up some environment variables for API keys and endpoints:

SHAMELA_API_KEY: Your API key for accessing the Shamela API. SHAMELA_API_MASTER_PATCH_ENDPOINT: The endpoint URL for the master database patches. SHAMELA_API_BOOKS_ENDPOINT: The base endpoint URL for book-related API calls. You can set these variables in a .env file at the root of your project:

SHAMELA_API_KEY=your_api_key_here
SHAMELA_API_MASTER_PATCH_ENDPOINT=https://shamela.ws/api/master_patch
SHAMELA_API_BOOKS_ENDPOINT=https://shamela.ws/api/books

Usage

Getting Started

First, import the library functions into your project:

import { getMasterMetadata, downloadMasterDatabase, getBookMetadata, downloadBook, getBook } from 'shamela';

API Functions

getMasterMetadata

Fetches metadata for the master database.

getMasterMetadata(version?: number): Promise<GetMasterMetadataResponsePayload>
  • version (optional): The version number of the master database you want to fetch.

Example:

const masterMetadata = await getMasterMetadata();

downloadMasterDatabase

Downloads the master database and saves it to a specified path.

downloadMasterDatabase(options: DownloadMasterOptions): Promise<string>
  • options: An object containing:
    • masterMetadata (optional): The metadata obtained from getMasterMetadata.
    • outputFile: An object specifying the output path.

Example:

await downloadMasterDatabase({
    outputFile: { path: './master.db' },
});

getBookMetadata

Fetches metadata for a specific book.

getBookMetadata(id: number, options?: GetBookMetadataOptions): Promise<GetBookMetadataResponsePayload>
  • id: The ID of the book.
  • options (optional): An object containing:
    • majorVersion: The major version of the book.
    • minorVersion: The minor version of the book.

Example:

await downloadMasterDatabase({
    outputFile: { path: './master.db' },
});

getBook

Retrieves the data of a book as a JavaScript object.

getBook(id: number): Promise<BookData>
  • id: The ID of the book.

Example:

const bookData = await getBook(26592);

Examples

Downloading the Master Database

import { downloadMasterDatabase } from 'shamela';

(async () => {
    await downloadMasterDatabase({
        outputFile: { path: './master.db' },
    });
})();

Downloading a Book

import { downloadBook } from 'shamela';

(async () => {
    await downloadBook(26592, {
        outputFile: { path: './book.db' },
    });
})();

Retrieving Book Data

import { getBook } from 'shamela';

(async () => {
    const bookData = await getBook(26592);
    console.log(bookData);
})();

Testing

The library includes tests to help you understand how the APIs are used. To run the tests, ensure you have the necessary environment variables set, then execute:

npm run test

For end-to-end tests:

npm run e2e

License

This project is licensed under the MIT License - see the LICENSE file for details.