27
27
* @returns {element is X }
28
28
*/
29
29
30
+ /**
31
+ * Check if a node is an element and passes a certain node test
32
+ *
33
+ * @callback AssertAnything
34
+ * @param {unknown } [node]
35
+ * @param {number } [index]
36
+ * @param {Parent } [parent]
37
+ * @returns {boolean }
38
+ */
39
+
30
40
/**
31
41
* Check if a node is an element and passes a certain node test
32
42
*
@@ -46,7 +56,7 @@ export const isElement =
46
56
*
47
57
* @type {(
48
58
* (<T extends Element>(node: unknown, test: T['tagName']|TestFunctionPredicate<T>|Array.<T['tagName']|TestFunctionPredicate<T>>, index?: number, parent?: Parent, context?: unknown) => node is T) &
49
- * ((node?: unknown, test?: null|undefined|TagName|TestFunctionAnything|Array.<TagName|TestFunctionAnything>, index?: number, parent?: Parent, context?: unknown) => node is Element )
59
+ * ((node?: unknown, test?: null|undefined|TagName|TestFunctionAnything|Array.<TagName|TestFunctionAnything>, index?: number, parent?: Parent, context?: unknown) => boolean )
50
60
* )}
51
61
*/
52
62
(
@@ -107,7 +117,7 @@ export const convertElement =
107
117
/**
108
118
* @type {(
109
119
* (<T extends Element>(test: T['tagName']|TestFunctionPredicate<T>) => AssertPredicate<T>) &
110
- * ((test?: null|undefined|TagName|TestFunctionAnything|Array.<TagName|TestFunctionAnything>) => AssertPredicate<Element> )
120
+ * ((test?: null|undefined|TagName|TestFunctionAnything|Array.<TagName|TestFunctionAnything>) => AssertAnything )
111
121
* )}
112
122
*/
113
123
(
@@ -119,7 +129,7 @@ export const convertElement =
119
129
* When `function` checks if function passed the node is true.
120
130
* When `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
121
131
* When `array`, checks any one of the subtests pass.
122
- * @returns {AssertPredicate<Element> }
132
+ * @returns {AssertAnything }
123
133
*/
124
134
function ( test ) {
125
135
if ( test === undefined || test === null ) {
@@ -144,10 +154,10 @@ export const convertElement =
144
154
145
155
/**
146
156
* @param {Array.<TagName|TestFunctionAnything> } tests
147
- * @returns {AssertPredicate<Element> }
157
+ * @returns {AssertAnything }
148
158
*/
149
159
function anyFactory ( tests ) {
150
- /** @type {Array.<AssertPredicate<Element> > } */
160
+ /** @type {Array.<AssertAnything > } */
151
161
var checks = [ ]
152
162
var index = - 1
153
163
@@ -160,7 +170,7 @@ function anyFactory(tests) {
160
170
/**
161
171
* @this {unknown}
162
172
* @param {unknown[] } parameters
163
- * @returns {node is Element }
173
+ * @returns {boolean }
164
174
*/
165
175
function any ( ...parameters ) {
166
176
var index = - 1
@@ -180,14 +190,14 @@ function anyFactory(tests) {
180
190
* name for said string.
181
191
*
182
192
* @param {TagName } check
183
- * @returns {AssertPredicate<Element> }
193
+ * @returns {AssertAnything }
184
194
*/
185
195
function tagNameFactory ( check ) {
186
196
return tagName
187
197
188
198
/**
189
199
* @param {Node } node
190
- * @returns {node is Element }
200
+ * @returns {boolean }
191
201
*/
192
202
function tagName ( node ) {
193
203
return element ( node ) && node . tagName === check
@@ -196,7 +206,7 @@ function tagNameFactory(check) {
196
206
197
207
/**
198
208
* @param {TestFunctionAnything } check
199
- * @returns {AssertPredicate<Element> }
209
+ * @returns {AssertAnything }
200
210
*/
201
211
function castFactory ( check ) {
202
212
return assertion
@@ -205,7 +215,7 @@ function castFactory(check) {
205
215
* @this {unknown}
206
216
* @param {Node } node
207
217
* @param {Array.<unknown> } parameters
208
- * @returns {node is Element }
218
+ * @returns {boolean }
209
219
*/
210
220
function assertion ( node , ...parameters ) {
211
221
return element ( node ) && Boolean ( check . call ( this , node , ...parameters ) )
@@ -215,7 +225,7 @@ function castFactory(check) {
215
225
/**
216
226
* Utility to return true if this is an element.
217
227
* @param {unknown } node
218
- * @returns {node is Element }
228
+ * @returns {boolean }
219
229
*/
220
230
function element ( node ) {
221
231
return Boolean (
0 commit comments