@library-pals/isbn 1.0.0 → 1.0.2

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
@@ -57,7 +57,6 @@ information.
57
57
 
58
58
  ```json
59
59
  {
60
- "isbn": 9780374104092,
61
60
  "title": "Annihilation",
62
61
  "authors": ["Jeff VanderMeer"],
63
62
  "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.",
@@ -65,7 +64,10 @@ information.
65
64
  "printType": "BOOK",
66
65
  "categories": ["Fiction"],
67
66
  "thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
68
- "link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ"
67
+ "link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ",
68
+ "publisher": "Macmillan",
69
+ "publishedDate": "2014-02-04",
70
+ "isbn": "9780374104092"
69
71
  }
70
72
  ```
71
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@library-pals/isbn",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * @typedef {object} Book
3
3
  * @property {string} isbn - The ISBN of the book.
4
- * @property {string} title - The long title of the book.
4
+ * @property {string} title - The title of the book.
5
5
  * @property {string[]} authors - The authors of the book.
6
6
  * @property {string} description - The overview of the book.
7
7
  * @property {number} pageCount - The number of pages in the book.
8
- * @property {string} printType - The print type of the book. Always "BOOK" for this context.
8
+ * @property {string} printType - The print type of the book.
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} publisher - The publisher of the book.
11
+ * @property {string} publishedDate - The date the book was published.
12
+ * @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
11
13
  * @property {string} [link] - The link of the book.
12
14
  */
13
15
  /**
@@ -47,7 +49,7 @@ export type Book = {
47
49
  */
48
50
  isbn: string;
49
51
  /**
50
- * - The long title of the book.
52
+ * - The title of the book.
51
53
  */
52
54
  title: string;
53
55
  /**
@@ -63,17 +65,25 @@ export type Book = {
63
65
  */
64
66
  pageCount: number;
65
67
  /**
66
- * - The print type of the book. Always "BOOK" for this context.
68
+ * - The print type of the book.
67
69
  */
68
70
  printType: string;
69
71
  /**
70
72
  * - The subjects or categories of the book.
71
73
  */
72
74
  categories: string[];
75
+ /**
76
+ * - The publisher of the book.
77
+ */
78
+ publisher: string;
79
+ /**
80
+ * - The date the book was published.
81
+ */
82
+ publishedDate: string;
73
83
  /**
74
84
  * - The thumbnail image link of the book.
75
85
  */
76
- thumbnail: string;
86
+ thumbnail?: string | undefined;
77
87
  /**
78
88
  * - The link of the book.
79
89
  */
@@ -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;;;;eACR,MAAM;;;;WACN,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;;;;;;;;;;;;;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"}
package/src/index.js CHANGED
@@ -7,13 +7,15 @@ import {
7
7
  /**
8
8
  * @typedef {object} Book
9
9
  * @property {string} isbn - The ISBN of the book.
10
- * @property {string} title - The long title of the book.
10
+ * @property {string} title - The title of the book.
11
11
  * @property {string[]} authors - The authors of the book.
12
12
  * @property {string} description - The overview of the book.
13
13
  * @property {number} pageCount - The number of pages in the book.
14
- * @property {string} printType - The print type of the book. Always "BOOK" for this context.
14
+ * @property {string} printType - The print type of the book.
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} publisher - The publisher of the book.
17
+ * @property {string} publishedDate - The date the book was published.
18
+ * @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
17
19
  * @property {string} [link] - The link of the book.
18
20
  */
19
21
 
@@ -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 {object} imageLinks - The image links of the book.
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} - The standardized book object.
54
+ * @returns {Book} The standardized book object.
47
55
  */
48
- export function standardize(book: GoogleBook, id: string, isbn: string): Book;
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: object;
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;;;;;;GAMG;AACH,kCALW,UAAU,MACV,MAAM,QACN,MAAM,GACJ,IAAI,CAgBhB;mBAxFY,OAAO,aAAa,EAAE,IAAI;iCAC1B,OAAO,OAAO,EAAE,kBAAkB;;;;;WAuCjC,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;;;;gBACN,MAAM;;;;cACN,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;;;;;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"}
@@ -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, book.id, isbn);
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 {object} imageLinks - The image links of the book.
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} - The standardized book object.
90
+ * @returns {Book} The standardized book object.
82
91
  */
83
- export function standardize(book, id, isbn) {
92
+ export function standardize(book, isbn) {
84
93
  const standardBook = {
85
94
  title: book.title,
86
95
  authors: book.authors,
@@ -88,10 +97,37 @@ export function standardize(book, id, isbn) {
88
97
  pageCount: book.pageCount,
89
98
  printType: book.printType,
90
99
  categories: book.categories,
91
- thumbnail: `https://books.google.com/books?id=${id}&printsec=frontcover&img=1&zoom=6&edge=curl&source=gbs_api`,
100
+ thumbnail: getLargestThumbnail(book.imageLinks),
92
101
  link: book.canonicalVolumeLink,
102
+ publisher: book.publisher,
103
+ publishedDate: book.publishedDate,
93
104
  isbn,
94
105
  };
95
106
 
96
107
  return standardBook;
97
108
  }
109
+
110
+ /**
111
+ * Get the largest available thumbnail from a book's image links.
112
+ * @param {ImageLinks} [imageLinks] - The image links object.
113
+ * @returns {string|undefined} The URL of the largest thumbnail, or undefined if not found.
114
+ */
115
+ function getLargestThumbnail(imageLinks) {
116
+ const sizes = [
117
+ "extraLarge",
118
+ "large",
119
+ "medium",
120
+ "small",
121
+ "thumbnail",
122
+ "smallThumbnail",
123
+ ];
124
+
125
+ if (!imageLinks) return;
126
+
127
+ for (const size of sizes) {
128
+ if (size in imageLinks) {
129
+ // @ts-ignore
130
+ return imageLinks[size];
131
+ }
132
+ }
133
+ }
@@ -123,6 +123,8 @@ function standardize(book, isbn) {
123
123
  printType: "BOOK",
124
124
  categories: book.subjects,
125
125
  thumbnail: book.image,
126
+ publisher: book.publisher,
127
+ publishedDate: book.date_published,
126
128
  isbn,
127
129
  };
128
130
  }
@@ -1 +1 @@
1
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;;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"}
@@ -118,6 +118,8 @@ export async function standardize(book, isbn) {
118
118
  link: book.key
119
119
  ? `${OPENLIBRARY_API_BASE}${book.key}`
120
120
  : `${OPENLIBRARY_API_BASE}${OPENLIBRARY_API_BOOK}/${isbn}`,
121
+ publisher: book.publishers?.join(", "),
122
+ publishedDate: book.publish_date,
121
123
  isbn,
122
124
  };
123
125