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 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, and the second being options to pass to [DOMPurify](https://github.com/kkomelin/isomorphic-dompurify).
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
@@ -1,4 +1,3 @@
1
- declare function sanitized(dirty: any, DOMPurifyOptions: {
2
- [key: string]: any;
3
- }): any;
1
+ import DOMPurify from "isomorphic-dompurify";
2
+ declare function sanitized(input: any, options?: DOMPurify.Config): any;
4
3
  export = sanitized;
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
- function sanitized(dirty, DOMPurifyOptions) {
8
- if (Array.isArray(dirty)) {
9
- for (let i = 0; i < dirty.length; i++) {
10
- dirty[i] = sanitized(dirty[i], DOMPurifyOptions);
11
- }
12
- return dirty;
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 dirty === "object") {
15
- for (const key in dirty) {
16
- if (dirty.hasOwnProperty(key)) {
17
- dirty[key] = sanitized(dirty[key], DOMPurifyOptions);
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 dirty === "string") {
23
- return he_1.default.decode(isomorphic_dompurify_1.default.sanitize(dirty, DOMPurifyOptions));
20
+ if (typeof input === "string") {
21
+ return he_1.default.decode(isomorphic_dompurify_1.default.sanitize(input, options));
24
22
  }
25
- return dirty;
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.6",
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.16.0",
31
- "jsdom": "^25.0.1"
30
+ "isomorphic-dompurify": "^2.35.0"
32
31
  },
33
32
  "devDependencies": {
34
- "@types/node": "^22.7.4",
33
+ "@types/node": "^25.0.3",
35
34
  "ts-node": "^10.9.2",
36
- "typescript": "^5.6.2"
35
+ "typescript": "^5.9.3"
37
36
  }
38
37
  }