sanitized 1.1.7 → 1.1.8

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 +18 -34
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,42 +1,26 @@
1
- const DOMPurify = require("dompurify");
1
+ let dompurify = require("dompurify");
2
2
  const he = require("he");
3
3
 
4
- let sanitizer = (dirty) => dirty;
5
-
6
- if (DOMPurify.sanitize) {
7
- sanitizer = (dirty, options) => he.decode(DOMPurify.sanitize(dirty, options));
8
- } else {
9
- try {
10
- const jsdom = require("jsdom");
11
- const JSDOM = new jsdom.JSDOM("<!DOCTYPE html>");
12
- const DOMPurifyWindow = DOMPurify(JSDOM.window);
13
- sanitizer = (dirty, options) =>
14
- he.decode(DOMPurifyWindow.sanitize(dirty, options));
15
- } catch (error) {
16
- console.error(error);
17
- }
4
+ if (!dompurify.sanitize) {
5
+ const jsdom = require("jsdom");
6
+ const jsdomWindow = new jsdom.JSDOM("").window;
7
+ dompurify = dompurify(jsdomWindow);
18
8
  }
19
9
 
20
- function sanitized(dirty, DOMPurifyOptions, errorCallback) {
21
- try {
22
- let clone = JSON.parse(JSON.stringify(dirty));
23
-
24
- if (typeof clone === "string") clone = sanitizer(clone, DOMPurifyOptions);
25
-
26
- if (clone instanceof Array)
27
- for (let i = 0; i < clone.length; i++)
28
- clone[i] = sanitized(clone[i], DOMPurifyOptions);
29
-
30
- if (clone instanceof Object)
31
- for (let cloneKey of Object.keys(clone))
32
- clone[cloneKey] = sanitized(clone[cloneKey], DOMPurifyOptions);
33
-
34
- return clone;
35
- } catch (err) {
36
- if (errorCallback) errorCallback(err);
37
-
38
- return dirty;
10
+ function sanitized(dirty = "", dompurifyOption) {
11
+ let clone = JSON.parse(JSON.stringify(dirty));
12
+
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++)
17
+ clone[i] = sanitized(clone[i], dompurifyOption);
18
+ } else if (clone instanceof Object) {
19
+ for (let key of Object.keys(clone))
20
+ clone[key] = sanitized(clone[key], dompurifyOption);
39
21
  }
22
+
23
+ return clone;
40
24
  }
41
25
 
42
26
  module.exports = sanitized;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanitized",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
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": "^2.3.6",
25
+ "dompurify": "^2.4.3",
26
26
  "he": "^1.2.0",
27
- "jsdom": "^19.0.0"
27
+ "jsdom": "^21.0.0"
28
28
  }
29
29
  }