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

@ramstack/alpinegear-safehtml

v1.5.0

Published

@ramstack/alpinegear-safehtml provides the 'x-safehtml' Alpine.js directive for rendering HTML sanitized by DOMPurify.

Readme

@ramstack/alpinegear-safehtml

@ramstack/alpinegear-safehtml provides the x-safehtml Alpine.js directive. It renders reactive HTML after sanitizing it with DOMPurify.

Installation

Using CDN

Include the plugin before Alpine.js:

<script src="https://cdn.jsdelivr.net/npm/@ramstack/alpinegear-safehtml@1/alpinegear-safehtml.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3/dist/cdn.min.js" defer></script>

Using NPM

npm install --save @ramstack/alpinegear-safehtml
import Alpine from "alpinejs";
import safehtml from "@ramstack/alpinegear-safehtml";

Alpine.plugin(safehtml);
Alpine.start();

Usage

<div x-data="{ content: '<p>Hello <strong>world</strong></p>' }">
  <div x-safehtml="content"></div>
</div>

Whenever content changes, the directive sanitizes the new value before replacing the element's contents.

The sanitized content is treated as plain HTML. Each top-level element is marked with the current Alpine x-ignore attribute and ignored immediately, so Alpine does not initialize its subtree even if Alpine.initTree() is called later.

Attributes disallowed by DOMPurify are removed normally. If trusted configuration such as ADD_ATTR preserves an Alpine directive or a custom mapAttributes shorthand, x-ignore keeps it inert.

Configuration

Global DOMPurify options can be declared in a meta element:

<meta
  name="alpinegear-safehtml-options"
  content='{ "USE_PROFILES": { "html": true }, "FORBID_ATTR": ["style"] }'
>

Options for an individual element can be provided with data-safehtml-options:

<div
  x-safehtml="content"
  data-safehtml-options='{ "FORBID_TAGS": ["img"] }'
></div>

Both settings are static JSON objects read when the directive is initialized. Element options override global options using a shallow merge, so arrays and nested objects are replaced rather than combined.

[!WARNING] Configuration must come from trusted application markup. Options that change DOMPurify's return type (IN_PLACE, RETURN_DOM, and RETURN_DOM_FRAGMENT) are always disabled.

License

This package is released under the MIT License.