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

turath-sdk

v1.0.0

Published

JavaScript SDK for accessing turath.io books

Downloads

13

Readme

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

turath-sdk

JavaScript SDK for accessing the books and resources provided by turath.io. This SDK allows you to interact with the turath.io API to retrieve book information, author details, specific pages, and perform searches across the database.

Installation

To install turath-sdk, use npm or yarn:

npm install turath-sdk
# or
yarn add turath-sdk
# or
pnpm i turath-sdk

Requirements

Node.js >= 20.0.0

Usage

The SDK provides several functions to interact with the turath.io API. Below are the main functions that you can use:

Importing the SDK

import { getBookInfo } from 'turath-sdk';

1. getAuthor

Fetches information about an author by their ID.

import { getAuthor } from 'turath-sdk';

(async () => {
    try {
        const author = await getAuthor(44);
        console.log(author);
    } catch (error) {
        console.error(error.message);
    }
})();

Parameters:

id (number): The unique identifier of the author.

Returns: A promise that resolves to the author's information.

Throws: Will throw an error if the author is not found.

2. getBookFile

Fetches the JSON file of a book by its ID.

import { getBookFile } from 'turath-sdk';

(async () => {
    try {
        const bookFile = await getBookFile(147927);
        console.log(bookFile);
    } catch (error) {
        console.error(error.message);
    }
})();

Parameters:

id (number): The unique identifier of the book.

Returns: A promise that resolves to the book file information.

Throws: Will throw an error if the book file is not found.

3. getBookInfo

Fetches the information about a book, including its metadata and indexes.

import { getBookInfo } from 'turath-sdk';

(async () => {
    const bookInfo = await getBookInfo(147927);
    console.log(bookInfo);
})();

Parameters:

id (number): The unique identifier of the book.

Returns: A promise that resolves to the book information including indexes.

4. getPage

Fetches a specific page from a book by its book ID and page number.

import { getPage } from 'turath-sdk';

(async () => {
    try {
        const page = await getPage(147927, 5);
        console.log(page);
    } catch (error) {
        console.error(error.message);
    }
})();

Parameters:

bookId (number): The unique identifier of the book.

pageNumber (number): The page number to retrieve.

Returns: A promise that resolves to the page metadata and text.

Throws: Will throw an error if the page is not found.

5. search

Searches for books or content using a query string.

import { search } from 'turath-sdk';

(async () => {
    const results = await search('الإسلام', { category: 6 });
    console.log(results);
})();

Parameters:

query (string): The search query string.

options (SearchOptions, optional): Additional search options such as category or sorting field.

Returns: A promise that resolves to the search results, including count and data.

Contributing

If you'd like to contribute to the SDK, feel free to fork the repository and submit a pull request. Contributions are welcome!

License

This SDK is licensed under the MIT License.