Skip to content

jill64/universal-dompurify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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