@library-pals/isbn 1.0.0 → 1.0.1
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/package.json +1 -1
- package/src/index.d.ts +2 -2
- package/src/index.d.ts.map +1 -1
- package/src/index.js +1 -1
- package/src/providers/google.d.ts +39 -5
- package/src/providers/google.d.ts.map +1 -1
- package/src/providers/google.js +40 -6
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @property {number} pageCount - The number of pages in the book.
|
|
8
8
|
* @property {string} printType - The print type of the book. Always "BOOK" for this context.
|
|
9
9
|
* @property {string[]} categories - The subjects or categories of the book.
|
|
10
|
-
* @property {string} thumbnail - The thumbnail image link of the book.
|
|
10
|
+
* @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
|
|
11
11
|
* @property {string} [link] - The link of the book.
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
@@ -73,7 +73,7 @@ export type Book = {
|
|
|
73
73
|
/**
|
|
74
74
|
* - The thumbnail image link of the book.
|
|
75
75
|
*/
|
|
76
|
-
thumbnail
|
|
76
|
+
thumbnail?: string | undefined;
|
|
77
77
|
/**
|
|
78
78
|
* - The link of the book.
|
|
79
79
|
*/
|
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;GAWG;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;;;;;UA9Ea,MAAM;;;;WACN,MAAM;;;;aACN,MAAM,EAAE;;;;iBACR,MAAM;;;;eACN,MAAM;;;;eACN,MAAM;;;;gBACN,MAAM,EAAE;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;GAWG;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;;;;;UA9Ea,MAAM;;;;WACN,MAAM;;;;aACN,MAAM,EAAE;;;;iBACR,MAAM;;;;eACN,MAAM;;;;eACN,MAAM;;;;gBACN,MAAM,EAAE;;;;gBACR,MAAM,GAAG,SAAS;;;;WAClB,MAAM;;wBAIP,OAAO,yBAAyB,EAAE,SAAS;iCAC3C,OAAO,OAAO,EAAE,kBAAkB"}
|
package/src/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
* @property {number} pageCount - The number of pages in the book.
|
|
14
14
|
* @property {string} printType - The print type of the book. Always "BOOK" for this context.
|
|
15
15
|
* @property {string[]} categories - The subjects or categories of the book.
|
|
16
|
-
* @property {string} thumbnail - The thumbnail image link of the book.
|
|
16
|
+
* @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
|
|
17
17
|
* @property {string} [link] - The link of the book.
|
|
18
18
|
*/
|
|
19
19
|
|
|
@@ -10,6 +10,15 @@
|
|
|
10
10
|
* @throws {Error} If the API response code is not 200, or if no books are found with the provided ISBN, or if no volume information is found for the book.
|
|
11
11
|
*/
|
|
12
12
|
export function resolveGoogle(isbn: string, options: AxiosRequestConfig): Promise<Book>;
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} ImageLinks
|
|
15
|
+
* @property {string} [extraLarge] - extraLarge
|
|
16
|
+
* @property {string} [large] - large
|
|
17
|
+
* @property {string} [medium] - medium
|
|
18
|
+
* @property {string} [small] - small
|
|
19
|
+
* @property {string} [thumbnail] - thumbnail
|
|
20
|
+
* @property {string} [smallThumbnail] - smallThumbnail
|
|
21
|
+
*/
|
|
13
22
|
/**
|
|
14
23
|
* @typedef {object} GoogleBook
|
|
15
24
|
* @property {string} title - The title of the book.
|
|
@@ -29,7 +38,7 @@ export function resolveGoogle(isbn: string, options: AxiosRequestConfig): Promis
|
|
|
29
38
|
* @property {boolean} allowAnonLogging - The allow anon logging of the book.
|
|
30
39
|
* @property {string} contentVersion - The content version of the book.
|
|
31
40
|
* @property {object} panelizationSummary - The panelization summary of the book.
|
|
32
|
-
* @property {
|
|
41
|
+
* @property {ImageLinks} [imageLinks] - The image links of the book.
|
|
33
42
|
* @property {string} language - The language of the book.
|
|
34
43
|
* @property {string} previewLink - The preview link of the book.
|
|
35
44
|
* @property {string} infoLink - The info link of the book.
|
|
@@ -41,13 +50,38 @@ export function resolveGoogle(isbn: string, options: AxiosRequestConfig): Promis
|
|
|
41
50
|
/**
|
|
42
51
|
* Standardizes a book object by extracting relevant information from the provided book object.
|
|
43
52
|
* @param {GoogleBook} book - The book object to be standardized.
|
|
44
|
-
* @param {string} id - The book's id.
|
|
45
53
|
* @param {string} isbn - The book's ISBN.
|
|
46
|
-
* @returns {Book}
|
|
54
|
+
* @returns {Book} The standardized book object.
|
|
47
55
|
*/
|
|
48
|
-
export function standardize(book: GoogleBook,
|
|
56
|
+
export function standardize(book: GoogleBook, isbn: string): Book;
|
|
49
57
|
export type Book = import('../index.js').Book;
|
|
50
58
|
export type AxiosRequestConfig = import('axios').AxiosRequestConfig;
|
|
59
|
+
export type ImageLinks = {
|
|
60
|
+
/**
|
|
61
|
+
* - extraLarge
|
|
62
|
+
*/
|
|
63
|
+
extraLarge?: string;
|
|
64
|
+
/**
|
|
65
|
+
* - large
|
|
66
|
+
*/
|
|
67
|
+
large?: string;
|
|
68
|
+
/**
|
|
69
|
+
* - medium
|
|
70
|
+
*/
|
|
71
|
+
medium?: string;
|
|
72
|
+
/**
|
|
73
|
+
* - small
|
|
74
|
+
*/
|
|
75
|
+
small?: string;
|
|
76
|
+
/**
|
|
77
|
+
* - thumbnail
|
|
78
|
+
*/
|
|
79
|
+
thumbnail?: string;
|
|
80
|
+
/**
|
|
81
|
+
* - smallThumbnail
|
|
82
|
+
*/
|
|
83
|
+
smallThumbnail?: string;
|
|
84
|
+
};
|
|
51
85
|
export type GoogleBook = {
|
|
52
86
|
/**
|
|
53
87
|
* - The title of the book.
|
|
@@ -120,7 +154,7 @@ export type GoogleBook = {
|
|
|
120
154
|
/**
|
|
121
155
|
* - The image links of the book.
|
|
122
156
|
*/
|
|
123
|
-
imageLinks
|
|
157
|
+
imageLinks?: ImageLinks;
|
|
124
158
|
/**
|
|
125
159
|
* - The language of the book.
|
|
126
160
|
*/
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;GAKG;AACH,kCAJW,UAAU,QACV,MAAM,GACJ,IAAI,CAgBhB;mBAjGY,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,12 +38,22 @@ 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,
|
|
41
|
+
return standardize(book.volumeInfo, isbn);
|
|
42
42
|
} catch (error) {
|
|
43
43
|
throw new Error(error.message);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {object} ImageLinks
|
|
49
|
+
* @property {string} [extraLarge] - extraLarge
|
|
50
|
+
* @property {string} [large] - large
|
|
51
|
+
* @property {string} [medium] - medium
|
|
52
|
+
* @property {string} [small] - small
|
|
53
|
+
* @property {string} [thumbnail] - thumbnail
|
|
54
|
+
* @property {string} [smallThumbnail] - smallThumbnail
|
|
55
|
+
*/
|
|
56
|
+
|
|
47
57
|
/**
|
|
48
58
|
* @typedef {object} GoogleBook
|
|
49
59
|
* @property {string} title - The title of the book.
|
|
@@ -63,7 +73,7 @@ export async function resolveGoogle(isbn, options) {
|
|
|
63
73
|
* @property {boolean} allowAnonLogging - The allow anon logging of the book.
|
|
64
74
|
* @property {string} contentVersion - The content version of the book.
|
|
65
75
|
* @property {object} panelizationSummary - The panelization summary of the book.
|
|
66
|
-
* @property {
|
|
76
|
+
* @property {ImageLinks} [imageLinks] - The image links of the book.
|
|
67
77
|
* @property {string} language - The language of the book.
|
|
68
78
|
* @property {string} previewLink - The preview link of the book.
|
|
69
79
|
* @property {string} infoLink - The info link of the book.
|
|
@@ -76,11 +86,10 @@ export async function resolveGoogle(isbn, options) {
|
|
|
76
86
|
/**
|
|
77
87
|
* Standardizes a book object by extracting relevant information from the provided book object.
|
|
78
88
|
* @param {GoogleBook} book - The book object to be standardized.
|
|
79
|
-
* @param {string} id - The book's id.
|
|
80
89
|
* @param {string} isbn - The book's ISBN.
|
|
81
|
-
* @returns {Book}
|
|
90
|
+
* @returns {Book} The standardized book object.
|
|
82
91
|
*/
|
|
83
|
-
export function standardize(book,
|
|
92
|
+
export function standardize(book, isbn) {
|
|
84
93
|
const standardBook = {
|
|
85
94
|
title: book.title,
|
|
86
95
|
authors: book.authors,
|
|
@@ -88,10 +97,35 @@ export function standardize(book, id, isbn) {
|
|
|
88
97
|
pageCount: book.pageCount,
|
|
89
98
|
printType: book.printType,
|
|
90
99
|
categories: book.categories,
|
|
91
|
-
thumbnail:
|
|
100
|
+
thumbnail: getLargestThumbnail(book.imageLinks),
|
|
92
101
|
link: book.canonicalVolumeLink,
|
|
93
102
|
isbn,
|
|
94
103
|
};
|
|
95
104
|
|
|
96
105
|
return standardBook;
|
|
97
106
|
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get the largest available thumbnail from a book's image links.
|
|
110
|
+
* @param {ImageLinks} [imageLinks] - The image links object.
|
|
111
|
+
* @returns {string|undefined} The URL of the largest thumbnail, or undefined if not found.
|
|
112
|
+
*/
|
|
113
|
+
function getLargestThumbnail(imageLinks) {
|
|
114
|
+
const sizes = [
|
|
115
|
+
"extraLarge",
|
|
116
|
+
"large",
|
|
117
|
+
"medium",
|
|
118
|
+
"small",
|
|
119
|
+
"thumbnail",
|
|
120
|
+
"smallThumbnail",
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
if (!imageLinks) return;
|
|
124
|
+
|
|
125
|
+
for (const size of sizes) {
|
|
126
|
+
if (size in imageLinks) {
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
return imageLinks[size];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|