@library-pals/isbn 1.0.2 → 1.1.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 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,11 +66,86 @@ 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": ["Fiction"],
66
- "thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
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",
84
+ "language": "en",
85
+ "isbn": "9780374104092"
86
+ }
87
+ ```
88
+
89
+ #### Response: OpenLibrary
90
+
91
+ <!-- openlibrary 9780374104092 -->
92
+
93
+ ```json
94
+ {
95
+ "title": "Annihilation",
96
+ "authors": ["Jeff VanderMeer"],
97
+ "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.",
98
+ "pageCount": 208,
99
+ "printType": "BOOK",
100
+ "categories": [
101
+ "Nebula Award Winner",
102
+ "award:nebula_award=novel",
103
+ "award:nebula_award=2015",
104
+ "Discoveries in geography",
105
+ "Fiction",
106
+ "Scientists",
107
+ "Science-Fiction",
108
+ "Suspense fiction",
109
+ "Paranormal fiction",
110
+ "Women scientists",
111
+ "Science fiction",
112
+ "Fantasy fiction",
113
+ "Mystery fiction",
114
+ "Adventure fiction",
115
+ "Exploration",
116
+ "Amerikanisches Englisch",
117
+ "Fiction, science fiction, action & adventure",
118
+ "Fiction, suspense",
119
+ "Action & Adventure",
120
+ "Dystopian",
121
+ "Fantasy",
122
+ "Extrasensory perception",
123
+ "Literary",
124
+ "Suspense",
125
+ "Thrillers",
126
+ "General",
127
+ "Pollution",
128
+ "horror",
129
+ "body horror",
130
+ "alien invasion",
131
+ "nyt:trade-fiction-paperback=2018-03-18",
132
+ "New York Times bestseller",
133
+ "Explorers",
134
+ "Secrecy",
135
+ "Scientific expeditions",
136
+ "Psychic ability",
137
+ "Fiction, thrillers, suspense",
138
+ "Discoveries in geography--fiction",
139
+ "Scientists--fiction",
140
+ "Women scientists--fiction",
141
+ "Ps3572.a4284 a84 2014",
142
+ "813/.54"
143
+ ],
144
+ "thumbnail": "https://covers.openlibrary.org/b/id/10520611-L.jpg",
145
+ "link": "https://openlibrary.org/books/OL31444108M",
146
+ "publisher": "Farrar, Straus and Giroux",
147
+ "publishedDate": "2014",
148
+ "language": "en",
70
149
  "isbn": "9780374104092"
71
150
  }
72
151
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@library-pals/isbn",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Find books by ISBN",
5
5
  "exports": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
package/src/index.d.ts CHANGED
@@ -9,6 +9,7 @@
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.
14
15
  */
@@ -80,6 +81,10 @@ export type Book = {
80
81
  * - The date the book was published.
81
82
  */
82
83
  publishedDate: string;
84
+ /**
85
+ * - The language of the book.
86
+ */
87
+ language?: string | undefined;
83
88
  /**
84
89
  * - The thumbnail image link of the book.
85
90
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;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;;;;;UAhFa,MAAM;;;;WACN,MAAM;;;;aACN,MAAM,EAAE;;;;iBACR,MAAM;;;;eACN,MAAM;;;;eACN,MAAM;;;;gBACN,MAAM,EAAE;;;;eACR,MAAM;;;;mBACN,MAAM;;;;gBACN,MAAM,GAAG,SAAS;;;;WAClB,MAAM;;wBAIP,OAAO,yBAAyB,EAAE,SAAS;iCAC3C,OAAO,OAAO,EAAE,kBAAkB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;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;;;;;UAjFa,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;;wBAIP,OAAO,yBAAyB,EAAE,SAAS;iCAC3C,OAAO,OAAO,EAAE,kBAAkB"}
package/src/index.js CHANGED
@@ -15,6 +15,7 @@ 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.
20
21
  */
@@ -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;;;;;GAKG;AACH,kCAJW,UAAU,QACV,MAAM,GACJ,IAAI,CAkBhB;mBAnGY,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"}
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,CAsBzB;AAED;;;;;GAKG;AACH,8BAJW,MAAM,GACJ,QAAQ;IAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAC,CAAC,CAiBrE;mBA9HY,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"}
@@ -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,54 @@ 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: book.categories,
100
- thumbnail: getLargestThumbnail(book.imageLinks),
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,
105
110
  };
106
111
 
107
112
  return standardBook;
108
113
  }
109
114
 
115
+ /**
116
+ * Retrieves the volume information for a book.
117
+ * @param {string} id - The book id.
118
+ * @returns {Promise<{imageLinks?: ImageLinks, categories?: string[]}>} - A promise that resolves to an array of author names.
119
+ * @throws {Error} - If there is an error retrieving the author information.
120
+ */
121
+ export async function getVolume(id) {
122
+ try {
123
+ const url = `${GOOGLE_BOOKS_API_BASE}${GOOGLE_BOOKS_API_BOOK}/${id}`;
124
+ const response = await axios.get(url);
125
+
126
+ if (response.status !== 200) {
127
+ throw new Error(`Unable to get volume ${id}: ${response.status}`);
128
+ }
129
+ return {
130
+ ...response.data.volumeInfo,
131
+ };
132
+ } catch (error) {
133
+ throw new Error(error.message);
134
+ }
135
+ }
136
+
110
137
  /**
111
138
  * Get the largest available thumbnail from a book's image links.
112
139
  * @param {ImageLinks} [imageLinks] - The image links object.
@@ -124,10 +151,34 @@ function getLargestThumbnail(imageLinks) {
124
151
 
125
152
  if (!imageLinks) return;
126
153
 
127
- for (const size of sizes) {
128
- if (size in imageLinks) {
129
- // @ts-ignore
130
- return imageLinks[size];
131
- }
132
- }
154
+ const size = sizes.find((size) => size in imageLinks);
155
+
156
+ // @ts-ignore
157
+ return removeQueryParameter(imageLinks[size], "imgtk");
158
+ }
159
+
160
+ /**
161
+ * Removes a query parameter from a URL.
162
+ * @param {string} url - The URL.
163
+ * @param {string} parameter - The query parameter to remove.
164
+ * @returns {string | undefined} The URL with the query parameter removed.
165
+ */
166
+ function removeQueryParameter(url, parameter) {
167
+ const urlObject = new URL(url);
168
+ urlObject.searchParams.delete(parameter);
169
+ return urlObject.toString();
170
+ }
171
+
172
+ /**
173
+ * Formats the categories array.
174
+ * @param {string[]} categories - The array of categories.
175
+ * @returns {string[]} The formatted categories array.
176
+ */
177
+ function formatCategories(categories) {
178
+ if (!categories || categories.length === 0) return [];
179
+
180
+ const [firstCategory] = categories;
181
+ return firstCategory.includes("/")
182
+ ? [firstCategory.split("/")[0].trim(), ...categories]
183
+ : categories;
133
184
  }
@@ -125,6 +125,7 @@ function standardize(book, isbn) {
125
125
  thumbnail: book.image,
126
126
  publisher: book.publisher,
127
127
  publishedDate: book.date_published,
128
+ language: book.language,
128
129
  isbn,
129
130
  };
130
131
  }
@@ -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,CAsBzB;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;mBArMY,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;;;;;;iBA6DR,MAAM;;;;cACN,MAAM,EAAE;;;;aACR;QAAC,MAAM,EAAE;YAAC,GAAG,EAAE,MAAM,CAAA;SAAC,CAAA;KAAC,EAAE"}
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,CAuBzB;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;mBAtMY,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;;;;;;iBA8DR,MAAM;;;;cACN,MAAM,EAAE;;;;aACR;QAAC,MAAM,EAAE;YAAC,GAAG,EAAE,MAAM,CAAA;SAAC,CAAA;KAAC,EAAE"}
@@ -120,6 +120,7 @@ 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,
124
125
  };
125
126
 
@@ -204,3 +205,38 @@ export async function getWorks(book) {
204
205
  throw new Error(error.message);
205
206
  }
206
207
  }
208
+
209
+ /**
210
+ * Formats the language codes from Open Library API to their corresponding ISO 639-1 codes.
211
+ * @param {Language[]} languages - An array of language codes from Open Library API.
212
+ * @returns {string | undefined} - A new language map object with ISO 639-1 codes as keys and language codes as values.
213
+ */
214
+ function formatLanguage(languages) {
215
+ if (!languages || languages.length === 0) {
216
+ return;
217
+ }
218
+ /**
219
+ * Mapping of Open Library language codes to their corresponding language names.
220
+ * https://openlibrary.org/languages.json
221
+ * @type {{ [key: string]: string } } - A new language map object with ISO 639-1 codes as keys and language codes as values.
222
+ */
223
+ const newLanguageMap = {
224
+ "/languages/eng": "en",
225
+ "/languages/spa": "es",
226
+ "/languages/fre": "fr",
227
+ "/languages/ger": "de",
228
+ "/languages/rus": "ru",
229
+ "/languages/ita": "it",
230
+ "/languages/chi": "zh",
231
+ "/languages/jpn": "ja",
232
+ "/languages/por": "pt",
233
+ "/languages/ara": "ar",
234
+ "/languages/heb": "he",
235
+ "/languages/kor": "ko",
236
+ "/languages/pol": "pl",
237
+ "/languages/dut": "nl",
238
+ "/languages/lat": "la",
239
+ };
240
+
241
+ return newLanguageMap[languages[0].key] || undefined;
242
+ }