@library-pals/isbn 1.3.1 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@library-pals/isbn",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Find books by ISBN",
5
5
  "exports": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -44,9 +44,7 @@
44
44
  "typescript": "^5.4.5"
45
45
  },
46
46
  "dependencies": {
47
- "axios": "^1.6.8",
48
- "string-strip-html": "^13.4.8",
49
- "xss": "^1.0.15"
47
+ "axios": "^1.6.8"
50
48
  },
51
49
  "bugs": {
52
50
  "url": "https://github.com/library-pals/isbn/issues"
@@ -1 +1 @@
1
- {"version":3,"file":"librofm.d.ts","sourceRoot":"","sources":["librofm.js"],"names":[],"mappings":"AAKA;;;GAGG;AAEH;;;;;GAKG;AACH,qCAJW,MAAM,GACJ,QAAQ,IAAI,CAAC,CAezB;AAED;;;;;;GAMG;AACH,kCALW,MAAM,QACN,MAAM,OACN,MAAM,GACJ,QAAQ,IAAI,CAAC,CAgCzB;AAED;;;GAGG;AACH;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;GAIG;AACH,+CAHW,MAAM,GACJ,MAAM,CAkBlB;mBA5GY,OAAO,aAAa,EAAE,IAAI;iCAC1B,OAAO,OAAO,EAAE,kBAAkB;;;;;UAgEjC,MAAM;;;;;;SAIN,MAAM;;;;gBACN,MAAM;;;;UACN,MAAM;;;;iBACN,MAAM;;;;UACN,MAAM;;;;WACN,MAAM;;;;cACN,MAAM;;;;YACN,MAAM,EAAE;;;;YACR,MAAM,EAAE;;;;eACR,MAAM;;;;mBACN,MAAM;;;;gBACN,MAAM;;;;cACN,MAAM;;;;oBACN,MAAM,EAAE;;;;YACR,MAAM;;;;iBACN,MAAM"}
1
+ {"version":3,"file":"librofm.d.ts","sourceRoot":"","sources":["librofm.js"],"names":[],"mappings":"AAGA;;;GAGG;AAEH;;;;;GAKG;AACH,qCAJW,MAAM,GACJ,QAAQ,IAAI,CAAC,CAezB;AAED;;;;;;GAMG;AACH,kCALW,MAAM,QACN,MAAM,OACN,MAAM,GACJ,QAAQ,IAAI,CAAC,CAgCzB;AAED;;;GAGG;AACH;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;GAIG;AACH,+CAHW,MAAM,GACJ,MAAM,CAiBlB;mBA3GY,OAAO,aAAa,EAAE,IAAI;iCAC1B,OAAO,OAAO,EAAE,kBAAkB;;;;;UAgEjC,MAAM;;;;;;SAIN,MAAM;;;;gBACN,MAAM;;;;UACN,MAAM;;;;iBACN,MAAM;;;;UACN,MAAM;;;;WACN,MAAM;;;;cACN,MAAM;;;;YACN,MAAM,EAAE;;;;YACR,MAAM,EAAE;;;;eACR,MAAM;;;;mBACN,MAAM;;;;gBACN,MAAM;;;;cACN,MAAM;;;;oBACN,MAAM,EAAE;;;;YACR,MAAM;;;;iBACN,MAAM"}
@@ -1,7 +1,5 @@
1
1
  import { LIBROFM_API_BASE, LIBROFM_API_BOOK } from "../provider-resolvers.js";
2
2
  import axios from "axios";
3
- import xss from "xss";
4
- import { stripHtml } from "string-strip-html";
5
3
 
6
4
  /**
7
5
  * @typedef {import('../index.js').Book} Book
@@ -98,15 +96,14 @@ export async function standardize(data, isbn, url) {
98
96
  */
99
97
  export function formatDescription(description) {
100
98
  if (!description) return "";
101
- description = xss(description);
102
99
  // Replace <br> with a space
103
100
  description = description.replaceAll("<br>", " ");
104
101
  // Replace <b>—</b> with a dash
105
102
  description = description.replaceAll("<b>—</b>", "—");
106
103
  // Remove bold tags and contents
107
104
  description = description.replaceAll(/<b>.*?<\/b>/g, "");
108
- // Remove all other html elements
109
- description = stripHtml(description).result;
105
+ // Strip HTML tags
106
+ description = stripHtmlTags(description);
110
107
  // Trim
111
108
  description = description.trim();
112
109
  // Remove extra spaces
@@ -135,3 +132,27 @@ function extractGenres(text) {
135
132
 
136
133
  return genres;
137
134
  }
135
+
136
+ /**
137
+ * Encodes HTML special characters to prevent XSS attacks.
138
+ * @param {string} string - The string to encode.
139
+ * @returns {string} - The encoded string.
140
+ */
141
+ function encodeHTML(string) {
142
+ return string
143
+ .replaceAll("&", "&amp;")
144
+ .replaceAll("<", "&lt;")
145
+ .replaceAll(">", "&gt;")
146
+ .replaceAll('" ', "” ")
147
+ .replaceAll(' "', "“ ")
148
+ .replaceAll("'", "&#39;");
149
+ }
150
+
151
+ /**
152
+ * Removes HTML tags from a string and encodes it to prevent XSS attacks.
153
+ * @param {string} string - The string from which to remove HTML tags.
154
+ * @returns {string} - The sanitized string without HTML tags.
155
+ */
156
+ function stripHtmlTags(string) {
157
+ return encodeHTML(string.replaceAll(/<\/?[^>]+(>|$)/g, ""));
158
+ }