1 | var select = require('dom-select');
|
2 |
|
3 | module.exports = ifNecessary;
|
4 | module.exports.all = ifNecessaryAll;
|
5 |
|
6 | function ifNecessary (child, parent) {
|
7 | if (Array.isArray(child)) {
|
8 | child = child[0];
|
9 | }
|
10 |
|
11 | if ( typeof child != 'string') {
|
12 | return child;
|
13 | }
|
14 |
|
15 | if (typeof parent == 'string') {
|
16 | parent = select(parent, document);
|
17 | }
|
18 |
|
19 | return select(child, parent);
|
20 | }
|
21 |
|
22 | function ifNecessaryAll (child, parent) {
|
23 | if (Array.isArray(child)) {
|
24 | child = child[0];
|
25 | }
|
26 |
|
27 | if ( typeof child != 'string') {
|
28 | return [child];
|
29 | }
|
30 |
|
31 | if (typeof parent == 'string') {
|
32 | parent = select(parent, document);
|
33 | }
|
34 |
|
35 | return select.all(child, parent);
|
36 | }
|