sanitized 1.1.7 → 1.1.9
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/index.js +18 -34
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,42 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
let dompurify = require("dompurify");
|
|
2
2
|
const he = require("he");
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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.
|
|
3
|
+
"version": "1.1.9",
|
|
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": "^
|
|
25
|
+
"dompurify": "^3.0.3",
|
|
26
26
|
"he": "^1.2.0",
|
|
27
|
-
"jsdom": "^
|
|
27
|
+
"jsdom": "^22.0.0"
|
|
28
28
|
}
|
|
29
29
|
}
|