html-minifier
Version:
Highly effective, super-configurable, well-tested web page minifier
109 lines • 4.83 kB
TypeScript
/**
* HTML attribute parsing, decoding, and minification
*/
import type { ProcessedOptions } from './options.js';
export type HTMLAttribute = {
name: string;
value?: string | undefined;
quote?: string;
customAssign?: string;
customOpen?: string;
customClose?: string;
};
/**
* @param {string} text
* @param {ProcessedOptions} options
*/
declare function isIgnoredComment(text: string, options: ProcessedOptions): boolean;
/**
* Remove duplicate attributes from an attribute list.
* Per HTML spec, when an attribute appears multiple times, the first occurrence wins.
* Duplicate attributes result in invalid HTML, so only the first is kept.
* @param {HTMLAttribute[]} attrs - Array of attribute objects with `name` property
* @param {boolean} caseSensitive - Whether to compare names case-sensitively (for XML/SVG)
* @returns {HTMLAttribute[]} Deduplicated attribute array (modifies in place and returns)
*/
declare function deduplicateAttributes(attrs: HTMLAttribute[], caseSensitive: boolean): HTMLAttribute[];
declare function isClassicScriptType(attrValue?: string): boolean;
/**
* @param {string} tag
* @param {HTMLAttribute[]} attrs
*/
declare function isExecutableScript(tag: string, attrs: HTMLAttribute[]): boolean;
declare function isStyleLinkTypeAttribute(attrValue?: string): boolean;
/**
* @param {string} tag
* @param {HTMLAttribute[]} attrs
*/
declare function isStyleElement(tag: string, attrs: HTMLAttribute[]): boolean;
/**
* Whether a `meta` element has no effect in any current browser, holding no more than the
* `http-equiv` or `name` that says so, and `content`
* @param {HTMLAttribute[]} attrs - Deduplicated
* @param {string[]} markers - What custom fragment and `htmlmin:ignore` placeholders hold
*/
declare function isMetaWithoutEffect(attrs: HTMLAttribute[], markers: string[]): boolean;
/**
* Replace a `meta` element’s `http-equiv=Content-Type` and `content` with the `charset` they
* declare, which browsers read the same
* @param {HTMLAttribute[]} attrs - Deduplicated; changed in place
* @param {string[]} markers - What custom fragment and `htmlmin:ignore` placeholders hold
*/
declare function replaceContentTypePragma(attrs: HTMLAttribute[], markers: string[]): void;
/**
* The name to write and to hand to hooks: as in the source for HTML names under
* `caseSensitive`, as named otherwise (foreign names are named as written anyway)
* @param {HTMLAttribute} attr
* @param {string} attrName
* @param {ProcessedOptions} options
*/
declare function nameAttrOut(attr: HTMLAttribute, attrName: string, options: ProcessedOptions): string;
/**
* Whether `removeEmptyAttributes` removes the attribute
* @param {string} tag
* @param {string} attrName
* @param {string | undefined} attrValue
* @param {ProcessedOptions} options
* @param {string} [tagOut]
* @param {string} [attrNameOut]
*/
declare function removesEmptyAttribute(tag: string, attrName: string, attrValue: string | undefined, options: ProcessedOptions, tagOut?: string, attrNameOut?: string): any;
/**
* @param {string} name
* @param {HTMLAttribute[]} attrs
*/
declare function hasAttrName(name: string, attrs: HTMLAttribute[]): boolean;
/**
* @param {HTMLAttribute} attr
* @param {HTMLAttribute[]} attrs
* @param {string} tag
* @param {string} tagOut - The tag name as written, for hooks
* @param {ProcessedOptions} options
* @param {Function} minifyHTML
* @param {string[]} [markers] - What custom fragment and `htmlmin:ignore` placeholders hold
*/
declare function normalizeAttr(attr: HTMLAttribute, attrs: HTMLAttribute[], tag: string, tagOut: string, options: ProcessedOptions, minifyHTML: Function, markers?: string[]): Promise<{
attr: HTMLAttribute;
name: string;
value: string | undefined;
} | undefined> | {
attr: HTMLAttribute;
name: string;
value: string | undefined;
} | undefined;
/**
* @param {{name: string, value: string | undefined, attr: HTMLAttribute}} normalized
* @param {string} tag
* @param {string | boolean | undefined} hasUnarySlash
* @param {ProcessedOptions} options
* @param {boolean} isLast
* @param {string | undefined} uidAttr
* @param {string[]} markers - What custom fragment and `htmlmin:ignore` placeholders hold
*/
declare function buildAttr(normalized: {
name: string;
value: string | undefined;
attr: HTMLAttribute;
}, tag: string, hasUnarySlash: string | boolean | undefined, options: ProcessedOptions, isLast: boolean, uidAttr: string | undefined, markers: string[]): string;
export { isIgnoredComment, isExecutableScript, isClassicScriptType, isStyleElement, isStyleLinkTypeAttribute, isMetaWithoutEffect, hasAttrName, nameAttrOut, removesEmptyAttribute, normalizeAttr, buildAttr, deduplicateAttributes, replaceContentTypePragma };
//# sourceMappingURL=attributes.d.ts.map