sanitized
Advanced tools
Comparing version 1.1.3 to 1.1.4
43
index.js
@@ -6,4 +6,2 @@ const DOMPurify = require("dompurify"); | ||
const logError = (error) => console.error("[sanitized] " + error.toString()); | ||
if (DOMPurify.sanitize) { | ||
@@ -19,11 +17,12 @@ sanitizer = (dirty, options) => decode(DOMPurify.sanitize(dirty, options)); | ||
} catch (error) { | ||
logError(error); | ||
console.error("[sanitized] " + error.toString()); | ||
} | ||
} | ||
function handleDirtyValue(dirty, DOMPurifyOptions) { | ||
if (dirty) { | ||
if (dirty.constructor === String) { | ||
function handleDirtyValue(dirty, DOMPurifyOptions, callback) { | ||
try { | ||
if (dirty && dirty.constructor === String) | ||
return sanitizer(dirty, DOMPurifyOptions); | ||
} else if (dirty.constructor === Array) { | ||
if (dirty && dirty.constructor === Array) { | ||
let clone = [].concat(dirty); | ||
@@ -34,19 +33,21 @@ for (let i = 0; i < clone.length; i++) { | ||
return clone; | ||
} else if (dirty.constructor === Object) { | ||
try { | ||
let clone = JSON.parse(JSON.stringify(dirty)); | ||
let cloneKeys = Object.keys(clone); | ||
for (let j = 0; j < cloneKeys.length; j++) { | ||
const cloneKey = cloneKeys[j]; | ||
clone[cloneKey] = handleDirtyValue(clone[cloneKey], DOMPurifyOptions); | ||
} | ||
return clone; | ||
} catch (error) { | ||
logError(error); | ||
return dirty; | ||
} | ||
if (dirty && dirty.constructor === Object) { | ||
let clone = JSON.parse(JSON.stringify(dirty)); | ||
let cloneKeys = Object.keys(clone); | ||
for (let j = 0; j < cloneKeys.length; j++) { | ||
const cloneKey = cloneKeys[j]; | ||
clone[cloneKey] = handleDirtyValue(clone[cloneKey], DOMPurifyOptions); | ||
} | ||
} else return dirty; | ||
} else return dirty; | ||
return clone; | ||
} | ||
return dirty; | ||
} catch (err) { | ||
if (callback) callback(err); | ||
return dirty; | ||
} | ||
} | ||
module.exports = handleDirtyValue; |
{ | ||
"name": "sanitized", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Recursive function that'll sanitize a string or ALL strings in an object or array.", | ||
@@ -25,6 +25,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"dompurify": "^2.2.8", | ||
"dompurify": "^2.2.9", | ||
"he": "^1.2.0", | ||
"jsdom": "^16.5.3" | ||
"jsdom": "^16.6.0" | ||
} | ||
} |
3038
43
Updateddompurify@^2.2.9
Updatedjsdom@^16.6.0