Installing
NPM
$ npm install xss
Bower
$ bower install xss
Or
$ bower install https://github.com/leizongmin/js-xss.git
Usages
Node.js
var xss = require('xss');
var html = xss('<script>alert("xss");</script>');
console.log(html);
Browser
Shim mode (reference file test/test.html
):
<script src="https://raw.github.com/leizongmin/js-xss/master/dist/xss.js"></script>
<script>
// apply function filterXSS in the same way
var html = filterXSS('<script>alert("xss");</scr' + 'ipt>');
alert(html);
</script>
AMD mode (reference file test/test_amd.html
):
<script>
require.config({
baseUrl: './'
})
require(['xss'], function (xss) {
var html = xss('<script>alert("xss");</scr' + 'ipt>');
alert(html);
});
</script>