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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ampersand-sanitized-html-data-type

v0.2.2

Published

This module implements an isomorphic sanitized HTML data type for [Ampersand.js][]. On the server, [Google's Gumbo HTML parser][gumbo] is used to parse and sanitize the HTML data. In the browser, the sanitized value is used when rendering user-generated c

Readme

Sanitized HTML data type for Ampersand

This module implements an isomorphic sanitized HTML data type for Ampersand.js. On the server, Google's Gumbo HTML parser is used to parse and sanitize the HTML data. In the browser, the sanitized value is used when rendering user-generated content.

In a typical use case, a user submits HTML to the server. The server then parses and sanitizes the HTML to return to the client. The client implementation then renders the sanitized HTML. To avoid XSS attacks, even from the same user that generated the HTML content, care must be taken to only trust server-sanitized HTML.

The security of the data type is dependent on the underlying libraries used to parse and sanitize the HTML:

Security reviews and code contributions are welcome.

Install

npm install --save ampersand-sanitized-html-data-type

Usage

var Model = require("ampersand-model");
var htmlMixin = require("ampersand-sanitized-html-data-type");

module.exports = Model.extend(htmlMixin, {
  props: {
    body: "html"
  }
});

Alternatively, you may also define the data type under a different name:

var Model = require("ampersand-model");
var htmlMixin = require("ampersand-sanitized-html-data-type");

module.exports = Model.extend(htmlMixin, {
  dataTypes: {
    sanitizedHtml: htmlMixin.dataTypes.html
  },
  props: {
    body: "sanitizedHtml"
  }
});

To use different options for Gumbo Sanitize, pass the appropriate string. The supported values are "STRICT", "BASIC", and "RELAXED":

var Model = require("ampersand-model");
var htmlMixin = require("ampersand-sanitized-html-data-type")("RELAXED");

To provide custom options to Gumbo Sanitize, you may pass an object:

var Model = require("ampersand-model");
var htmlMixin = require("ampersand-sanitized-html-data-type")({
  secret: "xyzzy",
  elements: ["i"]
});

The configuration object is deterministically serialized and its SHA-1 hash is used as the SHA-1 HMAC key for signing the raw HTML. The cryptographic signature allows us to cache the sanitized HTML in the database while still allowing updates to the sanitization options to re-sanitize the raw HTML on read. The secret option "salts" the cryptographic signature to thward scenarios in which the attacker has compromised the application database. Configuration options are ignored on the client.

License

MIT