node-caniuse
Check your JavaScript against the Can I Use database
Quick Start
npm install node-caniuse
var caniuse = require('node-caniuse');
caniuse({
files: './src/**/*.js',
browsers: {
Chrome: '>= 5',
Firefox: '>= 4',
InternetExplorer: '>= 9'
},
reporter: 'console'
});
API Reference
#####caniuse(Object options [, Function callback]) -> Promise
The result (for both the resolved Promise and for the callback) is an Array where each element represents a file and it's bad tokens.
[{
"filename" : "path/to/file",
"tokens" : [{
token: "<invalid token>",
location: {...}
}]
}]
Note: The callback and the promise are equivalent and can be used interchangeably.
> option.files
Type: Array String
Default: []
The files to be scanned by caniuse. Both the String and Array versions accept globs. E.g. ./src/**/*.js
> options.browsers
Type: Object
Default: {}
An object representing your browser support matrix in the following format:
{
<browser-name>: <browser-versions>
}
browser versions can be specified in the following three ways:
- Direct selection -
[9, 10, 11] or '11'
- Versions newer than -
'> 9' or '>= 8'
- Versions with Global Usage greater than -
'> 10%'
browser names can be any of the following (case insensitive):
Android for old Android stock browser.
BlackBerry or bb for Blackberry browser.
Chrome for Google Chrome.
Firefox or ff for Mozilla Firefox.
Explorer or ie or InternetExplorer for Internet Explorer.
iOS or ios_saf for iOS Safari.
Opera for Opera.
Safari for desktop Safari.
OperaMobile or op_mob for Opera Mobile.
OperaMini or op_mini for Opera Mini.
ChromeAndroid or and_chr for Chrome for Android
(mostly same as common Chrome).
FirefoxAndroid or and_ff for Firefox for Android.
ExplorerMobile or ie_mob for Internet Explorer Mobile.
> reporter
Type: String
Default: null
Specify the output format by choosing any of the node-caniuse reporters
caniuse({
files: './src/**/*.js',
browsers: { Chrome: '>= 5' },
reporter: 'console'
});
> gobalIgnores
Type: Array
Default: []
Ignore tokens that are properties of of the specified objects. This is helpful if you have libraries that act as polyfills for native behavior.
caniuse({
files: './src/**/*.js',
browsers: { Chrome: '>= 5' },
gobalIgnores: '_'
});
License
MIT License