-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
117 lines (104 loc) · 2.66 KB
/
types.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* @file Library TypeScript Declarations
*/
/**
* Map of HTML attribute names and values.
*
* A primitive interpretation of
* {@link https://developer.mozilla.org/en-US/docs/Web/API/NamedNodeMap `NamedNodeMap`}
* and {@link https://developer.mozilla.org/en-US/docs/Web/API/Attr `Attr`}.
*
* @typedef {Object<AttrName, unknown>} AttrMap
*/
export type AttrMap = Record<AttrName, unknown>;
/**
* Compares attributes to sort.
*
* @callback AttrMapComparator
*
* @param {AttrPair} a
* @param {AttrPair} b
* @returns {number}
*/
export type AttrMapComparator = (a: AttrPair, b: AttrPair) => number;
/**
* An attribute name.
*
* @typedef {string} AttrName
*/
export type AttrName = string;
/**
* An HTML attribute name or pattern for sorting.
*
* @typedef {AttrName|RegExp} AttrOrder
*/
export type AttrOrder = AttrName | RegExp;
/**
* Pair of an HTML attribute's name and value.
*
* @typedef {[ AttrName, unknown? ]} AttrPair
*/
export type AttrPair = [ AttrName, unknown? ];
/**
* A filtered attribute value.
*
* Either:
*
* - `string`: Should render attribute.
* - `true`: Should render attribute.
* - `false`: Should reject attribute.
*
* @typedef {string|boolean} AttrValue
*/
export type AttrValue = string | boolean;
/**
* Converts special characters to their corresponding HTML entities.
*
* @callback AttrValueEscaper
*
* @param {string} value
* @param {AttrName} [name]
* @returns {string}
*/
export type AttrValueEscaper = (value: string, name?: AttrName) => string;
/**
* Approves, rejects, and parses a value for an HTML attribute.
*
* @callback AttrValueFilter
*
* @param {*} value
* @param {?AttrName} [name]
* @param {?AttrValueFilterFallback} [fallback]
* @returns {AttrValue}
*/
export type AttrValueFilter = (value: unknown, name?: AttrName, fallback?: AttrValueFilterFallback) => AttrValue;
/**
* A fallback filter function or attribute value.
*
* @typedef {AttrValueFilter|AttrValue} AttrValueFilterFallback
*/
export type AttrValueFilterFallback = AttrValueFilter | AttrValue;
/**
* An HTML attribute value separator.
*
* @typedef {string} AttrValueSeparator
*/
export type AttrValueSeparator = string;
/**
* Map of HTML attribute names and separator strings.
*
* @typedef {Object<AttrName, string>} AttrValueSeparatorMap
*/
export type AttrValueSeparatorMap = Record<AttrName, AttrValueSeparator>;
/**
* Map of characters to entities.
*
* @typedef {Object<string, string>} HTMLCharEscapeMap
*/
export type HTMLCharEscapeMap = Record<string, string>;
/**
* Either null or undefined.
*
* @typedef {null|undefined} Nil
*/
export type Nil = null | undefined;