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

css-browser-support

v0.12.0

Published

Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentages.

Downloads

95

Readme

css-browser-support

Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentages.

Usage

Install the package:

npm i --save-dev css-browser-support

Then import it into your project:

const { cssBrowserSupport } = require("css-browser-support");

And call it by passing a string or an array of strings containing the CSS features you'd like to query support:

cssBrowserSupport([
  "aspect-ratio",
  "margin-inline",
  "border-radius",
  ":nth-last-child",
  "@layer",
  "gap",
]);

Returns an object that includes each browser for which support is available, example for aspect-ratio:

{
  'aspect-ratio': {
    chrome: {
      sinceVersion: '88',
      flagged: true,
      globalSupport: 22.46,
      browserTitle: 'Chrome'
    },
    chrome_android: {
      sinceVersion: '88',
      flagged: false,
      globalSupport: 41.34,
      browserTitle: 'Chrome Android'
    },
    edge: {
      sinceVersion: '88',
      flagged: false,
      globalSupport: 3.88,
      browserTitle: 'Edge'
    },
    // ... continued for all browsers
    globalSupport: 86.49
  }
}

Supported CSS features

The API is intended to work for passing features as you would write them in CSS. As such, a few things will not be available if they exist on MDN under an expanded name. For example, > would be available as child.

Additionally, some features are nested and may be missed by the API. Exceptions are grid features (ex. repeat()), and color types (ex. color-contrast()) which have been explicitly included.

Review the data from MDN:

Special case: gap

Since gap is a popular feature known to have been implemented for both flexbox and grid at different times, the API splits a request for gap to return support for both implementations.

In your implementation, you'll want to check for an input of gap and then update to handle for the two returned keys of gap - flexbox and gap - grid.

Example:

if (queries.includes("gap")) {
  queries.splice(queries.indexOf("gap"), 1);
  queries.push("gap - flexbox");
  queries.push("gap - grid");
}

Implementing the data

  • if your implementation accepts properties with values, ex margin-inline: auto, you are responsible for removing values before passing the property to the API
  • due to the data returned from MDN, characters like : are stripped from selectors and pseudo-elements, and @ is removed from at-rule, so for example @layer will be found in returned data as layer

For an example on using this data, see my Eleventy plugin implementation: @11tyrocks/eleventy-plugin-css-browser-support

Browser list

You can also import the full browser list as BROWSERS:

const { cssBrowserSupport, BROWSERS } = require("css-browser-support");

The list is as follows:

[
  "chrome",
  "chrome_android",
  "edge",
  "firefox",
  "firefox_android",
  "ie",
  "opera",
  "safari",
  "safari_ios",
  "samsunginternet_android",
];

Credits

Two packages are being used to obtain support data: