UNPKG

html-minifier

Version:

Highly effective, super-configurable, well-tested web page minifier

139 lines • 5.93 kB
/** * General utility functions */ /** * Stringify with sorted keys, for cache keys—values that can behave differently must not * stringify alike, so unquoted markers stand in for what JSON cannot express * @param {unknown} obj * @returns {string} */ declare function stableStringify(obj: unknown): string; declare class LRU { limit: number; gets: number; hits: number; /** @type {Map<string, unknown>} */ map: Map<string, unknown>; constructor(limit?: number); /** @param {string} key */ get(key: string): unknown; /** * @param {string} key * @param {unknown} value */ set(key: string, value: unknown): void; /** @param {string} key */ delete(key: string): void; /** @returns {{ gets: number, hits: number, size: number, limit: number }} */ stats(): { gets: number; hits: number; size: number; limit: number; }; } declare const MAX_CACHE_ENTRY_SIZE: number; /** @param {string} str */ declare function hashContent(str: string): string; /** @param {string} value */ declare function uniqueId(value: string): string; /** * Write decoded text or an attribute value for an XML parser to read it the same * @param {string} value - Text or attribute value, decoded * @param {boolean} [attribute] - Whether the value is an attribute value * @returns {string} */ declare function escapeXML(value: string, attribute?: boolean): string; /** * Script and style text as browsers read it, for code minifiers * @param {string} text */ declare function replaceNUL(text: string): string; /** * Read text in foreign content as HTML does: CDATA sections hold text as written, * while what surrounds them reads character references * @param {string} text * @param {(text: string) => string} decode - `decodeHTML` * @returns {string} */ declare function decodeForeignText(text: string, decode: (text: string) => string): string; /** @param {string} value */ declare function identity(value: string): string; /** * @param {unknown} value * @returns {value is PromiseLike<any>} */ declare function isThenable(value: unknown): value is PromiseLike<any>; /** @param {string} value */ declare function lowercase(value: string): string; /** @param {string} value */ declare function paramCase(value: string): string; /** * Asynchronously replace matches in a string. * @param {string} str - Input string * @param {RegExp} regex - Regular expression with global flag * @param {Function} asyncFn - Async function to process each match * @returns {Promise<string>} Processed string */ declare function replaceAsync(str: string, regex: RegExp, asyncFn: Function): Promise<string>; /** @param {string | RegExp} value */ declare function parseRegExp(value: string | RegExp): RegExp | undefined; /** * Which flag changes what a source matches, so that embedding the source where the * flag cannot follow would silently match something else. `u` and `v` only narrow * what syntax is legal, so a source valid under either stays valid without it—the * difference never surfaces as a syntax error, and this stands in for the one that * would otherwise be raised. * @param {RegExp} pattern * @returns {'u' | 'v' | 'm' | null} The flag the source depends on, or `null` where * every flag it carries would leave the source matching the same */ declare function lostFlag(pattern: RegExp): 'u' | 'v' | 'm' | null; /** * A pattern’s source, rewritten to match the way its own flags make it match, for * embedding in a larger regex that cannot carry them. `i` and `s` fit into a * source; `m`, `u`, and `v` do not, and are left to the pattern it joins. Where * `i` cannot be written in—a backreference, a range outside ASCII, a range that * spans letters without being one—the source stands as it is, matching less than * the pattern would rather than more. * @param {RegExp} pattern * @returns {string} */ declare function embedSource(pattern: RegExp): string; export type Repeat = { text: string; ranges: [number, number][] | null; }; /** * @param {RegExp | string} pattern - Pattern to judge, or a bare source to read * as it stands * @returns {string | null} What makes the pattern a backtracking risk, phrased * to follow the pattern itself, or `null` where it is none */ declare function describeQuantifierRisk(pattern: RegExp | string): string | null; /** @param {number} code */ declare function isWhitespaceCode(code: number): boolean; /** * Find the index of the `>` that closes an opening tag, correctly skipping * over quoted attribute values (which may contain `>`). * @param {string} html * @param {number} pos - Start position (just after the tag name) * @param {number} [limit] - Position to stop the search at (exclusive) * @returns {number} Index of the closing `>`, or -1 if not found */ declare function findTagEnd(html: string, pos: number, limit?: number): number; /** * A package that resolves but fails to load—e.g., a native binding built for * another platform—is not one another `npm install` fixes, so name what happened * rather than the install command * * @param {string} label - Minifier name as it should read in the message * @param {string} specifier - Package that failed to load * @param {unknown} cause - Error the import rejected with * @returns {string} Message describing the failure */ declare function describeDependencyFailure(label: string, specifier: string, cause: unknown): string; /** @param {string} doctype */ declare function isQuirksDoctype(doctype: string): boolean; export { stableStringify, findTagEnd, LRU, MAX_CACHE_ENTRY_SIZE, hashContent, uniqueId, escapeXML, replaceNUL, decodeForeignText, identity, isQuirksDoctype, isThenable, isWhitespaceCode, lowercase, paramCase, replaceAsync, parseRegExp, embedSource, lostFlag, describeQuantifierRisk, describeDependencyFailure }; //# sourceMappingURL=utils.d.ts.map