Add support for typescript #60

Open
rasaturyan opened this Issue Oct 21, 2016 · 5 comments

Projects

None yet

3 participants

@rasaturyan

No description provided.

@leizongmin
Owner

Hi, I don't have any experience in TypeScript. Could you please send me a pull request?

@leizongmin leizongmin reopened this Nov 17, 2016
@leizongmin
Owner
leizongmin commented Nov 17, 2016 edited

I just publish a new version xss@0.3.1, add typings support for TypeScript 2.0.

Install the latest version and try this sample code:

import xss = require('xss');

const x = new xss.FilterXSS();

x.process('html');

const a = xss.StripTagBody([], () => {});
console.log(a.onIgnoreTag, a.remove);

console.log(xss('hello'));
console.log(xss('hello', {
  onTag(tag: string, html: string, options: {}): string {
    return html;
  },
  css: false,
}));


interface ICustomWhiteList extends XSS.IWhiteList {
  view?: string[];
}

const whiteList: ICustomWhiteList = xss.getDefaultWhiteList();
console.log(whiteList.abbr);
whiteList.view = [ 'class', 'style', 'id' ];
console.log(whiteList);

If any question please let me know.

@caliber01

Hello, thanks for adding TypeScript support, I am running the latest release and have a trouble with the typings. I am using TypeScript@2.0.9 with the following tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist/",
    "module": "commonjs",
    "noImplicitAny": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "target": "es5",
    "jsx": "react",
    "noUnusedLocals": true,
    "noUnusedParameters": true
  }
}

and I have these compile errors:

Error in [default] .../node_modules/xss/typings/xss.d.ts:106:4
'onIgnoreTag', which lacks return-type annotation, implicitly has an 'any' return type.

Error in [default] .../node_modules/xss/typings/xss.d.ts:122:147
Cannot find name 'EscapeHandler'.
@leizongmin leizongmin added a commit that closed this issue Dec 2, 2016
@leizongmin fix #60 typings 6313322
@leizongmin leizongmin closed this in 6313322 Dec 2, 2016
@leizongmin
Owner

I just fix some typings problem, please try the newest version xss@0.3.2

@leizongmin leizongmin reopened this Dec 2, 2016
@caliber01

Yes, now everything is fine, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment