Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sanitized

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sanitized - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

sanitizer.js

65

index.js

@@ -1,53 +0,28 @@

const he = require("he");
const DOMPurify = require("dompurify");
const sanitizer = require("./sanitizer");
module.exports = value => {
function sanitizeStr(str) {
return str ? sanitized(str).trim() : "";
}
function sanitizeArr(arr) {
var clone = [].concat(arr);
clone.forEach((item, index) => {
clone[index] = module.exports(item);
});
return clone;
}
function sanitizeObj(obj) {
var clone = JSON.parse(JSON.stringify(obj));
for (const prop in clone) {
clone[prop] = module.exports(clone[prop]);
}
return clone;
}
module.exports = (value) => {
const handlers = {
string: (str) => (str ? sanitizer(str).trim() : ""),
array: (arr) => {
var clone = [].concat(arr);
clone.forEach((item, index) => (clone[index] = module.exports(item)));
return clone;
},
object: (obj) => {
var clone = JSON.parse(JSON.stringify(obj));
Object.keys(clone).forEach(
(key) => (clone[key] = module.exports(clone[key]))
);
return clone;
},
};
return value
? value.constructor === String
? sanitizeStr(value)
? handlers.string(value)
: value.constructor === Array
? sanitizeArr(value)
? handlers.array(value)
: value.constructor === Object
? sanitizeObj(value)
? handlers.object(value)
: value
: value;
};
function sanitized(value) {
return DOMPurify.sanitize
? he.decode(DOMPurify.sanitize(value))
: jsdom({ createDOMPurify: DOMPurify, value });
}
function jsdom({ createDOMPurify, value }) {
const { JSDOM } = require("jsdom");
const window = new JSDOM("").window;
const DOMPurify = createDOMPurify(window);
return he.decode(DOMPurify.sanitize(value));
}
{
"name": "sanitized",
"version": "1.0.3",
"version": "1.0.4",
"description": "Recursive function that'll sanitize a string or ALL values in an object or array.",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc