UNPKG

3.04 kBTypeScriptView Raw
1/**
2 * @typedef IgnoreAttributesForTags
3 * @property {string[]} tags tags on which to ignore the given attributes
4 * @property {string[]} attributes attributes to ignore for the given tags
5 */
6/**
7 * @typedef DiffOptions
8 * @property {(string | IgnoreAttributesForTags)[]} [ignoreAttributes]
9 * array of attributes to ignore, when given a string that attribute will be ignored on all tags
10 * when given an object of type `IgnoreAttributesForTags`, you can specify on which tags to ignore which attributes
11 * @property {string[]} [ignoreTags] array of tags to ignore, these tags are stripped from the output
12 * @property {string[]} [ignoreChildren] array of tags whose children to ignore, the children of
13 * these tags are stripped from the output
14 * @property {string[]} [stripEmptyAttributes] array of attributes which should be removed when empty.
15 * Be careful not to add any boolean attributes here (e.g. `hidden`) unless you know what you're doing
16 */
17/**
18 * Restructures given HTML string, returning it in a format which can be used for comparison:
19 * - whitespace and newlines are normalized
20 * - tags and attributes are printed on individual lines
21 * - comments, style, script and svg tags are removed
22 * - additional tags and attributes can optionally be ignored
23 *
24 * See README.md for details.
25 *
26 * @example
27 * import getDiffableHTML from '@open-wc/semantic-dom-diff';
28 *
29 * const htmlA = getDiffableHTML(`... some html ...`, { ignoredAttributes: [], ignoredTags: [], ignoreChildren: [] });
30 * const htmlB = getDiffableHTML(`... some html ...`);
31 *
32 * // use regular string comparison to spot the differences
33 * expect(htmlA).to.equal(htmlB);
34 *
35 * @param {Node | string} html
36 * @param {DiffOptions} [options]
37 * @returns {string} html restructured in a diffable format
38 */
39export function getDiffableHTML(html: Node | string, options?: DiffOptions): string;
40/**
41 * @param {*} arg
42 * @return {arg is DiffOptions}
43 */
44export function isDiffOptions(arg: any): arg is DiffOptions;
45export type IgnoreAttributesForTags = {
46 /**
47 * tags on which to ignore the given attributes
48 */
49 tags: string[];
50 /**
51 * attributes to ignore for the given tags
52 */
53 attributes: string[];
54};
55export type DiffOptions = {
56 /**
57 * array of attributes to ignore, when given a string that attribute will be ignored on all tags
58 * when given an object of type `IgnoreAttributesForTags`, you can specify on which tags to ignore which attributes
59 */
60 ignoreAttributes?: (string | IgnoreAttributesForTags)[];
61 /**
62 * array of tags to ignore, these tags are stripped from the output
63 */
64 ignoreTags?: string[];
65 /**
66 * array of tags whose children to ignore, the children of
67 * these tags are stripped from the output
68 */
69 ignoreChildren?: string[];
70 /**
71 * array of attributes which should be removed when empty.
72 * Be careful not to add any boolean attributes here (e.g. `hidden`) unless you know what you're doing
73 */
74 stripEmptyAttributes?: string[];
75};