npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

html-sanitizer-p5

v1.0.2

Published

A simple HTML sanitizer built on parse5

Readme

html-sanitizer-p5

html-sanitizer-p5 is a simple HTML sanitizer built on parse5.

html-sanitizer-p5 allows you to specify HTML tags and attributes that you want to keep. If a tag or attribute is not allowed, it is deleted. Tag contents are preserved subject to options.

href attributes are validated to ensure they only contain http, https, ftp and mailto URLs. Relative URLs are also allowed. You can also limit src domains for iframes.

HTML comments are preserved by default. You can change this behavior by setting the option keepComments to false.

Requirements

html-sanitizer-p5 is a pure Javascript module with only one dependency on parse5.

Install

npm install html-sanitizer-p5

Usage

var sanitizer = require('html-sanitizer-p5');

/* Santize HTML fragments typically submitted by WYSIWYG editors like tinyMCE */
var html = '<div class="p-1"><script src="http://malicious.org"></script></div>';
var clean = sanitizer.sanitize(html);

That will allow the default list of allowed tags and attributes. You can override default behavior as follows:

// Allow only a restricted set of tags and attributes
clean = sanitizer.sanitize(html, {
  allowedTags: [ 'h4', 'p', 'br' ],
  allowedAttributes: {
    'a': [ 'href' ]
  },
  allowedIframeDomains: ['www.youtube.com']
});

Options

  • allowedTags - Array of tag names. Specify false to allow everything and [] to allow nothing.
  • allowedAttributes - Object that specifies allowed attributes for one more tags. Use '*' to specify attributes that are allowed on any element. For example:
{ 
  '*': ['class', 'style'], 
  'img': ['src']
} 
  • allowedIframeDomains - Array of domains that can appear as iframe source
  • allowedUrlSchemes - Array of URL schemes that are allowed in href attribute of links
  • keepComments - Specify false to remove comments

Defaults

Default option values are available via properties of the sanitizer object with the same name. For example sanitizer.allowedTags returns default array of allowed tags.

{
  allowedTags: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul',
  'ol', 'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'code', 'hr', 'br', 'div',
  'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'span', 'img', 'iframe' ],
  allowedAttributes: {
    '*': ['class', 'style'],
    a: [ 'href', 'name', 'target' ],
    img: [ 'src' ],
    iframe: ['src']
  },
  allowedIframeDomains: ['www.youtube.com', 'player.vimeo.com'],
  allowedUrlSchemes: [ 'http', 'https', 'ftp', 'mailto' ],
}