Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jill64/universal-sanitizer
💎 Isomorphic html sanitizer by DOMPurify + sanitize-html
https://github.com/jill64/universal-sanitizer
dom html isomorphic sanitizer xss
Last synced: 3 months ago
JSON representation
💎 Isomorphic html sanitizer by DOMPurify + sanitize-html
- Host: GitHub
- URL: https://github.com/jill64/universal-sanitizer
- Owner: jill64
- License: mit
- Created: 2023-12-03T13:17:11.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-27T23:16:40.000Z (8 months ago)
- Last Synced: 2024-05-28T08:38:23.002Z (8 months ago)
- Topics: dom, html, isomorphic, sanitizer, xss
- Language: TypeScript
- Homepage: https://npmjs.com/package/@jill64/universal-sanitizer
- Size: 209 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @jill64/universal-sanitizer
💎 Isomorphic html sanitizer by DOMPurify + sanitize-html
## Installation
```sh
npm i @jill64/universal-sanitizer
```## Usage
Conditional Export applies the appropriate file at each runtime.
```js
import { sanitize } from '@jill64/universal-sanitizer'const cleaned = sanitize(/* ... */, {
// options: {
// sanitizeHtml: sanitize-html options
// dompurify: DOMPurify options
// }
})
```| condition | resolve |
| --------- | ------------------------------------------------------------------------ |
| `browser` | [`DOMPurify`](https://github.com/cure53/DOMPurify#readme) |
| `default` | [`sanitize-html`](https://github.com/apostrophecms/sanitize-html#readme) |
| `worker` | [`sanitize-html`](https://github.com/apostrophecms/sanitize-html#readme) |## Add DOMPurify hook
The hook is executed before sanitize
```js
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](LICENSE)