Modernizr tests as ES Modules.
Features:
- Each test can be imported and used separately
- Tests return multiple named exports if they test multiple features
- Async tests support Promises as result
- No global modifications like setting classes on
html
element - Ignores browser globals when imported directly in SSR environment
Refer to original Modernizr documentation for more information.
npm install modernizr-esm --save
import emoji from 'modernizr-esm/feature/emoji';
console.log(emoji); // Are emojis supported?
import flash from 'modernizr-esm/feature/flash';
flash(( support ) => {
console.log(support); // Is Flash supported?
});
If you don’t provide callback, calling function will return Promise.
import flash from 'modernizr-esm/feature/flash';
flash().then(( support ) => {
console.log(support); // Is Flash supported?
});
import { cssgrid } from 'modernizr-esm/feature/css/cssgrid';
console.log(cssgrid); // Is CSS Grid supported?
Use classList
and export value of feature test:
import emoji from 'modernizr-esm/feature/emoji';
document.documentElement.classList.add(`${emoji ? '' : 'no-'}emoji`);
Or if you want to use Modernizr HTML class setter:
import setClasses from 'modernizr-esm/src/setClasses';
import emoji from 'modernizr-esm/feature/emoji';
setClasses([`${emoji ? '' : 'no-'}emoji`]);
MIT © Ivan Nikolić
MIT © Modernizr