forked from artcommacode/q
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (34 loc) · 1.19 KB
/
index.js
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
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var toArray = function toArray(list) {
return [].concat(_toConsumableArray(list));
};
var first = function first(xs) {
return xs[0];
};
var elemError = function elemError(e) {
throw new Error("\"" + String(e) + "\" does't exist in the document");
};
var elemExists = function elemExists(e) {
return document && document.body && document.body.contains(e);
};
var getRoot = function getRoot(e) {
if (e === document) return e;
return elemExists(e) ? e : elemError(e);
};
var queryChildren = exports.queryChildren = function queryChildren(e, q) {
var root = getRoot(e);
return root ? toArray(root.querySelectorAll(q)) : [];
};
var queryChild = exports.queryChild = function queryChild(e, q) {
return first(queryChildren(e, q));
};
var query = exports.query = function query(q) {
return queryChildren(document, q);
};
var queryOne = exports.queryOne = function queryOne(q) {
return queryChild(document, q);
};