forked from emberjs/ember-test-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
-target.ts
39 lines (33 loc) · 1.01 KB
/
-target.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
type Target = string | Element | Document | Window;
export default Target;
export interface HTMLElementContentEditable extends HTMLElement {
isContentEditable: true;
}
// eslint-disable-next-line require-jsdoc
export function isElement(target: unknown): target is Element {
return (
target !== null &&
typeof target === 'object' &&
Reflect.get(target, 'nodeType') === Node.ELEMENT_NODE
);
}
// eslint-disable-next-line require-jsdoc
export function isWindow(target: Target): target is Window {
return target instanceof Window;
}
// eslint-disable-next-line require-jsdoc
export function isDocument(target: unknown): target is Document {
return (
target !== null &&
typeof target === 'object' &&
Reflect.get(target, 'nodeType') === Node.DOCUMENT_NODE
);
}
// eslint-disable-next-line require-jsdoc
export function isContentEditable(
element: Element
): element is HTMLElementContentEditable {
return (
'isContentEditable' in element && (element as HTMLElement).isContentEditable
);
}