-
Notifications
You must be signed in to change notification settings - Fork 42
/
api.ts
39 lines (34 loc) · 1.1 KB
/
api.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
export { nodesFromString } from "./deserialize.ts";
export * from "./dom/node.ts";
export * from "./dom/element.ts";
export * from "./dom/document.ts";
export * from "./dom/dom-parser.ts";
export { NodeListPublic as NodeList } from "./dom/node-list.ts";
export { HTMLCollectionPublic as HTMLCollection } from "./dom/html-collection.ts";
import { NodeList } from "./dom/node-list.ts";
import { HTMLCollection } from "./dom/html-collection.ts";
// Prevent childNodes and HTMLCollections from being seen as an arrays
const oldHasInstance = Array[Symbol.hasInstance];
Object.defineProperty(Array, Symbol.hasInstance, {
value(value: any): boolean {
switch (value?.constructor) {
case HTMLCollection:
case NodeList:
return false;
default:
return oldHasInstance.call(this, value);
}
},
});
const oldIsArray = Array.isArray;
Object.defineProperty(Array, "isArray", {
value: (value: any): boolean => {
switch (value?.constructor) {
case HTMLCollection:
case NodeList:
return false;
default:
return oldIsArray.call(Array, value);
}
},
});