ember-dompurify
Installation
ember i ember-dompurify
Helper usage
Basic
Returns an htmlSafe string:
<img src="x">
Advanced
import { Transform } from 'ember-dompurify';
class AttributeBlankTransform extends Transform {
afterSanitizeAttributes(node) {
if ('target' in node) {
node.setAttribute('target', '_blank');
}
}
}
export default Component.extend({
AttributeBlankTransform
});
Result:
<a src="https://google.com" target="_blank">Link</a>
API
import createDOMPurify from 'ember-dompurify';
const dompurify = createDOMPurify(window);
dompurify.sanitize('<img src="x" onerror=alert(1)/>'); // -> type: String, result: `<img src="x">`
Options
Contributing
Installation
git clone <repository-url>
cd ember-dompurify
npm install
Linting
npm run lint:js
npm run lint:js -- --fix
Running tests
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"npm test
– Runsember try:each
to test your addon against multiple Ember versions
Running the dummy application
ember serve
- Visit the dummy application at http://localhost:4200.
For more information on using ember-cli, visit https://ember-cli.com/.
License
This project is licensed under the MIT License