|
1 | | -import { assert as utilsAssert } from '../../utils'; |
| 1 | +import { |
| 2 | + assert as utilsAssert, |
| 3 | + objectHasOwn, |
| 4 | + isArrayLike, |
| 5 | + isContextObject, |
| 6 | + isContextProp, |
| 7 | + isLabelledFramesSelector, |
| 8 | + isLabelledShadowDomSelector |
| 9 | +} from '../../utils'; |
2 | 10 |
|
3 | 11 | /** |
4 | 12 | * Normalize the input of "context" so that many different methods of input are accepted |
@@ -29,16 +37,6 @@ export function normalizeContext(contextSpec) { |
29 | 37 | return { include, exclude }; |
30 | 38 | } |
31 | 39 |
|
32 | | -/** |
33 | | - * Determine if some value can be parsed as a context |
34 | | - * @private |
35 | | - * @param {Mixed} contextSpec The configuration object passed to `Context` |
36 | | - * @return {boolea} |
37 | | - */ |
38 | | -export function isContextSpec(contextSpec) { |
39 | | - return isContextObject(contextSpec) || isContextProp(contextSpec); |
40 | | -} |
41 | | - |
42 | 40 | function normalizeContextList(selectorList = []) { |
43 | 41 | const normalizedList = []; |
44 | 42 | if (!isArrayLike(selectorList)) { |
@@ -89,30 +87,6 @@ function normalizeFrameSelectors(frameSelectors) { |
89 | 87 | return normalizedSelectors; |
90 | 88 | } |
91 | 89 |
|
92 | | -function isContextObject(contextSpec) { |
93 | | - return ['include', 'exclude'].some( |
94 | | - prop => objectHasOwn(contextSpec, prop) && isContextProp(contextSpec[prop]) |
95 | | - ); |
96 | | -} |
97 | | - |
98 | | -function isContextProp(contextList) { |
99 | | - return ( |
100 | | - typeof contextList === 'string' || |
101 | | - contextList instanceof window.Node || |
102 | | - isLabelledFramesSelector(contextList) || |
103 | | - isLabelledShadowDomSelector(contextList) || |
104 | | - isArrayLike(contextList) |
105 | | - ); |
106 | | -} |
107 | | - |
108 | | -function isLabelledFramesSelector(selector) { |
109 | | - return objectHasOwn(selector, 'fromFrames'); |
110 | | -} |
111 | | - |
112 | | -function isLabelledShadowDomSelector(selector) { |
113 | | - return objectHasOwn(selector, 'fromShadowDom'); |
114 | | -} |
115 | | - |
116 | 90 | function assertLabelledFrameSelector(selector) { |
117 | 91 | assert( |
118 | 92 | Array.isArray(selector.fromFrames), |
@@ -157,28 +131,10 @@ function isShadowSelector(selector) { |
157 | 131 | ); |
158 | 132 | } |
159 | 133 |
|
160 | | -function isArrayLike(arr) { |
161 | | - return ( |
162 | | - // Avoid DOM weirdness |
163 | | - arr && |
164 | | - typeof arr === 'object' && |
165 | | - typeof arr.length === 'number' && |
166 | | - arr instanceof window.Node === false |
167 | | - ); |
168 | | -} |
169 | | - |
170 | 134 | // Wrapper to ensure the correct message |
171 | 135 | function assert(bool, str) { |
172 | 136 | utilsAssert( |
173 | 137 | bool, |
174 | 138 | `Invalid context; ${str}\nSee: https://github.com/dequelabs/axe-core/blob/master/doc/context.md` |
175 | 139 | ); |
176 | 140 | } |
177 | | - |
178 | | -// Wrapper to prevent throwing for non-objects & null |
179 | | -function objectHasOwn(obj, prop) { |
180 | | - if (!obj || typeof obj !== 'object') { |
181 | | - return false; |
182 | | - } |
183 | | - return Object.prototype.hasOwnProperty.call(obj, prop); |
184 | | -} |
0 commit comments