-
Notifications
You must be signed in to change notification settings - Fork 10
/
detect.js
29 lines (26 loc) · 866 Bytes
/
detect.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
define(['implementations'], function (impls) {
var map = {},
isArray = function (it) {
return {}.toString.call(it) == '[object Array]';
},
isAvailable = function (impl, name) {
var isFunction = typeof impl.isAvailable === 'function';
return (isFunction && impl.isAvailable(name)) || (!isFunction && impl.isAvailable);
};
for (var name in impls) {
var featureInfo = impls[name],
mapItem = map[name] = {};
if (isArray(featureInfo)) {
for (var i = 0, m = featureInfo.length; i < m; i++) {
if (isAvailable(featureInfo[i], name)) {
mapItem.implementedBy = featureInfo[i].implementation;
mapItem.testSource = featureInfo[i].isAvailable.toString();
break;
}
}
} else {
mapItem.implementedBy = featureInfo;
}
}
return map;
});