forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis-context.js
More file actions
53 lines (48 loc) · 1.8 KB
/
is-context.js
File metadata and controls
53 lines (48 loc) · 1.8 KB
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
import objectHasOwn from './object-has-own';
import isArrayLike from './is-array-like';
/**
* Determine if some value can be parsed as a context
* @private
* @param {Mixed} contextSpec The configuration object passed to `Context`
* @return {boolea}
*/
export function isContextSpec(contextSpec) {
return isContextObject(contextSpec) || isContextProp(contextSpec);
}
/**
* Checks if the given context specification is a valid context object.
*
* @param {Object} contextSpec - The context specification object to check.
* @returns {boolean} - Returns true if the context specification is a valid context object, otherwise returns false.
*/
export function isContextObject(contextSpec) {
return ['include', 'exclude'].some(
prop => objectHasOwn(contextSpec, prop) && isContextProp(contextSpec[prop])
);
}
/**
* Checks if the given contextList is a valid context property.
* @param {string|Node|Array} contextList - The contextList to check.
* @returns {boolean} - Returns true if the contextList is a valid context property, otherwise false.
*/
export function isContextProp(contextList) {
return (
typeof contextList === 'string' ||
contextList instanceof window.Node ||
isLabelledFramesSelector(contextList) ||
isLabelledShadowDomSelector(contextList) ||
isArrayLike(contextList)
);
}
export function isLabelledFramesSelector(selector) {
// This doesn't guarantee the selector is valid.
// Just that this isn't a runOptions object
// Normalization will ignore invalid selectors
return objectHasOwn(selector, 'fromFrames');
}
export function isLabelledShadowDomSelector(selector) {
// This doesn't guarantee the selector is valid.
// Just that this isn't a runOptions object
// Normalization will ignore invalid selectors
return objectHasOwn(selector, 'fromShadowDom');
}