feat(typings): add global XSS namespace

This commit is contained in:
Zongmin Lei
2019-03-21 10:58:56 +08:00
parent 75c7868e3e
commit 1317bb05c6
2 changed files with 120 additions and 102 deletions

View File

@@ -6,7 +6,7 @@
* @author Zongmin Lei<leizongmin@gmail.com>
*/
import xss = require("xss");
import * as xss from "xss";
const x = new xss.FilterXSS();
@@ -37,7 +37,7 @@ xss.filterXSS("hello", {
onIgnoreTag(tag, html) {}
});
interface ICustomWhiteList extends xss.IWhiteList {
interface ICustomWhiteList extends XSS.IWhiteList {
view?: string[];
}
@@ -47,3 +47,5 @@ whiteList.view = ["class", "style", "id"];
console.log(whiteList);
filterXSS("hello");
const options: XSS.IFilterXSSOptions = {};

42
typings/xss.d.ts vendored
View File

@@ -6,9 +6,9 @@
declare global {
function filterXSS(html: string, options?: IFilterXSSOptions): string;
}
export interface IFilterXSSOptions {
namespace XSS {
export interface IFilterXSSOptions {
whiteList?: IWhiteList;
onTag?: OnTagHandler;
onTagAttr?: OnTagAttrHandler;
@@ -21,9 +21,9 @@ export interface IFilterXSSOptions {
allowCommentTag?: boolean;
stripBlankChar?: boolean;
css?: {} | boolean;
}
}
export interface IWhiteList {
interface IWhiteList {
a?: string[];
abbr?: string[];
address?: string[];
@@ -87,34 +87,50 @@ export interface IWhiteList {
u?: string[];
ul?: string[];
video?: string[];
}
}
export type OnTagHandler = (
type OnTagHandler = (
tag: string,
html: string,
options: {}
) => string | void;
) => string | void;
export type OnTagAttrHandler = (
type OnTagAttrHandler = (
tag: string,
name: string,
value: string,
isWhiteAttr: boolean
) => string | void;
) => string | void;
export type SafeAttrValueHandler = (
type SafeAttrValueHandler = (
tag: string,
name: string,
value: string,
cssFilter: ICSSFilter
) => string;
) => string;
export type EscapeHandler = (str: string) => string;
type EscapeHandler = (str: string) => string;
export interface ICSSFilter {
interface ICSSFilter {
process(value: string): string;
}
}
}
export interface IFilterXSSOptions extends XSS.IFilterXSSOptions {}
export interface IWhiteList extends XSS.IWhiteList {}
export type OnTagHandler = XSS.OnTagHandler;
export type OnTagAttrHandler = XSS.OnTagAttrHandler;
export type SafeAttrValueHandler = XSS.SafeAttrValueHandler;
export type EscapeHandler = XSS.EscapeHandler;
export interface ICSSFilter extends XSS.ICSSFilter {}
export function StripTagBody(
tags: string[],
next: () => void