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

@types/sanitize-html

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/sanitize-html

TypeScript definitions for sanitize-html

  • 2.9.0
  • ts4.2
  • ts4.3
  • ts4.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
increased by12.24%
Maintainers
1
Weekly downloads
 
Created

What is @types/sanitize-html?

@types/sanitize-html provides TypeScript type definitions for the sanitize-html library, which is used to sanitize HTML input by removing potentially dangerous elements and attributes.

What are @types/sanitize-html's main functionalities?

Basic HTML Sanitization

This feature allows you to sanitize a string of HTML by removing any potentially dangerous elements like <script> tags.

const sanitizeHtml = require('sanitize-html');
const dirty = '<script>alert("xss")</script><div>Safe content</div>';
const clean = sanitizeHtml(dirty);
console.log(clean); // Output: <div>Safe content</div>

Customizing Allowed Tags and Attributes

This feature allows you to specify which HTML tags and attributes are allowed in the sanitized output.

const sanitizeHtml = require('sanitize-html');
const dirty = '<a href="http://example.com" onclick="stealCookies()">Click me</a>';
const clean = sanitizeHtml(dirty, {
  allowedTags: [ 'a' ],
  allowedAttributes: {
    'a': [ 'href' ]
  }
});
console.log(clean); // Output: <a href="http://example.com">Click me</a>

Transforming Tags

This feature allows you to transform specific tags in the HTML input, such as changing the src attribute of img tags.

const sanitizeHtml = require('sanitize-html');
const dirty = '<img src="http://example.com/image.jpg" />';
const clean = sanitizeHtml(dirty, {
  transformTags: {
    'img': sanitizeHtml.simpleTransform('img', { 'src': 'https://example.com/placeholder.jpg' })
  }
});
console.log(clean); // Output: <img src="https://example.com/placeholder.jpg">

Other packages similar to @types/sanitize-html

FAQs

Package last updated on 14 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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