update html-minifier version to 3.5 (#21907)

* update html-minifier to v3

* sweep lint issues
This commit is contained in:
Riku
2018-01-03 04:08:33 +08:00
committed by Mohamed Hegazy
parent cd03f1cc14
commit 0d5e006750
7 changed files with 351 additions and 150 deletions

View File

@@ -1,8 +1,7 @@
import * as HTMLMinifier from 'html-minifier';
const minify = HTMLMinifier.minify;
var result = minify('<p title="blah" id="moo">foo</p>', {
const result = minify('<p title="blah" id="moo">foo</p>', {
removeAttributeQuotes: true
});
result; // '<p title=blah id=moo>foo</p>'

View File

@@ -1,111 +1,164 @@
// Type definitions for HTMLMinifier v1.1.1
// Type definitions for html-minifier 3.5
// Project: https://github.com/kangax/html-minifier
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
// Riku <https://github.com/rikuayanokozy>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="uglify-js" />
import * as UglifyJS from 'uglify-js';
import * as CleanCSS from 'clean-css';
import * as RelateUrl from 'relateurl';
declare namespace HTMLMinifier {
function minify(text: string, options?: Options): string;
export function minify(text: string, options?: Options): string;
interface Options {
// Strip HTML comments
removeComments?: boolean;
export interface Options {
// Treat attributes in case sensitive manner (useful for custom HTML tags)
caseSensitive?: boolean;
// Strip HTML comments from scripts and styles
removeCommentsFromCDATA?: boolean;
// Omit attribute values from boolean attributes
collapseBooleanAttributes?: boolean;
// Remove CDATA sections from script and style elements
removeCDATASectionsFromCDATA?: boolean;
// Don't leave any spaces between display:inline; elements when collapsing. Must be used in conjunction with collapseWhitespace=true
collapseInlineTagWhitespace?: boolean;
// Collapse white space that contributes to text nodes in a document tree
collapseWhitespace?: boolean;
/**
* Collapse white space that contributes to text nodes in a document tree
* @see http://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace
*/
collapseWhitespace?: boolean;
// Always collapse to 1 space (never remove it entirely). Must be used in conjunction with collapseWhitespace=true
conservativeCollapse?: boolean;
// Always collapse to 1 space (never remove it entirely). Must be used in conjunction with collapseWhitespace=true
conservativeCollapse?: boolean;
// Don't leave any spaces between display:inline; elements when collapsing. Must be used in conjunction with collapseWhitespace=true
collapseInlineTagWhitespace?: boolean;
// Arrays of regex'es that allow to support custom attribute assign expressions (e.g. '<div flex?="{{mode != cover}}"></div>')
customAttrAssign?: RegExp[];
// 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
preserveLineBreaks?: boolean;
// Regex that specifies custom attribute to strip newlines from (e.g. /ng-class/)
customAttrCollapse?: RegExp[];
// Omit attribute values from boolean attributes
collapseBooleanAttributes?: boolean;
// Arrays of regex'es that allow to support custom attribute surround expressions (e.g. <input {{#if value}}checked="checked"{{/if}}>)
customAttrSurround?: RegExp[];
// Remove quotes around attributes when possible
removeAttributeQuotes?: boolean;
// Arrays of regex'es that allow to support custom event attributes for minifyJS (e.g. ng-click)
customEventAttributes?: RegExp[];
// Remove attributes when value matches default
removeRedundantAttributes?: boolean;
// Use direct Unicode characters whenever possible
decodeEntities?: boolean;
// Prevents the escaping of the values of attributes.
preventAttributesEscaping?: boolean;
// Parse input according to HTML5 specifications
html5?: boolean;
// Replaces the doctype with the short (HTML5) doctype
useShortDoctype?: boolean;
// Array of regex'es that allow to ignore certain comments, when matched
ignoreCustomComments?: RegExp[];
// Remove all attributes with whitespace-only values
removeEmptyAttributes?: boolean;
// Array of regex'es that allow to ignore certain fragments, when matched (e.g. <?php ... ?>, {{ ... }}, etc.)
ignoreCustomFragments?: RegExp[];
// Remove type="text/javascript" from script tags. Other type attribute values are left intact.
removeScriptTypeAttributes?: boolean;
// Insert tags generated by HTML parser
includeAutoGeneratedTags?: boolean;
// Remove type="text/css" from style and link tags. Other type attribute values are left intact.
removeStyleLinkTypeAttributes?: boolean;
// Keep the trailing slash on singleton elements
keepClosingSlash?: boolean;
// Remove unrequired tags
removeOptionalTags?: boolean;
// Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points
maxLineLength?: number;
// Remove all elements with empty contents
removeEmptyElements?: boolean;
// Minify CSS in style elements and style attributes (uses clean-css or function specified)
minifyCSS?: boolean | CleanCSS.Options | ((text: string) => string);
// Toggle linting
lint?: boolean;
// Minify JavaScript in script elements and event attributes (uses UglifyJS or function specified)
minifyJS?: boolean | UglifyJS.MinifyOptions | ((text: string, inline: boolean) => string);
// Keep the trailing slash on singleton elements
keepClosingSlash?: boolean;
// Minify URLs in various attributes (uses relateurl or function specified)
minifyURLs?: boolean | RelateUrl.Options | ((text: string) => string);
// Treat attributes in case sensitive manner (useful for custom HTML tags.)
caseSensitive?: boolean;
// 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
preserveLineBreaks?: boolean;
// Minify Javascript in script elements and on* attributes (uses UglifyJS)
minifyJS?: boolean | UglifyJS.MinifyOptions;
// Prevents the escaping of the values of attributes
preventAttributesEscaping?: boolean;
// Minify CSS in style elements and style attributes (uses clean-css)
minifyCSS?: boolean | CleanCSS.Options;
// Process contents of conditional comments through minifier
processConditionalComments?: boolean;
// Minify URLs in various attributes (uses relateurl)
minifyURLs?: boolean | RelateUrl.Options;
// Array of strings corresponding to types of script elements to process through minifier (e.g. text/ng-template, text/x-handlebars-template, etc.)
processScripts?: string[];
// Array of regex'es that allow to ignore certain comments, when matched
ignoreCustomComments?: Array<RegExp>;
// Type of quote to use for attribute values (' or ")
quoteCharacter?: string;
// Array of regex'es that allow to ignore certain fragments, when matched (e.g. <?php ... ?>, {{ ... }}, etc.)
ignoreCustomFragments?: Array<RegExp>;
/**
* Remove quotes around attributes when possible
* @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_attribute_quotes
*/
removeAttributeQuotes?: boolean;
// Array of strings corresponding to types of script elements to process through minifier (e.g. text/ng-template, text/x-handlebars-template, etc.)
processScripts?: Array<string>;
/**
* Strip HTML comments
* @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_comments
*/
removeComments?: boolean;
// Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points
maxLineLength?: number;
/**
* Remove all attributes with whitespace-only values
* @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_or_blank_attributes
*/
removeEmptyAttributes?: boolean | ((attrName: string, tag: string) => boolean);
// Arrays of regex'es that allow to support custom attribute assign expressions (e.g. '<div flex?="{{mode != cover}}"></div>')
customAttrAssign?: Array<RegExp>;
/**
* Remove all elements with empty contents
* @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_elements
*/
removeEmptyElements?: boolean;
// Arrays of regex'es that allow to support custom attribute surround expressions (e.g. <input {{#if value}}checked="checked"{{/if}}>)
customAttrSurround?: Array<RegExp>;
/**
* Remove optional tags
* @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_optional_tags
*/
removeOptionalTags?: boolean;
// Regex that specifies custom attribute to strip newlines from (e.g. /ng\-class/)
customAttrCollapse?: RegExp;
/**
* Remove attributes when value matches default.
* @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_redundant_attributes
*/
removeRedundantAttributes?: boolean;
// Type of quote to use for attribute values (' or ")
quoteCharacter?: string;
}
// Remove type="text/javascript" from script tags. Other type attribute values are left intact
removeScriptTypeAttributes?: boolean;
// Remove type="text/css" from style and link tags. Other type attribute values are left intact
removeStyleLinkTypeAttributes?: boolean;
// Remove space between attributes whenever possible. Note that this will result in invalid HTML!
removeTagWhitespace?: boolean;
/**
* Sort attributes by frequency
*
* Minifier options like sortAttributes and sortClassName won't impact the plain-text size
* of the output. However, they form long repetitive chains of characters that should improve
* compression ratio of gzip used in HTTP compression.
*
* @see https://github.com/kangax/html-minifier#sorting-attributes--style-classes
*/
sortAttributes?: boolean;
/**
* Sort style classes by frequency
*
* Minifier options like sortAttributes and sortClassName won't impact the plain-text size
* of the output. However, they form long repetitive chains of characters that should improve
* compression ratio of gzip used in HTTP compression.
*
* @see https://github.com/kangax/html-minifier#sorting-attributes--style-classes
*/
sortClassName?: boolean;
// Trim white space around ignoreCustomFragments
trimCustomFragments?: boolean;
/**
* Replaces the doctype with the short (HTML5) doctype
* @see http://perfectionkills.com/experimenting-with-html-minifier/#use_short_doctype
*/
useShortDoctype?: boolean;
}
export = HTMLMinifier;

View File

@@ -1,79 +1,3 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
"extends": "dtslint/dt.json"
}

View File

@@ -0,0 +1,8 @@
import * as HTMLMinifier from 'html-minifier';
const minify = HTMLMinifier.minify;
var result = minify('<p title="blah" id="moo">foo</p>', {
removeAttributeQuotes: true
});
result; // '<p title=blah id=moo>foo</p>'

111
types/html-minifier/v1/index.d.ts vendored Normal file
View File

@@ -0,0 +1,111 @@
// Type definitions for HTMLMinifier v1.1.1
// Project: https://github.com/kangax/html-minifier
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="uglify-js" />
import * as UglifyJS from 'uglify-js';
import * as CleanCSS from 'clean-css';
import * as RelateUrl from 'relateurl';
declare namespace HTMLMinifier {
function minify(text: string, options?: Options): string;
interface Options {
// Strip HTML comments
removeComments?: boolean;
// Strip HTML comments from scripts and styles
removeCommentsFromCDATA?: boolean;
// Remove CDATA sections from script and style elements
removeCDATASectionsFromCDATA?: boolean;
// Collapse white space that contributes to text nodes in a document tree
collapseWhitespace?: boolean;
// Always collapse to 1 space (never remove it entirely). Must be used in conjunction with collapseWhitespace=true
conservativeCollapse?: boolean;
// Don't leave any spaces between display:inline; elements when collapsing. Must be used in conjunction with collapseWhitespace=true
collapseInlineTagWhitespace?: boolean;
// 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
preserveLineBreaks?: boolean;
// Omit attribute values from boolean attributes
collapseBooleanAttributes?: boolean;
// Remove quotes around attributes when possible
removeAttributeQuotes?: boolean;
// Remove attributes when value matches default
removeRedundantAttributes?: boolean;
// Prevents the escaping of the values of attributes.
preventAttributesEscaping?: boolean;
// Replaces the doctype with the short (HTML5) doctype
useShortDoctype?: boolean;
// Remove all attributes with whitespace-only values
removeEmptyAttributes?: boolean;
// Remove type="text/javascript" from script tags. Other type attribute values are left intact.
removeScriptTypeAttributes?: boolean;
// Remove type="text/css" from style and link tags. Other type attribute values are left intact.
removeStyleLinkTypeAttributes?: boolean;
// Remove unrequired tags
removeOptionalTags?: boolean;
// Remove all elements with empty contents
removeEmptyElements?: boolean;
// Toggle linting
lint?: boolean;
// Keep the trailing slash on singleton elements
keepClosingSlash?: boolean;
// Treat attributes in case sensitive manner (useful for custom HTML tags.)
caseSensitive?: boolean;
// Minify Javascript in script elements and on* attributes (uses UglifyJS)
minifyJS?: boolean | UglifyJS.MinifyOptions;
// Minify CSS in style elements and style attributes (uses clean-css)
minifyCSS?: boolean | CleanCSS.Options;
// Minify URLs in various attributes (uses relateurl)
minifyURLs?: boolean | RelateUrl.Options;
// Array of regex'es that allow to ignore certain comments, when matched
ignoreCustomComments?: Array<RegExp>;
// Array of regex'es that allow to ignore certain fragments, when matched (e.g. <?php ... ?>, {{ ... }}, etc.)
ignoreCustomFragments?: Array<RegExp>;
// Array of strings corresponding to types of script elements to process through minifier (e.g. text/ng-template, text/x-handlebars-template, etc.)
processScripts?: Array<string>;
// Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points
maxLineLength?: number;
// Arrays of regex'es that allow to support custom attribute assign expressions (e.g. '<div flex?="{{mode != cover}}"></div>')
customAttrAssign?: Array<RegExp>;
// Arrays of regex'es that allow to support custom attribute surround expressions (e.g. <input {{#if value}}checked="checked"{{/if}}>)
customAttrSurround?: Array<RegExp>;
// Regex that specifies custom attribute to strip newlines from (e.g. /ng\-class/)
customAttrCollapse?: RegExp;
// Type of quote to use for attribute values (' or ")
quoteCharacter?: string;
}
}
export = HTMLMinifier;

View File

@@ -0,0 +1,27 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"paths": {
"html-minifier": ["html-minifier/v1"],
"html-minifier/*": ["html-minifier/v1/*"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"html-minifier-tests.ts"
]
}

View File

@@ -0,0 +1,79 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
}