@jill64/universal-sanitizer

💎 Isomorphic html sanitizer by DOMPurify + sanitize-html
Installation
npm i @jill64/universal-sanitizer
Usage
Conditional Export applies the appropriate file at each runtime.
import { sanitize } from '@jill64/universal-sanitizer'
const cleaned = sanitize(/* ... */, {
// options: {
// sanitizeHtml: sanitize-html options
// dompurify: DOMPurify options
// }
})
Add DOMPurify hook
The hook is executed before sanitize
import { sanitize } from '@jill64/universal-sanitizer'
const cleaned = sanitize(/* ... */, {
options: {
hook: (DOMPurify) => {
DOMPurify.addHook(
'uponSanitizeAttribute',
function (currentNode, hookEvent, config) {
// Do something with the current node
// You can also mutate hookEvent for current node (i.e. set hookEvent.forceKeepAttr = true)
// For other than 'uponSanitizeAttribute' hook types hookEvent equals to null
}
)
}
}
})
License
MIT