sanitized 1.1.9 → 1.2.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.
Files changed (2) hide show
  1. package/index.js +9 -5
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -3,21 +3,25 @@ const he = require("he");
3
3
 
4
4
  if (!dompurify.sanitize) {
5
5
  const jsdom = require("jsdom");
6
+
6
7
  const jsdomWindow = new jsdom.JSDOM("").window;
8
+
7
9
  dompurify = dompurify(jsdomWindow);
8
10
  }
9
11
 
10
12
  function sanitized(dirty = "", dompurifyOption) {
11
13
  let clone = JSON.parse(JSON.stringify(dirty));
12
14
 
13
- if (typeof clone === "string") {
14
- clone = he.decode(dompurify.sanitize(dirty, dompurifyOption));
15
- } else if (clone instanceof Array) {
16
- for (let i = 0; i < clone.length; i++)
15
+ if (clone instanceof Array) {
16
+ for (let i = 0; i < clone.length; i++) {
17
17
  clone[i] = sanitized(clone[i], dompurifyOption);
18
+ }
18
19
  } else if (clone instanceof Object) {
19
- for (let key of Object.keys(clone))
20
+ for (let key of Object.keys(clone)) {
20
21
  clone[key] = sanitized(clone[key], dompurifyOption);
22
+ }
23
+ } else if (typeof clone === "string") {
24
+ clone = he.decode(dompurify.sanitize(dirty, dompurifyOption));
21
25
  }
22
26
 
23
27
  return clone;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanitized",
3
- "version": "1.1.9",
3
+ "version": "1.2.1",
4
4
  "description": "Recursive function that'll sanitize a string or ALL strings in a json input.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,8 +22,8 @@
22
22
  },
23
23
  "homepage": "https://github.com/nameer-rizvi/sanitized#readme",
24
24
  "dependencies": {
25
- "dompurify": "^3.0.3",
25
+ "dompurify": "^3.0.6",
26
26
  "he": "^1.2.0",
27
- "jsdom": "^22.0.0"
27
+ "jsdom": "22"
28
28
  }
29
29
  }