sanitized 1.2.6 → 1.2.7
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 +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +15 -17
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
sanitized() is a recursive function that'll sanitize a string or ALL strings in a json input. It's great for sanitizing form data before it gets submitted to the back-end (re: protection against XSS attacks).
|
|
4
4
|
|
|
5
|
-
It accepts two params the first being the value to sanitize
|
|
5
|
+
It accepts two params the first being the value to sanitize and the second being options to pass to [DOMPurify](https://github.com/kkomelin/isomorphic-dompurify).
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,26 +2,24 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
-
const isomorphic_dompurify_1 = __importDefault(require("isomorphic-dompurify"));
|
|
6
5
|
const he_1 = __importDefault(require("he"));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const isomorphic_dompurify_1 = __importDefault(require("isomorphic-dompurify"));
|
|
7
|
+
function sanitized(input, options = {}) {
|
|
8
|
+
if (Array.isArray(input)) {
|
|
9
|
+
const results = [];
|
|
10
|
+
for (const item of input)
|
|
11
|
+
results.push(sanitized(item, options));
|
|
12
|
+
return results;
|
|
13
13
|
}
|
|
14
|
-
if (typeof
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return dirty;
|
|
14
|
+
if (input !== null && typeof input === "object") {
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const [key, value] of Object.entries(input))
|
|
17
|
+
result[key] = sanitized(value, options);
|
|
18
|
+
return result;
|
|
21
19
|
}
|
|
22
|
-
if (typeof
|
|
23
|
-
return he_1.default.decode(isomorphic_dompurify_1.default.sanitize(
|
|
20
|
+
if (typeof input === "string") {
|
|
21
|
+
return he_1.default.decode(isomorphic_dompurify_1.default.sanitize(input, options));
|
|
24
22
|
}
|
|
25
|
-
return
|
|
23
|
+
return input;
|
|
26
24
|
}
|
|
27
25
|
module.exports = sanitized;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanitized",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "Recursive function that'll sanitize a string or ALL strings in a json input.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,12 +27,11 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@types/he": "^1.2.3",
|
|
29
29
|
"he": "^1.2.0",
|
|
30
|
-
"isomorphic-dompurify": "^2.
|
|
31
|
-
"jsdom": "^25.0.1"
|
|
30
|
+
"isomorphic-dompurify": "^2.35.0"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
|
-
"@types/node": "^
|
|
33
|
+
"@types/node": "^25.0.3",
|
|
35
34
|
"ts-node": "^10.9.2",
|
|
36
|
-
"typescript": "^5.
|
|
35
|
+
"typescript": "^5.9.3"
|
|
37
36
|
}
|
|
38
37
|
}
|