This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
58 lines (46 loc) · 1.53 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
47
48
49
50
51
52
53
54
55
56
57
58
var _cacheSupports = {};
function parse(propertyName, reg) {
return propertyName.split(reg).slice(1, -1);
}
function cssSupports(propertyName, value) {
var style = document.createElement('div').style;
// 1 argument
if (typeof value === 'undefined') {
// The regex will do this '( a:b ) or ( c:d )' => [" a:b ", " c:d "]
var arrOr = parse(propertyName, /(?:^\(|\)\s*or\s*\(|\)$)/gi);
if (arrOr) {
return arrOr.some(function(condition) { return supports.apply(null, condition.split(':')); });
}
var arrAnd = parse(propertyName, /(?:^\(|\)\s*and\s*\(|\)$)/gi);
if (arrAnd) {
return arrAnd.every(function(condition) { return supports.apply(null, condition.split(':')); });
}
style.cssText = propertyName;
// 2 arguments
} else {
style.cssText = propertyName + ':' + value;
}
return !!style.length;
}
function supports(propertyName, value) {
propertyName = typeof propertyName !== 'undefined' &&
String.prototype.trim.call(propertyName);
value = typeof value !== 'undefined' &&
String.prototype.trim.call(value) || undefined;
if (!propertyName || (arguments.length === 2 && !value)) return false;
var key = [propertyName, value].toString();
if (key in _cacheSupports) {
return _cacheSupports[key];
}
return _cacheSupports[key] = cssSupports(propertyName, value);
}
function shim() {
if (!('CSS' in window)) {
window.CSS = {};
}
if (!('supports' in window.CSS)) {
window.CSS.supports = supports;
}
}
module.exports = supports;
module.exports.shim = shim;