Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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.

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); // =>


});
```