A configurable feature detection library that doesn't dirty the DOM.
Most detection libraries expose an API for querying the availability of features as required:
const areWorkersSupported = featureDetector.areWorkersSupported();
console.log(areWorkersSupported); // => true
Detectorist is different; one must provide a configuration of desired features, and these will be evaluated to return an overall result reflecting their support:
'use strict';
const featureConfig = [
{
name: 'window',
methods: [
'CustomEvent'
]
},
{
name: 'document',
methods: [
'querySelector'
]
},
{
name: 'element',
methods: [
'querySelector'
],
properties: [
'outerHTML'
],
styles: [
'display',
'textAlign'
]
}
];
const isBrowserSupported = detectorist(featureConfig);
console.log(isBrowserSupported); // => true
The rationale behind this approach is to allow developers to specify which APIs a user's browser must support in order for it to be determined as suitable for one's web app or website.
Determines whether the environment in which this function is invoked is compliant with the specified featureConfig
.
Returns:
true
- browser provides required featuresfalse
- browser does not provides required features
The featureConfig
parameter is an Array
of configuration Object
s that allows for the specification of features. The name
property of the contained Object
s can be:
window
- detects features on the globalwindow
objectdocument
- detects features on the globaldocument
objectelement
- detects features on an instantiatedHTMLElement
Any other value of the name
property will conrespond to a property of the global window
Object
, although this behaviour needs further testing.
These objects can also contain these properties:
properties
- an array ofString
s determining the properties that should be supportedmethods
- an array ofString
s determining the methods (read: properties whosetypeof === 'function'
) that should be supported
The element
type also supports:
styles
- an array of camel-cased, standards-compliantString
s representing the CSS features that should be supported
This project was written with BDD and has Chrome browser tests, but this is pretty much a WIP.
- Minify
- Transpile to ES5
- Document local dev setup
- Tests for other browsers
- Publish