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 🙏

© 2025 – Pkg Stats / Ryan Hefner

turath-sdk

v1.1.0

Published

JavaScript SDK for accessing turath.io books

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

Install turath-sdk using your preferred JavaScript package manager:

bun add turath-sdk
# or
npm install turath-sdk
# or
yarn add turath-sdk

Requirements

Node.js >= 22.0.0

Development

This repository uses Bun for dependency management and testing during development.

bun install
bun run build
bun test           # unit tests with coverage
bun test testing   # end-to-end tests
bun run lint       # Biome static analysis

Exports

The SDK exports strongly-typed helpers and data structures for working with turath.io:

| Export | Type | Description | | --- | --- | --- | | getAuthor | (id: number) => Promise<AuthorApiResponse> | Fetch author biography metadata. | | getBookFile | (id: number) => Promise<BookFileApiResponse> | Retrieve the full JSON dump for a book. | | getBookInfo | (id: number) => Promise<BookApiResponse> | Fetch high-level book metadata and indexes. | | getPage | (bookId: number, pageNumber: number) => Promise<PageResult> | Load a parsed page including metadata. | | search | (query: string, options?: SearchOptions) => Promise<SearchResults> | Run catalog searches with filters. | | SortField | enum | Sorting options for the search helper. | | SearchOptions | type | Optional filters accepted by search. | | SearchResult | type | Parsed representation of a single search hit. | | SearchResults | type | Envelope returned by the search helper. | | PageMetadata | type | Metadata describing page attribution and headings. | | PageResult | type | Page lookup result combining text and metadata. |

Usage

The sections below demonstrate how to use each helper and highlight the available options.

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. Available options are:

  • author (number): Filter results to a specific author ID.
  • book (number): Restrict matches to a single book ID.
  • category (number): Filter by category identifier.
  • page (number): Retrieve a specific page of results.
  • precision (number): Pass-through precision flag used by the API.
  • sortField (SortField): Sort the results (currently SortField.PageId).

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.