Skip to content

darrenkuro/meta-fetch

Repository files navigation

book-meta

MIT License Node >= 22 TypeScript

Fetch and rank book metadata from Open Library and Google Books.


Overview

@darrenkuro/book-meta queries multiple book APIs in parallel, normalizes the results into a unified format, scores them against your search query, and deduplicates across providers. All error handling uses neverthrow Result types -- no thrown exceptions.

Personal-use package. Not intended for general consumption.

API

Function Description
searchBooks(query, options?) Query both providers, deduplicate, return ranked results
searchOpenLibrary(query, options?) Query Open Library only
searchGoogleBooks(query, options?) Query Google Books only

SearchQuery

Field Type Description
title string? Book title to search
author string? Author name
isbn string? ISBN-10 or ISBN-13

At least one field is required.

SearchOptions

Field Type Default
googleApiKey string? ''
maxResults number? 10
timeout number? 10000
userAgent string? 'book-meta/0.1.0'

Scoring

Results are ranked by weighted Dice coefficient similarity:

Component Weight Method
Title 0.45 Dice bigram similarity
Author 0.25 Dice bigram similarity
ISBN 0.20 Exact match
Provider 0.05 Boost
Date 0.05 Always 1.0

Weights redistribute proportionally when query fields are absent.

Project Structure

src/
  index.ts              # Public exports
  types.ts              # Shared types (BookResult, SearchQuery, etc.)
  scoring.ts            # Dice similarity, scoring, deduplication
  search.ts             # Orchestrator (searchBooks, per-provider wrappers)
  providers/
    types.ts            # Raw API response types
    open-library.ts     # Open Library provider
    google-books.ts     # Google Books provider
  __tests__/
    scoring.test.ts
    open-library.test.ts
    google-books.test.ts
    search.test.ts

Usage

pnpm add @darrenkuro/book-meta
import { searchBooks } from '@darrenkuro/book-meta';

const result = await searchBooks({ title: 'The Great Gatsby', author: 'Fitzgerald' });

if (result.isOk()) {
  for (const book of result.value) {
    console.log(`${book.title} by ${book.authors.join(', ')} (score: ${book.score.toFixed(2)})`);
  }
} else {
  console.error(result.error);
}
# Development
pnpm install
pnpm test
pnpm run build

License

MIT - Darren Kuro

About

Fetch and rank book metadata from Open Library and Google Books

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors