From 71b9e552eab0e66ccb1385babb2f2b95e73afcb1 Mon Sep 17 00:00:00 2001 From: Rogier Schouten Date: Sat, 14 Feb 2015 21:31:41 +0100 Subject: [PATCH] Add typings for sanitize-html --- CONTRIBUTORS.md | 1 + sanitize-html/sanitize-html-tests.ts | 33 ++++++++++++++++++++++++++++ sanitize-html/sanitize-html.d.ts | 27 +++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 sanitize-html/sanitize-html-tests.ts create mode 100644 sanitize-html/sanitize-html.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 60ef278e8d..23aebd9a59 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -619,6 +619,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](rx/rx.virtualtime.d.ts) [RxJS-VirtualTime](http://rx.codeplex.com) by [gsino](http://www.codeplex.com/site/users/view/gsino), [Igor Oleinikov](https://github.com/Igorbek) * [:link:](sammyjs/sammyjs.d.ts) [Sammy.js](http://sammyjs.org) by [Boris Yankov](https://github.com/borisyankov), [Oisin Grehan](https://github.com/oising) * [:link:](sanitize-filename/sanitize-filename.d.ts) [sanitize-filename](https://github.com/parshap/node-sanitize-filename) by [Wim Looman](https://github.com/Nemo157) +* [:link:](sanitize-html/sanitize-html.d.ts) [sanitize-html](https://github.com/punkave/sanitize-html) by [rogierschouten](https://github.com/rogierschouten) * [:link:](screenfull/screenfull.d.ts) [screenfull.js](https://github.com/sindresorhus/screenfull.js) by [Ilia Choly](http://github.com/icholy) * [:link:](select2/select2.d.ts) [Select2](http://ivaynberg.github.com/select2) by [Boris Yankov](https://github.com/borisyankov) * [:link:](selectize/selectize.d.ts) [Selectize](https://github.com/brianreavis/selectize.js) by [Adi Dahiya](https://github.com/adidahiya) diff --git a/sanitize-html/sanitize-html-tests.ts b/sanitize-html/sanitize-html-tests.ts new file mode 100644 index 0000000000..22811faac5 --- /dev/null +++ b/sanitize-html/sanitize-html-tests.ts @@ -0,0 +1,33 @@ +/// + +import sanitizeHtml = require('sanitize-html'); + +var s: string; +var t: string; + +t = sanitizeHtml(s); +t = sanitizeHtml(s, { +}); +t = sanitizeHtml(s, { + allowedTags: ["a", "br"], + allowedSchemes: ["http"], + allowedAttributes: { "a": ["href"] }, + allowedClasses: { "a": ["someclass"] }, + transformTags: { + "a": "b", + "br": function(tagName: string, attributes: {[index: string]: string}): { tagName: string; attributes: {[index: string]: string};} { + return { tagName: tagName, attributes: attributes }; + } + }, + exclusiveFilter: { + "a": function(frame: { + tag: string; + attribs: { [index: string]: string }; + text: string; + tagPosition: number; + }): boolean { + return false; + } + } +}); + diff --git a/sanitize-html/sanitize-html.d.ts b/sanitize-html/sanitize-html.d.ts new file mode 100644 index 0000000000..1875eedab1 --- /dev/null +++ b/sanitize-html/sanitize-html.d.ts @@ -0,0 +1,27 @@ +// Type definitions for sanitize-html 1.6.0 +// Project: https://github.com/punkave/sanitize-html +// Definitions by: Rogier Schouten +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +declare module "sanitize-html" { + + function sanitizeHtml(s: string, opts?: { + allowedTags?: string[]; + allowedSchemes?: string[]; + allowedAttributes?: { [index: string]: string[] }; + allowedClasses?: { [index: string]: string[] }; + transformTags?: { [index: string]: any }; + exclusiveFilter?: { + [index: string]: (frame: { + tag: string; + attribs: { [index: string]: string }; + text: string; + tagPosition: number; + }) => boolean + }; + + }): string; + + export = sanitizeHtml; +}