npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

astro-modernizr

v0.1.0

Published

Add Modernizr feature detection to your Astro site.

Downloads

3

Readme

Astro + Modernizr

Build sites for the future and the past.

Modernizr documentation

This is an Astro integration that adds Modernizr to your Astro site, a fast tool that detects which HTML, CSS and JS features do browsers support, allowing you to progressively enhance and future-proof your components and site with fine control and guaranteed accuracy.

Installation

Install the integration automatically using the Astro CLI:

pnpm astro add astro-modernizr
npx astro add astro-modernizr
yarn astro add astro-modernizr

Or install it manually:

  1. Install the required dependencies
pnpm add astro-modernizr
npm install astro-modernizr
yarn add astro-modernizr
  1. Add the integration to your astro config
+import modernizr from "astro-modernizr";

export default defineConfig({
  integrations: [
+    modernizr({
+      options: [],
+      featureDetects: [
+        /* your feature detection tests */
+      ],
+    }),
  ],
});

Configuration

The integration follows the same configuration as building Modernizr from the JS module to provide the smallest bundle as needed.

options

An array of the name of the different Modernizr API functions to include. By default, it doesn't include anything.

For a more sensible default, ["setClasses"] is good for adding CSS classes in accord to the support or not of certain features, instead of adding classes only if it does support them.

featureDetects

An array of all the features that you wish to test for. The complete supported list can be found here.

By default, it doesn't test for anything.

classPrefix

A string that you wish to use to prefix your classes. For example, "supported-".

By default, there is no prefix.

enableCSSClasses

A boolean to enable adding CSS classes to the root of the document (the <html> node). If false, regardless of adding setClasses to the options array, Modernizr will not add any classes (except for .no-js).

Enabled by default.

enableJSClass

A boolean to enable updating the .no-js class that Modernizr adds automatically to the root of the document to .js if JavaScript is enabled and working. The class won't be able to update if the browser halts scripts on error.

Enabled by default.

minify

A boolean that determines whether to minify the generated client JavaScript that'll be placed on the Astro page.

Enabled by default.

This differs from the default in the npm module, as the generated code will not be optimized by Vite. This is done by design for backwards compatibility with browsers that do not support ES6 modules.

scriptGlobalName

The name of the global object to be used by Modernizr.

By default, it is set to "window", and there shouldn't be any need to change it.

usePrefixes

A boolean that determines whether to check for vendor prefixes when testing a feature.

Enabled by default.

Usage

You can use Modernizr just like you would normally. Check the documentation for more details.

The integration exposes the Modernizr object globally on client scripts and offers typings to be used in optimized scripts. However, for backwards compatibility purposes it's heavily recommended to use Modernizr only in inline scripts.

<script is:inline>
  if (Modernizr.awesomeNewFeature) {
    // Use the new awesome feature!
  } else {
    // Get the old lame experience.
  }
</script>

Contributing

This package is structured as a monorepo:

  • playground contains code for testing the package
  • package contains the actual package

Install dependencies using pnpm:

pnpm i --frozen-lockfile

Start the playground and package watcher:

pnpm dev

You can now edit files in package. Please note that making changes to those files may require restarting the playground dev server.

Licensing

MIT Licensed. Made with ❤️ by YonicDev.