Modernizr will not allow individual tests to be required from source. There is a standing issue about this:
This repository will make an effort to turn all test modules into CJS format with the specific intent to be required by libraries and not applications.
If you want to just add Modernizr to your website then please go to http://modernizr.com
use github repository:
npm install https://github.com/thanpolas/Modernizr-CJS/archive/master.tar.gz --save-dev
Require individual tests with:
var cookies = require('Modernizr-CJS/feature-detects/cookies');
All tests are functions with a callback that has as arguments the test outcome.
cookies(function(result) {
typeof result === 'boolean'; // true
});
A new module has been created to run multiple tests, require the src/cjsTestRunner
module and invoke like so:
var testRunner = require('modernizr-cjs/src/cjsTestRunner');
var tests = {
es5array: require('modernizr-cjs/feature-detects/es5/array'),
es5date: require('modernizr-cjs/feature-detects/es5/date'),
es5function: require('modernizr-cjs/feature-detects/es5/function'),
es5object: require('modernizr-cjs/feature-detects/es5/object'),
es5strictmode: require('modernizr-cjs/feature-detects/es5/strictmode'),
es5string: require('modernizr-cjs/feature-detects/es5/string')
};
testRunner([
tests.es5array,
tests.es5date,
tests.es5function,
tests.es5object,
tests.es5strictmode,
tests.es5string
], function(results) {
console.log(results);
typeof results.es5string === 'boolean'; // true
});
The following tests have been ported to be CJS modules:
feature-detects/es5/array
feature-detects/es5/date
feature-detects/es5/function
feature-detects/es5/object
feature-detects/es5/strictmode
feature-detects/es5/string
feature-detects/file/api
(Filereader test).feature-detects/cookies
feature-detects/cors
feature-detects/eventlistener
feature-detects/flash
feature-detects/json
feature-detects/history
feature-detects/video
feature-detects/webgl
feature-detects/websockets
Pull Requests welcome...
- v3.0.6, 26 Mar 2014
- The module is no longer available in npm, use the git url as instructed.
- v3.0.5, 25 Mar 2014
- Introduced the
cjsTestRunner
module.
- Introduced the
- v3.0.2, 24 Mar 2014
- Big Bang.