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