-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisbn_record.ts
30 lines (28 loc) · 1.05 KB
/
isbn_record.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { getObject, verifyIdentifier } from "./utility.ts";
import { normalizeISBN, validateISBN } from "./isbn.ts";
/**
* Verifies an ISBN using the Open Library API.
* @param isbn - The identifier to verify.
* @returns Promise<boolean> - True if the ISBN exists at Open Library, false otherwise.
*/
export async function verifyISBN(isbn: string): Promise<boolean> {
const normalizedISBN = normalizeISBN(isbn);
return verifyIdentifier(
isbn,
`https://openlibrary.org/isbn/${encodeURIComponent(normalizedISBN)}.json`,
validateISBN,
);
}
/**
* getObjectISBN retrieves an ISBN record from OpenLibrary.org
* @param isbn - The identifier of the object to retreive.
* @returns Promise<object | undefined>, if object can't be retrieved or JSON fail to parse undefined is returned.
*/
export async function getObjectISBN(isbn: string): Promise<object | undefined> {
const normalizedISBN = normalizeISBN(isbn);
return await getObject(
isbn,
`https://openlibrary.org/isbn/${encodeURIComponent(normalizedISBN)}.json`,
validateISBN,
);
}