-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
40 lines (34 loc) · 814 Bytes
/
utils.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
const matches = (toMatch, matchers) => {
if (!matchers) {
return false;
}
if (matchers instanceof RegExp) {
return matchers.test(toMatch);
}
if (typeof matchers === 'string') {
return toMatch.includes(matchers);
}
return matchers.some((matcher) => {
if (matcher instanceof RegExp) {
return matcher.test(toMatch);
} else {
return toMatch.includes(matcher);
}
});
};
const getModifiedElement = (tag, mediaValue) => {
return Object.assign({}, tag, {
attributes: Object.assign({}, tag.attributes, {
media: mediaValue,
}),
});
};
const isStylesheetTag = (tag) => {
return tag.tagName === 'link' && tag.attributes.rel === 'stylesheet' &&
tag.attributes.href;
};
module.exports = {
isStylesheetTag,
matches,
getModifiedElement,
};