sanitized 1.2.3 → 1.2.5

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 (3) hide show
  1. package/README.md +7 -1
  2. package/index.js +17 -11
  3. package/package.json +4 -2
package/README.md CHANGED
@@ -6,8 +6,14 @@ It accepts two params the first being the value to sanitize, and the second bein
6
6
 
7
7
  ## Installation
8
8
 
9
+ ```console
10
+ npm i sanitized
9
11
  ```
10
- $ npm i sanitized
12
+
13
+ ### Node v16 Support
14
+
15
+ ```console
16
+ npm i sanitized@1.2.1
11
17
  ```
12
18
 
13
19
  ## Usage
package/index.js CHANGED
@@ -10,21 +10,27 @@ if (!dompurify.sanitize) {
10
10
  }
11
11
 
12
12
  function sanitized(dirty, dompurifyOption) {
13
- let clone = JSON.parse(JSON.stringify(dirty));
14
-
15
- if (clone instanceof Array) {
16
- for (let i = 0; i < clone.length; i++) {
17
- clone[i] = sanitized(clone[i], dompurifyOption);
13
+ if (Array.isArray(dirty)) {
14
+ for (let i = 0; i < dirty.length; i++) {
15
+ dirty[i] = sanitized(dirty[i], dompurifyOption);
18
16
  }
19
- } else if (clone instanceof Object) {
20
- for (let key of Object.keys(clone)) {
21
- clone[key] = sanitized(clone[key], dompurifyOption);
17
+ return dirty;
18
+ }
19
+
20
+ if (typeof dirty === "object") {
21
+ for (const key in dirty) {
22
+ if (dirty.hasOwnProperty(key)) {
23
+ dirty[key] = sanitized(dirty[key], dompurifyOption);
24
+ }
22
25
  }
23
- } else if (typeof clone === "string") {
24
- clone = he.decode(dompurify.sanitize(dirty, dompurifyOption));
26
+ return dirty;
27
+ }
28
+
29
+ if (typeof dirty === "string") {
30
+ return he.decode(dompurify.sanitize(dirty, dompurifyOption));
25
31
  }
26
32
 
27
- return clone;
33
+ return dirty;
28
34
  }
29
35
 
30
36
  module.exports = sanitized;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanitized",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
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": {},
@@ -15,7 +15,9 @@
15
15
  ],
16
16
  "author": "Nameer Rizvi (https://github.com/nameer-rizvi)",
17
17
  "license": "ISC",
18
- "bugs": "https://github.com/nameer-rizvi/sanitized/issues",
18
+ "bugs": {
19
+ "url": "https://github.com/nameer-rizvi/sanitized/issues"
20
+ },
19
21
  "homepage": "https://github.com/nameer-rizvi/sanitized#readme",
20
22
  "dependencies": {
21
23
  "dompurify": "^3.1.4",