Socket
Book a DemoInstallSign in
Socket

browser-sanitize-html

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-sanitize-html

Sanitize html, for browser environments

latest
Source
npmnpm
Version
0.0.0
Version published
Maintainers
1
Created
Source

browser-sanitize-html

Sanitize html, for browser environments.

Example

Allow only divs and clear style attributes:

var sanitize = require('browser-sanitize-html');
var domify = require('domify');

var dirty = domify('<div><span></span><div style="foo:bar"></div></div>');
var clean = sanitize(dirty, function(el) {
  if (el.tagName != 'DIV') return false;
  el.setAttribute('style', null);
});
console.log(clean);
// => <div><div></div><div>

Installation

Install with npm

npm install browser-sanitize-html

and bundle with browserify.

API

var clean = sanitize(dirty, filter)

Sanitize dirty dom through your provided filter function. The return value will be null, one Element or a Fragment, depending on which Elements matched.

When filter returns false for an element it will be removed from the result set. You can also modify nodes you want to keep on the fly.

License

MIT.

Keywords

sanitize

FAQs

Package last updated on 08 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts