UNPKG

5.6 kBTypeScriptView Raw
1// Type definitions for Angular JS (ngSanitize module) 1.8
2// Project: http://angularjs.org
3// Definitions by: Diego Vilar <https://github.com/diegovilar>
4// Michał Lipiński <https://github.com/falsyvalues>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6// TypeScript Version: 2.3
7
8declare var _: string;
9export = _;
10
11import * as angular from 'angular';
12
13declare module 'angular' {
14 ///////////////////////////////////////////////////////////////////////////////
15 // ngSanitize module (angular-sanitize.js)
16 // see https://code.angularjs.org/1.7.0/docs/api/ngSanitize
17 ///////////////////////////////////////////////////////////////////////////////
18 namespace sanitize {
19 /**
20 * Sanitizes an html string by stripping all potentially dangerous tokens.
21 *
22 * The input is sanitized by parsing the HTML into tokens.
23 * All safe tokens (from a trusted list) are then serialized back to a properly
24 * escaped HTML string.
25 * This means that no unsafe input can make it into the returned string.
26 *
27 * URLs allowed in attribute values are configured using the methods aHrefSanitizationTrustedUrlList
28 * and imgSrcSanitizationTrustedUrlList of $compileProvider.
29 * The input may also contain SVG markup if this is enabled via $sanitizeProvider.
30 *
31 * @param html HTML input.
32 */
33 interface ISanitizeService {
34 (html: string): string;
35 }
36
37 /**
38 * Creates and configures $sanitize instance.
39 */
40 interface ISanitizeProvider {
41 /**
42 * Enables a subset of svg to be supported by the sanitizer.
43 *
44 * @see https://code.angularjs.org/1.7.0/docs/api/ngSanitize/provider/$sanitizeProvider#enableSvg
45 * @param flag Enable or disable SVG support in the sanitizer.
46 */
47 enableSvg(): boolean;
48 enableSvg(flag: boolean): ISanitizeProvider;
49 enableSvg(flag?: boolean): boolean | ISanitizeProvider;
50
51 /**
52 * Extends the built-in lists of valid HTML/SVG elements, i.e. elements that are considered safe and are not stripped off during sanitization.
53 *
54 * You can extend the following lists of elements:
55 * htmlElements: A list of elements (tag names) to extend the current list of safe HTML elements. HTML elements considered safe will not be removed during sanitization. All other elements will be stripped off.
56 * htmlVoidElements: This is similar to htmlElements, but marks the elements as "void elements" (similar to HTML void elements). These elements have no end tag and cannot have content.
57 * svgElements: This is similar to htmlElements, but for SVG elements. This list is only taken into account if SVG is enabled for $sanitize.
58 *
59 * @see https://code.angularjs.org/1.7.0/docs/api/ngSanitize/provider/$sanitizeProvider#addValidElements
60 * @param elements A list of valid HTML elements or an object with one or more of the following properties: htmlElements, htmlVoidElements, svgElements
61 */
62 addValidElements(elements: string[] | { htmlElements?: string[] | undefined; htmlVoidElements?: string[] | undefined; svgElements?: string[] | undefined }): ISanitizeProvider;
63
64 /**
65 * Extends the built-in list of valid attributes, i.e. attributes that are considered safe and are not stripped off during sanitization.
66 *
67 * Note: The new attributes will not be treated as URI attributes, which means their
68 * values will not be sanitized as URIs using $compileProvider's
69 * aHrefSanitizationTrustedUrlList and imgSrcSanitizationTrustedUrlList.
70 * @see https://code.angularjs.org/1.7.0/docs/api/ngSanitize/provider/$sanitizeProvider#addValidAttrs
71 * @param attrs A list of valid attributes.
72 */
73 addValidAttrs(attrs: string[]): ISanitizeProvider;
74 }
75
76 ///////////////////////////////////////////////////////////////////////////
77 // Filters included with the ngSanitize
78 // see https://github.com/angular/angular.js/tree/v1.2.0/src/ngSanitize/filter
79 ///////////////////////////////////////////////////////////////////////////
80 export namespace filter {
81 /**
82 * Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and plain email address links.
83 * @see https://code.angularjs.org/1.7.0/docs/api/ngSanitize/filter/linky
84 * @param text Input text.
85 * @param target ILinkyTargetType Window (_blank|_self|_parent|_top) or named frame to open links in.
86 * @param attributes Add custom attributes to the link element.
87 * @return Html-linkified and sanitized text.
88 */
89 interface ILinky {
90 (text: string, target?: string, attributes?: { [attribute: string]: string } | ((url: string) => { [attribute: string]: string })): string;
91 }
92 }
93
94 ///////////////////////////////////////////////////////////////////////////////
95 // Extend angular $filter declarations to include filters from angular.sanitize module
96 ///////////////////////////////////////////////////////////////////////////////
97 interface IFilterService {
98 (name: 'linky'): angular.sanitize.filter.ILinky;
99 }
100 }
101}
102
\No newline at end of file