Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/p-baleine/white-list-sanitize
Sanitizer based on white list approach.
https://github.com/p-baleine/white-list-sanitize
Last synced: 21 days 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 (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-08-19T10:23:53.000Z (about 11 years ago)
- Last Synced: 2024-04-15T02:14:02.510Z (7 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 [![Build Status](https://travis-ci.org/p-baleine/white-list-sanitize.png?branch=master)](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); // =>
});
```