Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        

# @jill64/universal-sanitizer

npm-version npm-license npm-download-month npm-min-size ci.yml

💎 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)