UNPKG

7.24 kBTypeScriptView Raw
1// Type definitions for html-minifier 4.0
2// Project: https://github.com/kangax/html-minifier, https://kangax.github.io/html-minifier
3// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
4// Piotr Błażejewicz <https://github.com/peterblazejewicz>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
7import * as UglifyJS from 'uglify-js';
8import * as CleanCSS from 'clean-css';
9import * as RelateUrl from 'relateurl';
10
11export function minify(text: string, options?: Options): string;
12
13export interface Options {
14 // Treat attributes in case sensitive manner (useful for custom HTML tags)
15 caseSensitive?: boolean | undefined;
16
17 // Omit attribute values from boolean attributes
18 collapseBooleanAttributes?: boolean | undefined;
19
20 // Don't leave any spaces between display:inline; elements when collapsing. Must be used in conjunction with collapseWhitespace=true
21 collapseInlineTagWhitespace?: boolean | undefined;
22
23 /**
24 * Collapse white space that contributes to text nodes in a document tree
25 * @see http://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace
26 */
27 collapseWhitespace?: boolean | undefined;
28
29 // Always collapse to 1 space (never remove it entirely). Must be used in conjunction with collapseWhitespace=true
30 conservativeCollapse?: boolean | undefined;
31 /**
32 * Handle parse errors instead of aborting
33 * @default false
34 */
35 continueOnParseError?: boolean | undefined;
36
37 // Arrays of regex'es that allow to support custom attribute assign expressions (e.g. '<div flex?="{{mode != cover}}"></div>')
38 customAttrAssign?: RegExp[] | undefined;
39
40 // Regex that specifies custom attribute to strip newlines from (e.g. /ng-class/)
41 customAttrCollapse?: RegExp | undefined;
42
43 // Arrays of regex'es that allow to support custom attribute surround expressions (e.g. <input {{#if value}}checked="checked"{{/if}}>)
44 customAttrSurround?: RegExp[] | undefined;
45
46 // Arrays of regex'es that allow to support custom event attributes for minifyJS (e.g. ng-click)
47 customEventAttributes?: RegExp[] | undefined;
48
49 // Use direct Unicode characters whenever possible
50 decodeEntities?: boolean | undefined;
51
52 // Parse input according to HTML5 specifications
53 html5?: boolean | undefined;
54
55 // Array of regex'es that allow to ignore certain comments, when matched
56 ignoreCustomComments?: RegExp[] | undefined;
57
58 // Array of regex'es that allow to ignore certain fragments, when matched (e.g. <?php ... ?>, {{ ... }}, etc.)
59 ignoreCustomFragments?: RegExp[] | undefined;
60
61 // Insert tags generated by HTML parser
62 includeAutoGeneratedTags?: boolean | undefined;
63
64 // Keep the trailing slash on singleton elements
65 keepClosingSlash?: boolean | undefined;
66
67 // Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points
68 maxLineLength?: number | undefined;
69
70 // Minify CSS in style elements and style attributes (uses clean-css or function specified)
71 minifyCSS?: boolean | CleanCSS.Options | ((text: string) => string) | undefined;
72
73 // Minify JavaScript in script elements and event attributes (uses UglifyJS or function specified)
74 minifyJS?: boolean | UglifyJS.MinifyOptions | ((text: string, inline: boolean) => string) | undefined;
75
76 // Minify URLs in various attributes (uses relateurl or function specified)
77 minifyURLs?: boolean | RelateUrl.Options | ((text: string) => string) | undefined;
78
79 // Always collapse to 1 line break (never remove it entirely) when whitespace between tags include a line break. Must be used in conjunction with collapseWhitespace=true
80 preserveLineBreaks?: boolean | undefined;
81
82 // Prevents the escaping of the values of attributes
83 preventAttributesEscaping?: boolean | undefined;
84
85 // Process contents of conditional comments through minifier
86 processConditionalComments?: boolean | undefined;
87
88 // Array of strings corresponding to types of script elements to process through minifier (e.g. text/ng-template, text/x-handlebars-template, etc.)
89 processScripts?: string[] | undefined;
90
91 // Type of quote to use for attribute values (' or ")
92 quoteCharacter?: string | undefined;
93
94 /**
95 * Remove quotes around attributes when possible
96 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_attribute_quotes
97 */
98 removeAttributeQuotes?: boolean | undefined;
99
100 /**
101 * Strip HTML comments
102 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_comments
103 */
104 removeComments?: boolean | undefined;
105
106 /**
107 * Remove all attributes with whitespace-only values
108 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_or_blank_attributes
109 */
110 removeEmptyAttributes?: boolean | ((attrName: string, tag: string) => boolean) | undefined;
111
112 /**
113 * Remove all elements with empty contents
114 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_elements
115 */
116 removeEmptyElements?: boolean | undefined;
117
118 /**
119 * Remove optional tags
120 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_optional_tags
121 */
122 removeOptionalTags?: boolean | undefined;
123
124 /**
125 * Remove attributes when value matches default.
126 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_redundant_attributes
127 */
128 removeRedundantAttributes?: boolean | undefined;
129
130 // Remove type="text/javascript" from script tags. Other type attribute values are left intact
131 removeScriptTypeAttributes?: boolean | undefined;
132
133 // Remove type="text/css" from style and link tags. Other type attribute values are left intact
134 removeStyleLinkTypeAttributes?: boolean | undefined;
135
136 // Remove space between attributes whenever possible. Note that this will result in invalid HTML!
137 removeTagWhitespace?: boolean | undefined;
138
139 /**
140 * Sort attributes by frequency
141 *
142 * Minifier options like sortAttributes and sortClassName won't impact the plain-text size
143 * of the output. However, they form long repetitive chains of characters that should improve
144 * compression ratio of gzip used in HTTP compression.
145 *
146 * @see https://github.com/kangax/html-minifier#sorting-attributes--style-classes
147 */
148 sortAttributes?: boolean | undefined;
149
150 /**
151 * Sort style classes by frequency
152 *
153 * Minifier options like sortAttributes and sortClassName won't impact the plain-text size
154 * of the output. However, they form long repetitive chains of characters that should improve
155 * compression ratio of gzip used in HTTP compression.
156 *
157 * @see https://github.com/kangax/html-minifier#sorting-attributes--style-classes
158 */
159 sortClassName?: boolean | undefined;
160
161 // Trim white space around ignoreCustomFragments
162 trimCustomFragments?: boolean | undefined;
163
164 /**
165 * Replaces the doctype with the short (HTML5) doctype
166 * @see http://perfectionkills.com/experimenting-with-html-minifier/#use_short_doctype
167 */
168 useShortDoctype?: boolean | undefined;
169}
170
\No newline at end of file