Files
js-xss/lib/index.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-02-13 14:58:36 +08:00
/**
2017-12-21 14:19:10 +08:00
* xss
2014-02-13 14:58:36 +08:00
*
2017-12-21 14:19:10 +08:00
* @author Zongmin Lei<leizongmin@gmail.com>
2014-02-13 14:58:36 +08:00
*/
2017-12-21 14:22:34 +08:00
var DEFAULT = require("./default");
var parser = require("./parser");
var FilterXSS = require("./xss");
2014-02-13 14:58:36 +08:00
/**
2017-12-21 14:19:10 +08:00
* filter xss function
2014-02-13 14:58:36 +08:00
*
2017-12-21 14:19:10 +08:00
* @param {String} html
* @param {Object} options { whiteList, onTag, onTagAttr, onIgnoreTag, onIgnoreTagAttr, safeAttrValue, escapeHtml }
2014-02-13 14:58:36 +08:00
* @return {String}
*/
2017-12-21 14:22:34 +08:00
function filterXSS(html, options) {
2014-02-13 14:58:36 +08:00
var xss = new FilterXSS(options);
return xss.process(html);
}
exports = module.exports = filterXSS;
2019-03-20 14:07:13 +08:00
exports.filterXSS = filterXSS;
2014-02-13 14:58:36 +08:00
exports.FilterXSS = FilterXSS;
2022-03-09 19:39:57 +08:00
for (let i in DEFAULT) exports[i] = DEFAULT[i];
for (let i in parser) exports[i] = parser[i];
2014-02-13 14:58:36 +08:00
2017-12-21 14:19:10 +08:00
// using `xss` on the browser, output `filterXSS` to the globals
2017-12-21 14:22:34 +08:00
if (typeof window !== "undefined") {
2014-02-13 14:58:36 +08:00
window.filterXSS = module.exports;
}
// using `xss` on the WebWorker, output `filterXSS` to the globals
function isWorkerEnv() {
return (
typeof self !== "undefined" &&
typeof DedicatedWorkerGlobalScope !== "undefined" &&
self instanceof DedicatedWorkerGlobalScope
);
}
if (isWorkerEnv()) {
self.filterXSS = module.exports;
}