universal-dompurify

1.0.11Β β€’Β PublicΒ β€’Β Published

universal-dompurify

npm-version npm-license npm-download-month npm-min-size

πŸ’Ž Use DOMPurify for some context by conditional exports

Installation

npm i universal-dompurify

Usage

Conditional exports apply the appropriate DOMPurify file at each run.

import DOMPurify from 'universal-dompurify'

const cleaned = DOMPurify.sanitize(/* ... */)
condition resolve
browser DOMPurify
default DOMPurify + JSDOM
worker DOMPurify + JSDOM + (require: your external node polyfills)

[!TIP] It is generally not recommended to use JSDOM with the restricted Edge runtime.
See also @jill64/universal-sanitizer for a more lightweight alternative.

Browser Only Mode

Reduces bundle size by omitting rendering on the server.

/** @type {DOMPurify | null} */
import DOMPurify from 'universal-dompurify/browser-only'

const cleaned = DOMPurify?.sanitize?.(/* ... */) ?? 'server-fallback-value'
condition resolve
browser DOMPurify
default null
worker null

License

MIT

/universal-dompurify/

    Package Sidebar

    Install

    npm i universal-dompurify

    Weekly Downloads

    1,099

    Version

    1.0.11

    License

    MIT

    Unpacked Size

    5.8 kB

    Total Files

    11

    Last publish

    Collaborators

    • jill64