@library-pals/isbn 1.0.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -3
- package/package.json +1 -1
- package/src/index.d.ts +10 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +2 -0
- package/src/providers/google.d.ts +13 -2
- package/src/providers/google.d.ts.map +1 -1
- package/src/providers/google.js +63 -11
- package/src/providers/isbndb.js +2 -0
- package/src/providers/open-library.d.ts.map +1 -1
- package/src/providers/open-library.js +37 -0
package/README.md
CHANGED
|
@@ -55,6 +55,10 @@ Response follows the same schema, but some fields could depend on the service
|
|
|
55
55
|
that was used to find the book. In general, Google Books API returns more
|
|
56
56
|
information.
|
|
57
57
|
|
|
58
|
+
#### Response: Google
|
|
59
|
+
|
|
60
|
+
<!-- google 9780374104092 -->
|
|
61
|
+
|
|
58
62
|
```json
|
|
59
63
|
{
|
|
60
64
|
"title": "Annihilation",
|
|
@@ -62,12 +66,89 @@ information.
|
|
|
62
66
|
"description": "Describes the 12th expedition to “Area X,” a region cut off from the continent for decades, by a group of intrepid women scientists who try to ignore the high mortality rates of those on the previous 11 missions. Original. 75,000 first printing.",
|
|
63
67
|
"pageCount": 209,
|
|
64
68
|
"printType": "BOOK",
|
|
65
|
-
"categories": [
|
|
66
|
-
|
|
69
|
+
"categories": [
|
|
70
|
+
"Fiction",
|
|
71
|
+
"Fiction / General",
|
|
72
|
+
"Fiction / Fantasy / General",
|
|
73
|
+
"Fiction / Horror",
|
|
74
|
+
"Fiction / Literary",
|
|
75
|
+
"Fiction / Science Fiction / General",
|
|
76
|
+
"Fiction / Science Fiction / Action & Adventure",
|
|
77
|
+
"Fiction / Thrillers / Suspense",
|
|
78
|
+
"Fiction / Dystopian"
|
|
79
|
+
],
|
|
80
|
+
"thumbnail": "http://books.google.com/books/publisher/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=6&edge=curl&source=gbs_api",
|
|
67
81
|
"link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ",
|
|
68
82
|
"publisher": "Macmillan",
|
|
69
83
|
"publishedDate": "2014-02-04",
|
|
70
|
-
"
|
|
84
|
+
"language": "en",
|
|
85
|
+
"isbn": "9780374104092",
|
|
86
|
+
"bookProvider": "Google Books"
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Response: OpenLibrary
|
|
91
|
+
|
|
92
|
+
<!-- openlibrary 9780374104092 -->
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"title": "Annihilation",
|
|
97
|
+
"authors": ["Jeff VanderMeer"],
|
|
98
|
+
"description": "Area X has been cut off from the rest of the continent for decades. Nature has reclaimed the last vestiges of human civilization. The twelfth expedition arrives expecting the unexpected, and Area X delivers. They discover a massive topographic anomaly and life-forms that surpass understanding. But it's the surprises that came across the border with them, and the secrets the expedition members are keeping from one another that change everything.",
|
|
99
|
+
"pageCount": 208,
|
|
100
|
+
"printType": "BOOK",
|
|
101
|
+
"categories": [
|
|
102
|
+
"Nebula Award Winner",
|
|
103
|
+
"award:nebula_award=novel",
|
|
104
|
+
"award:nebula_award=2015",
|
|
105
|
+
"Discoveries in geography",
|
|
106
|
+
"Fiction",
|
|
107
|
+
"Scientists",
|
|
108
|
+
"Science-Fiction",
|
|
109
|
+
"Suspense fiction",
|
|
110
|
+
"Paranormal fiction",
|
|
111
|
+
"Women scientists",
|
|
112
|
+
"Science fiction",
|
|
113
|
+
"Fantasy fiction",
|
|
114
|
+
"Mystery fiction",
|
|
115
|
+
"Adventure fiction",
|
|
116
|
+
"Exploration",
|
|
117
|
+
"Amerikanisches Englisch",
|
|
118
|
+
"Fiction, science fiction, action & adventure",
|
|
119
|
+
"Fiction, suspense",
|
|
120
|
+
"Action & Adventure",
|
|
121
|
+
"Dystopian",
|
|
122
|
+
"Fantasy",
|
|
123
|
+
"Extrasensory perception",
|
|
124
|
+
"Literary",
|
|
125
|
+
"Suspense",
|
|
126
|
+
"Thrillers",
|
|
127
|
+
"General",
|
|
128
|
+
"Pollution",
|
|
129
|
+
"horror",
|
|
130
|
+
"body horror",
|
|
131
|
+
"alien invasion",
|
|
132
|
+
"nyt:trade-fiction-paperback=2018-03-18",
|
|
133
|
+
"New York Times bestseller",
|
|
134
|
+
"Explorers",
|
|
135
|
+
"Secrecy",
|
|
136
|
+
"Scientific expeditions",
|
|
137
|
+
"Psychic ability",
|
|
138
|
+
"Fiction, thrillers, suspense",
|
|
139
|
+
"Discoveries in geography--fiction",
|
|
140
|
+
"Scientists--fiction",
|
|
141
|
+
"Women scientists--fiction",
|
|
142
|
+
"Ps3572.a4284 a84 2014",
|
|
143
|
+
"813/.54"
|
|
144
|
+
],
|
|
145
|
+
"thumbnail": "https://covers.openlibrary.org/b/id/10520611-L.jpg",
|
|
146
|
+
"link": "https://openlibrary.org/books/OL31444108M",
|
|
147
|
+
"publisher": "Farrar, Straus and Giroux",
|
|
148
|
+
"publishedDate": "2014",
|
|
149
|
+
"language": "en",
|
|
150
|
+
"isbn": "9780374104092",
|
|
151
|
+
"bookProvider": "Open Library"
|
|
71
152
|
}
|
|
72
153
|
```
|
|
73
154
|
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
* @property {string[]} categories - The subjects or categories of the book.
|
|
10
10
|
* @property {string} publisher - The publisher of the book.
|
|
11
11
|
* @property {string} publishedDate - The date the book was published.
|
|
12
|
+
* @property {string | undefined} [language] - The language of the book.
|
|
12
13
|
* @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
|
|
13
14
|
* @property {string} [link] - The link of the book.
|
|
15
|
+
* @property {string} bookProvider - The provider of the book information.
|
|
14
16
|
*/
|
|
15
17
|
/**
|
|
16
18
|
* @typedef {import('./provider-resolvers.js').Providers} Providers
|
|
@@ -80,6 +82,10 @@ export type Book = {
|
|
|
80
82
|
* - The date the book was published.
|
|
81
83
|
*/
|
|
82
84
|
publishedDate: string;
|
|
85
|
+
/**
|
|
86
|
+
* - The language of the book.
|
|
87
|
+
*/
|
|
88
|
+
language?: string | undefined;
|
|
83
89
|
/**
|
|
84
90
|
* - The thumbnail image link of the book.
|
|
85
91
|
*/
|
|
@@ -88,6 +94,10 @@ export type Book = {
|
|
|
88
94
|
* - The link of the book.
|
|
89
95
|
*/
|
|
90
96
|
link?: string;
|
|
97
|
+
/**
|
|
98
|
+
* - The provider of the book information.
|
|
99
|
+
*/
|
|
100
|
+
bookProvider: string;
|
|
91
101
|
};
|
|
92
102
|
export type Providers = import('./provider-resolvers.js').Providers;
|
|
93
103
|
export type AxiosRequestConfig = import('axios').AxiosRequestConfig;
|
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAMA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;GAeG;AAEH;;;GAGG;AAEH;IACE;;OAEG;IACH,wDAA+B;IAG7B;;;;MAAoC;IAGtC;;;;;;OAMG;IACH,oBALW,MAAM,EAAE,GACN,MAAM,CAwBlB;IAED;;;;;;OAMG;IACH,cALW,MAAM,YACN,kBAAkB,GAChB,QAAQ,IAAI,CAAC,CAkBzB;CACF;;;;;UAlFa,MAAM;;;;WACN,MAAM;;;;aACN,MAAM,EAAE;;;;iBACR,MAAM;;;;eACN,MAAM;;;;eACN,MAAM;;;;gBACN,MAAM,EAAE;;;;eACR,MAAM;;;;mBACN,MAAM;;;;eACN,MAAM,GAAG,SAAS;;;;gBAClB,MAAM,GAAG,SAAS;;;;WAClB,MAAM;;;;kBACN,MAAM;;wBAIP,OAAO,yBAAyB,EAAE,SAAS;iCAC3C,OAAO,OAAO,EAAE,kBAAkB"}
|
package/src/index.js
CHANGED
|
@@ -15,8 +15,10 @@ import {
|
|
|
15
15
|
* @property {string[]} categories - The subjects or categories of the book.
|
|
16
16
|
* @property {string} publisher - The publisher of the book.
|
|
17
17
|
* @property {string} publishedDate - The date the book was published.
|
|
18
|
+
* @property {string | undefined} [language] - The language of the book.
|
|
18
19
|
* @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
|
|
19
20
|
* @property {string} [link] - The link of the book.
|
|
21
|
+
* @property {string} bookProvider - The provider of the book information.
|
|
20
22
|
*/
|
|
21
23
|
|
|
22
24
|
/**
|
|
@@ -50,10 +50,21 @@ export function resolveGoogle(isbn: string, options: AxiosRequestConfig): Promis
|
|
|
50
50
|
/**
|
|
51
51
|
* Standardizes a book object by extracting relevant information from the provided book object.
|
|
52
52
|
* @param {GoogleBook} book - The book object to be standardized.
|
|
53
|
+
* @param {string} id - The book id.
|
|
53
54
|
* @param {string} isbn - The book's ISBN.
|
|
54
|
-
* @returns {Book} The standardized book object.
|
|
55
|
+
* @returns {Promise<Book>} The standardized book object.
|
|
55
56
|
*/
|
|
56
|
-
export function standardize(book: GoogleBook, isbn: string): Book
|
|
57
|
+
export function standardize(book: GoogleBook, id: string, isbn: string): Promise<Book>;
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves the volume information for a book.
|
|
60
|
+
* @param {string} id - The book id.
|
|
61
|
+
* @returns {Promise<{imageLinks?: ImageLinks, categories?: string[]}>} - A promise that resolves to an array of author names.
|
|
62
|
+
* @throws {Error} - If there is an error retrieving the author information.
|
|
63
|
+
*/
|
|
64
|
+
export function getVolume(id: string): Promise<{
|
|
65
|
+
imageLinks?: ImageLinks;
|
|
66
|
+
categories?: string[];
|
|
67
|
+
}>;
|
|
57
68
|
export type Book = import('../index.js').Book;
|
|
58
69
|
export type AxiosRequestConfig = import('axios').AxiosRequestConfig;
|
|
59
70
|
export type ImageLinks = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["google.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;;;;;;GAMG;AACH,oCALW,MAAM,WACN,kBAAkB,GAChB,QAAQ,IAAI,CAAC,CA4BzB;AAED;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["google.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;;;;;;GAMG;AACH,oCALW,MAAM,WACN,kBAAkB,GAChB,QAAQ,IAAI,CAAC,CA4BzB;AAED;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;GAMG;AACH,kCALW,UAAU,MACV,MAAM,QACN,MAAM,GACJ,QAAQ,IAAI,CAAC,CAuBzB;AAED;;;;;GAKG;AACH,8BAJW,MAAM,GACJ,QAAQ;IAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAC,CAAC,CAiBrE;mBA/HY,OAAO,aAAa,EAAE,IAAI;iCAC1B,OAAO,OAAO,EAAE,kBAAkB;;;;;iBAuCjC,MAAM;;;;YACN,MAAM;;;;aACN,MAAM;;;;YACN,MAAM;;;;gBACN,MAAM;;;;qBACN,MAAM;;;;;;WAKN,MAAM;;;;cACN,MAAM;;;;aACN,MAAM,EAAE;;;;eACR,MAAM;;;;mBACN,MAAM;;;;iBACN,MAAM;;;;yBACN,MAAM,EAAE;;;;kBACR,MAAM;;;;eACN,MAAM;;;;eACN,MAAM;;;;gBACN,MAAM,EAAE;;;;mBACR,MAAM;;;;kBACN,MAAM;;;;oBACN,MAAM;;;;sBACN,OAAO;;;;oBACP,MAAM;;;;yBACN,MAAM;;;;iBACN,UAAU;;;;cACV,MAAM;;;;iBACN,MAAM;;;;cACN,MAAM;;;;yBACN,MAAM;;;;cACN,MAAM;;;;gBACN,MAAM;;;;gBACN,MAAM"}
|
package/src/providers/google.js
CHANGED
|
@@ -38,7 +38,7 @@ export async function resolveGoogle(isbn, options) {
|
|
|
38
38
|
throw new Error(`No volume info found for book with isbn: ${isbn}`);
|
|
39
39
|
}
|
|
40
40
|
const book = books.items[0];
|
|
41
|
-
return standardize(book.volumeInfo, isbn);
|
|
41
|
+
return await standardize(book.volumeInfo, book.id, isbn);
|
|
42
42
|
} catch (error) {
|
|
43
43
|
throw new Error(error.message);
|
|
44
44
|
}
|
|
@@ -86,27 +86,55 @@ export async function resolveGoogle(isbn, options) {
|
|
|
86
86
|
/**
|
|
87
87
|
* Standardizes a book object by extracting relevant information from the provided book object.
|
|
88
88
|
* @param {GoogleBook} book - The book object to be standardized.
|
|
89
|
+
* @param {string} id - The book id.
|
|
89
90
|
* @param {string} isbn - The book's ISBN.
|
|
90
|
-
* @returns {Book} The standardized book object.
|
|
91
|
+
* @returns {Promise<Book>} The standardized book object.
|
|
91
92
|
*/
|
|
92
|
-
export function standardize(book, isbn) {
|
|
93
|
+
export async function standardize(book, id, isbn) {
|
|
94
|
+
const { imageLinks = book.imageLinks, categories = book.categories } =
|
|
95
|
+
await getVolume(id);
|
|
96
|
+
|
|
93
97
|
const standardBook = {
|
|
94
98
|
title: book.title,
|
|
95
99
|
authors: book.authors,
|
|
96
100
|
description: book.description,
|
|
97
101
|
pageCount: book.pageCount,
|
|
98
102
|
printType: book.printType,
|
|
99
|
-
categories:
|
|
100
|
-
thumbnail: getLargestThumbnail(
|
|
103
|
+
categories: formatCategories(categories),
|
|
104
|
+
thumbnail: getLargestThumbnail(imageLinks),
|
|
101
105
|
link: book.canonicalVolumeLink,
|
|
102
106
|
publisher: book.publisher,
|
|
103
107
|
publishedDate: book.publishedDate,
|
|
108
|
+
language: book.language,
|
|
104
109
|
isbn,
|
|
110
|
+
bookProvider: "Google Books",
|
|
105
111
|
};
|
|
106
112
|
|
|
107
113
|
return standardBook;
|
|
108
114
|
}
|
|
109
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves the volume information for a book.
|
|
118
|
+
* @param {string} id - The book id.
|
|
119
|
+
* @returns {Promise<{imageLinks?: ImageLinks, categories?: string[]}>} - A promise that resolves to an array of author names.
|
|
120
|
+
* @throws {Error} - If there is an error retrieving the author information.
|
|
121
|
+
*/
|
|
122
|
+
export async function getVolume(id) {
|
|
123
|
+
try {
|
|
124
|
+
const url = `${GOOGLE_BOOKS_API_BASE}${GOOGLE_BOOKS_API_BOOK}/${id}`;
|
|
125
|
+
const response = await axios.get(url);
|
|
126
|
+
|
|
127
|
+
if (response.status !== 200) {
|
|
128
|
+
throw new Error(`Unable to get volume ${id}: ${response.status}`);
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
...response.data.volumeInfo,
|
|
132
|
+
};
|
|
133
|
+
} catch (error) {
|
|
134
|
+
throw new Error(error.message);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
110
138
|
/**
|
|
111
139
|
* Get the largest available thumbnail from a book's image links.
|
|
112
140
|
* @param {ImageLinks} [imageLinks] - The image links object.
|
|
@@ -124,10 +152,34 @@ function getLargestThumbnail(imageLinks) {
|
|
|
124
152
|
|
|
125
153
|
if (!imageLinks) return;
|
|
126
154
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
155
|
+
const size = sizes.find((size) => size in imageLinks);
|
|
156
|
+
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
return removeQueryParameter(imageLinks[size], "imgtk");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Removes a query parameter from a URL.
|
|
163
|
+
* @param {string} url - The URL.
|
|
164
|
+
* @param {string} parameter - The query parameter to remove.
|
|
165
|
+
* @returns {string | undefined} The URL with the query parameter removed.
|
|
166
|
+
*/
|
|
167
|
+
function removeQueryParameter(url, parameter) {
|
|
168
|
+
const urlObject = new URL(url);
|
|
169
|
+
urlObject.searchParams.delete(parameter);
|
|
170
|
+
return urlObject.toString();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Formats the categories array.
|
|
175
|
+
* @param {string[]} categories - The array of categories.
|
|
176
|
+
* @returns {string[]} The formatted categories array.
|
|
177
|
+
*/
|
|
178
|
+
function formatCategories(categories) {
|
|
179
|
+
if (!categories || categories.length === 0) return [];
|
|
180
|
+
|
|
181
|
+
const [firstCategory] = categories;
|
|
182
|
+
return firstCategory.includes("/")
|
|
183
|
+
? [firstCategory.split("/")[0].trim(), ...categories]
|
|
184
|
+
: categories;
|
|
133
185
|
}
|
package/src/providers/isbndb.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-library.d.ts","sourceRoot":"","sources":["open-library.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;;;;;;GAMG;AACH,yCALW,MAAM,WACN,kBAAkB,GAChB,QAAQ,IAAI,CAAC,CAuBzB;AAED;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;;GAIG;AAEH;;;GAGG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;GAKG;AACH,kCAJW,eAAe,QACf,MAAM,GACJ,QAAQ,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"open-library.d.ts","sourceRoot":"","sources":["open-library.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;;;;;;GAMG;AACH,yCALW,MAAM,WACN,kBAAkB,GAChB,QAAQ,IAAI,CAAC,CAuBzB;AAED;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;;GAIG;AAEH;;;GAGG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;GAKG;AACH,kCAJW,eAAe,QACf,MAAM,GACJ,QAAQ,IAAI,CAAC,CAwBzB;AAED;;;;GAIG;AACH,uCAHW;IAAC,GAAG,EAAE,MAAM,CAAA;CAAC,EAAE,GACb,QAAQ,MAAM,EAAE,CAAC,CAuB7B;AAED;;;;;GAKG;AAEH;;;;GAIG;AACH,+BAHW,eAAe,GACb,QAAQ;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,EAAE;QAAC,GAAG,EAAE,MAAM,CAAA;KAAC,EAAE,CAAA;CAAC,CAAC,CAuC3F;mBAvMY,OAAO,aAAa,EAAE,IAAI;iCAC1B,OAAO,OAAO,EAAE,kBAAkB;;;;;SAkCjC,MAAM;;;;;;SAKN,MAAM;;;;;;SAKN,MAAM;;;;;;UAKN,MAAM;;;;WACN,MAAM;;;;;;SAKN,MAAM;;;;;;UAKN,MAAM;;;;WACN,MAAM;;;;;;iBAKN,MAAM;;;;WACN,MAAM;;;;aACN,MAAM,EAAE;;;;kBACR,MAAM;;;;gBACN,MAAM,EAAE;;;;YACR,MAAM,EAAE;;;;mBACR,MAAM,EAAE;;;;eACR,QAAQ,EAAE;;;;oBACV,MAAM,EAAE;;;;cACR,MAAM,EAAE;;;;UACR,IAAI;;;;oBACJ,aAAa;;;;SACb,MAAM;;;;qBACN,MAAM;;;;WACN,IAAI,EAAE;;;;qBACN,MAAM;;;;WACN,MAAM;;;;aACN,MAAM,EAAE;;;;aACR,MAAM,EAAE;;;;qBACR,MAAM;;;;cACN,MAAM;;;;aACN,QAAQ;;;;mBACR,QAAQ;;;;;;iBA+DR,MAAM;;;;cACN,MAAM,EAAE;;;;aACR;QAAC,MAAM,EAAE;YAAC,GAAG,EAAE,MAAM,CAAA;SAAC,CAAA;KAAC,EAAE"}
|
|
@@ -120,7 +120,9 @@ export async function standardize(book, isbn) {
|
|
|
120
120
|
: `${OPENLIBRARY_API_BASE}${OPENLIBRARY_API_BOOK}/${isbn}`,
|
|
121
121
|
publisher: book.publishers?.join(", "),
|
|
122
122
|
publishedDate: book.publish_date,
|
|
123
|
+
language: formatLanguage(book.languages),
|
|
123
124
|
isbn,
|
|
125
|
+
bookProvider: "Open Library",
|
|
124
126
|
};
|
|
125
127
|
|
|
126
128
|
return standardBook;
|
|
@@ -204,3 +206,38 @@ export async function getWorks(book) {
|
|
|
204
206
|
throw new Error(error.message);
|
|
205
207
|
}
|
|
206
208
|
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Formats the language codes from Open Library API to their corresponding ISO 639-1 codes.
|
|
212
|
+
* @param {Language[]} languages - An array of language codes from Open Library API.
|
|
213
|
+
* @returns {string | undefined} - A new language map object with ISO 639-1 codes as keys and language codes as values.
|
|
214
|
+
*/
|
|
215
|
+
function formatLanguage(languages) {
|
|
216
|
+
if (!languages || languages.length === 0) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Mapping of Open Library language codes to their corresponding language names.
|
|
221
|
+
* https://openlibrary.org/languages.json
|
|
222
|
+
* @type {{ [key: string]: string } } - A new language map object with ISO 639-1 codes as keys and language codes as values.
|
|
223
|
+
*/
|
|
224
|
+
const newLanguageMap = {
|
|
225
|
+
"/languages/eng": "en",
|
|
226
|
+
"/languages/spa": "es",
|
|
227
|
+
"/languages/fre": "fr",
|
|
228
|
+
"/languages/ger": "de",
|
|
229
|
+
"/languages/rus": "ru",
|
|
230
|
+
"/languages/ita": "it",
|
|
231
|
+
"/languages/chi": "zh",
|
|
232
|
+
"/languages/jpn": "ja",
|
|
233
|
+
"/languages/por": "pt",
|
|
234
|
+
"/languages/ara": "ar",
|
|
235
|
+
"/languages/heb": "he",
|
|
236
|
+
"/languages/kor": "ko",
|
|
237
|
+
"/languages/pol": "pl",
|
|
238
|
+
"/languages/dut": "nl",
|
|
239
|
+
"/languages/lat": "la",
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
return newLanguageMap[languages[0].key] || undefined;
|
|
243
|
+
}
|