forked from dvmarinoff/Auuki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq.js
More file actions
38 lines (36 loc) · 1.03 KB
/
q.js
File metadata and controls
38 lines (36 loc) · 1.03 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
function Q() {
const isFound = (selector, res) => {
return res === null || res === undefined ? false : true;
};
const isIdSelector = (selector) => {
return selector.charAt(0) === '#' ? true : false;
};
const get = (selector) => {
let res = document.querySelector(selector);
if(!isFound(selector, res)) {
throw new Error(`q Error ${selector} is not found: ${res}`);
}
return res;
};
const getAll = (selector) => {
let res = document.querySelectorAll(selector);
if(!isFound(selector, res)) {
throw new Error(`q Error ${selector} is not found: ${res}`);
}
return res;
};
const getId = (selector) => {
let res = document.getElementById(selector);
if(!isFound(selector, res)) {
throw new Error(`q Error ${selector} is not found: ${res}`);
}
return res;
};
return {
get: get,
getAll: getAll,
getId: getId,
};
}
let q = Q();
export { q };