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

@humanspeak/svelte-purify

v0.0.6

Published

Safe HTML rendering for Svelte powered by DOMPurify. SSR-ready, browser-only entry, and edge-friendly options.

Readme

@humanspeak/svelte-purify

A tiny, friendly sanitizer for Svelte that keeps your HTML shiny and safe using DOMPurify. SSR-ready by default.

NPM version Build Status Coverage Status License Downloads CodeQL Install size Code Style: Trunk TypeScript Types Maintenance

Features

  • 🚀 Fast and tiny: DOMPurify under the hood, minimal wrapper
  • 🔒 XSS protection: strips scripts, unsafe URLs, and sneaky attributes
  • 🧰 Options passthrough: you control DOMPurify via options
  • 🧭 SSR-ready: default component works on server and client
  • 🧪 Tested: unit tests with Vitest/JSDOM
  • 🧑‍💻 Full TypeScript: proper types for options and props
  • 🧿 Svelte 5 runes-friendly: clean, modern Svelte API

Installation

npm i -S @humanspeak/svelte-purify
# or
pnpm add @humanspeak/svelte-purify
# or
yarn add @humanspeak/svelte-purify

Basic Usage

Default

<script lang="ts">
    import { SveltePurify } from '@humanspeak/svelte-purify'

    const html = `<p>Hello <strong>world</strong><script>alert(1)</script></p>`
</script>

<SveltePurify {html} />

Limit output length

<SveltePurify {html} maxLength={120} />

Render hooks (preHtml/postHtml)

You can render UI before and after the sanitized HTML. Each hook receives the sanitized HTML length as a number.

<script lang="ts">
    import { SveltePurify } from '@humanspeak/svelte-purify'
    const html = `<p><strong>Hello</strong> world!</p>`
</script>

<SveltePurify
    {html}
    preHtml={(len) => <>Sanitized length: {len}</>}
    postHtml={(len) => <> • {len} chars</>}
/>

Options (DOMPurify)

Pass any DOMPurify.sanitize options. We don’t hide anything—use the full power of DOMPurify.

<script lang="ts">
    import { SveltePurify } from '@humanspeak/svelte-purify'

    const html = `<a href="javascript:alert(1)" title="nope">click me</a>`
    const options = {
        ALLOWED_TAGS: ['a'],
        ALLOWED_ATTR: ['href', 'title']
    }
</script>

<SveltePurify {html} {options} />

Note: The component returns sanitized HTML as a string (not DOM nodes).

Props

| Component | Prop | Type | Description | | -------------- | ----------- | ------------------------------------------ | ---------------------------------------------- | | SveltePurify | html | string | Raw HTML to sanitize and render | | | options | Parameters<typeof DOMPurify.sanitize>[1] | DOMPurify options (all supported) | | | maxLength | number | If set, truncates the sanitized HTML string | | | preHtml | Snippet<[number]> | Renders before HTML; receives sanitized length | | | postHtml | Snippet<[number]> | Renders after HTML; receives sanitized length |

Exports

import { SveltePurify } from '@humanspeak/svelte-purify'
  • SveltePurify: SSR-friendly sanitizer component

Security

This library delegates sanitization to DOMPurify, a battle-tested sanitizer. It removes script tags, event handler attributes (like onerror), and unsafe URLs (javascript:), among many other protections.

Examples

Strip a specific tag with DOMPurify options:

<SveltePurify html="<p>Hello <strong>world</strong></p>" options={{ FORBID_TAGS: ['strong'] }} />

Allow an extra tag:

<SveltePurify
    html="<iframe src=\"about:blank\"></iframe>"
    options={{ ADD_TAGS: ['iframe'] }}
/>

License

MIT © Humanspeak, Inc.

Credits

Made with ❤️ by Humanspeak

Special thanks to @jill64 — her years of Svelte contributions taught me so much and inspired this work.