universal-dompurify
![npm-min-size](https://img.shields.io/bundlephobia/min/universal-dompurify)
💎 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.
import DOMPurify from 'universal-dompurify/browser-only'
const cleaned = DOMPurify?.sanitize?.() ?? 'server-fallback-value'
condition | resolve |
---|
browser | DOMPurify |
default | null |
worker | null |
License
MIT