1.6.0 • Published 6 months ago

isbn-fetch v1.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

isbn-fetch

A small package that fetches book information given an ISBN number.

Usage

import IsbnFetch from 'isbn-fetch';

// Fetch a book with the best possible information
// Note: this method does not throw an error even if all providers fail
const book = await IsbnFetch.combined('978-3-453-31716-1');

// Fetch a book from Google Books
try {
    const book = await IsbnFetch.googlebooks('978-3-453-31716-1');
} catch (e) {
    console.error(e);
}

Providers

function namedescription
googlebooksFetches book information from the Google Books API.
openlibraryFetches book information from the Open Library API.
isbndbWebscrapeFetches book information by scraping the ISBNdb website.
amazonWebscrapeFetches book information by scraping the Amazon website.
combinedFetches book information from all other providers. Tries to return the most complete information.

All providers are exported as functions from the default export object.
For more infomation about a specific method see the documentation in the type definition files.

Types

A Book object is defined as follows:

type Book = {
    isbn10?: string;
    isbn13?: string;
    title?: string;
    authors?: string[];
    publishedDate?: string;
    genres?: string[];
    language?: string;
    pageCount?: number;
    thumbnail?: string;
    thumbnailSmall?: string;
    description?: string;
    publishers?: string[];
};

All provider functions have the following signature:

async function provider(isbn: string, fetchOptions?: FetchOptions): Promise<Book>;

Fetch options are a stripped down version of the RequestInit interface:

type FetchOptions = Omit<RequestInit, "body" | "method" | "keepalive">;

For more information see the documentation in the type definition files.

Installation

npm i isbn-fetch --save

If you want to use a provider that does web scraping, and you are using nodejs (DOMParser is not available), you also need to install the jsdom package:

npm i jsdom --save

combinedResults

You can use the combinedResults function to merge the results of only selected providers:

import IsbnFetch from 'isbn-fetch';

const book = IsbnFetch.combinedResults({
    googlebooks: /* fetched Book or undefined */,
    openlibrary: /* fetched Book or undefined */,
    isbndbWebscrape: /* fetched Book or undefined */,
    amazonWebscrape: /* fetched Book or undefined */
});

This is not a simple function over an array of books because it knows which provider has the best chance of providing the best information for each field.

1.6.0

6 months ago

1.5.1

6 months ago

1.5.0

6 months ago

1.4.1

7 months ago

1.4.0

7 months ago

1.3.1

7 months ago

1.3.0

7 months ago

1.2.1

7 months ago

1.2.0

7 months ago

1.1.0

7 months ago

1.0.0

7 months ago