https://github.com/p-baleine/white-list-sanitize
Sanitizer based on white list approach.
https://github.com/p-baleine/white-list-sanitize
Last synced: 4 months ago
JSON representation
Sanitizer based on white list approach.
- Host: GitHub
- URL: https://github.com/p-baleine/white-list-sanitize
- Owner: p-baleine
- Created: 2013-08-18T09:20:16.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-08-19T10:23:53.000Z (almost 12 years ago)
- Last Synced: 2024-10-18T20:49:30.140Z (9 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# white-list-sanitize [](https://travis-ci.org/p-baleine/white-list-sanitize)
Sanitizer based on white list approach.
This library based on darobin's [html-sanitiser](https://github.com/darobin/html-sanitiser) and also provide more controlled sanitize.
## API
Allowed elemtns and attributes can be specified via array.
```js
var sanitize = require('sanitize');var opts = {
allowedElements: ['a', 'h1'],
allowedAttributes: ['href']
};sanitize('Hoge', opts, function(err, result) {
console.log(result); // => Hoge
});
```Also these are specified via object for more controlled sanitize.
```js
var sanitize = require('sanitize');var input = [
'','
' ',
' ',
'
].join('');var opts = {
allowedElements: {
'div': true,
'iframe': {
only: function($elt) {
return $elt.attr('src').test(/^\/\/www\.youtube\.com\/embed\/[a-zA-Z0-9]+$/)
}
}
},
allowedAttributes: ['src']
};sanitize(input, opts, function(err, result) {
console.log(result); // =>
});
```