/modernizr-esm

Modernizr tests as ES Modules.

Primary LanguageJavaScriptOtherNOASSERTION

modernizr-esm

Build Status BrowserStack Status

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

Try it now!

Refer to original Modernizr documentation for more information.

Install

npm install modernizr-esm --save

Usage

import emoji from 'modernizr-esm/feature/emoji';

console.log(emoji); // Are emojis supported?

Async tests

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?
});

Multiple feature tests

import { cssgrid } from 'modernizr-esm/feature/css/cssgrid';

console.log(cssgrid); // Is CSS Grid supported?

Setting feature HTML classes

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`]);

License

MIT © Ivan Nikolić
MIT © Modernizr