UNPKG

649 BJavaScriptView Raw
1var select = require('dom-select');
2
3module.exports = ifNecessary;
4module.exports.all = ifNecessaryAll;
5
6function 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
22function 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}