From 3051b93e44c76235a5df0902371cdbf748e4f284 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Wed, 6 Jan 2016 17:22:22 +0100 Subject: [PATCH] Add definitions for HTMLMinifier (https://github.com/kangax/html-minifier) --- html-minifier/html-minifier-tests.ts | 9 +++ html-minifier/html-minifier.d.ts | 115 +++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 html-minifier/html-minifier-tests.ts create mode 100644 html-minifier/html-minifier.d.ts diff --git a/html-minifier/html-minifier-tests.ts b/html-minifier/html-minifier-tests.ts new file mode 100644 index 000000000..b02ecea19 --- /dev/null +++ b/html-minifier/html-minifier-tests.ts @@ -0,0 +1,9 @@ +/// + +import * as HTMLMinifier from 'html-minifier'; +const minify = HTMLMinifier.minify; + +var result = minify('

foo

', { + removeAttributeQuotes: true +}); +result; // '

foo

' diff --git a/html-minifier/html-minifier.d.ts b/html-minifier/html-minifier.d.ts new file mode 100644 index 000000000..9557de890 --- /dev/null +++ b/html-minifier/html-minifier.d.ts @@ -0,0 +1,115 @@ +// Type definitions for HTMLMinifier v1.1.1 +// Project: https://github.com/kangax/html-minifier +// Definitions by: Tanguy Krotoff +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// +/// + +declare module 'html-minifier' { + import * as UglifyJS from 'uglify-js'; + import * as CleanCSS from 'clean-css'; + import * as RelateUrl from 'relateurl'; + + 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; + + // Array of regex'es that allow to ignore certain fragments, when matched (e.g. , {{ ... }}, etc.) + ignoreCustomFragments?: Array; + + // 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; + + // 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. '
') + customAttrAssign?: Array; + + // Arrays of regex'es that allow to support custom attribute surround expressions (e.g. ) + customAttrSurround?: Array; + + // 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; +}