runtime-compat-data
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

runtime-compat-data

npm version npm downloads

This project provides machine-readable data on support for Web APIs and JavaScript features across non-browser JavaScript runtimes. The data format is the same as MDN's browser-compat-data, and it uses the runtime tests from mdn-bcd-collector. It includes most runtimes that are members of the WinterCG project, and can be used to track the goal of improving web-interoperability across different runtimes.

Supported runtimes

Currently this tracks the following JavaScript runtimes (shown with their WinterCG runtime key):

Usage

The module exports a JSON file, and it can be imported directly using ESM with import assertions, or using a CommonJS require statement. There is also a wrapper for ESM in older versions of Node.js that do not support import assertions.

It is published to npm, but can also be loaded from a CDN.

npm

Install the package:

# npm
npm install runtime-compat-data

# yarn
yarn add runtime-compat-data

# pnpm
pnpm install runtime-compat-data

# bun
bun install runtime-compat-data
// ESM with Import Assertions (Node.js 16+)
import data from "runtime-compat-data" assert { type: "json" };
// ...or...
const { default: data } = await import("runtime-compat-data", {
  assert: { type: "json" },
});
// ...or...

// ESM Wrapper for older Node.js versions (Node.js v12+)
import data from "runtime-compat-data/forLegacyNode";
// ...or...
const { default: data } = await import("runtime-compat-data/forLegacyNode");

// ...or...

// CommonJS Module (Any Node.js)
const data = require("runtime-compat-data");

CDN

For Deno or the browser, you can load the data from a CDN:

import data from "https://unpkg.com/runtime-compat-data" assert { type: "json" };
// ...or...
const { default: data } = await import(
  "https://unpkg.com/runtime-compat-data",
  {
    assert: { type: "json" },
  }
);

Data format

The data follows the same format as MDN's browser-compat-data, but only includes the javascript and api keys. Instead of the browser keys in MDN's data, this project uses the runtime keys from the WinterCG runtime key proposal. The data doesn't currently track versions where the feature was added, and just includes a boolean for whether the feature is supported in the current runtime.

Example data:

{
  "api": {
    "URLPattern": {
      "__compat": {
        "mdn_url": "https://developer.mozilla.org/docs/Web/API/URLPattern",
        "source_file": "api/URLPattern.json",
        "spec_url": "https://urlpattern.spec.whatwg.org/#urlpattern",
        "status": {
          "deprecated": false,
          "experimental": true,
          "standard_track": true
        },
        "support": {
          "bun": { "version_added": false },
          "deno": { "version_added": true },
          "edge-light": { "version_added": true },
          "fastly": { "version_added": false },
          "netlify": { "version_added": true },
          "node": { "version_added": false },
          "workerd": { "version_added": true }
        }
      }
    }
  }
}

The data is heirarchical, with the feature at the top level and then properties nested below it. Each level has a __compat key that contains the compatibility data for that item. The support key in that contains the compatibility data for each runtime.

For example, the TextEncoder key has this structure:

  • TextEncoder
    • __compat (shows compatibility for the feature itself)
    • TextEncoder
      • __compat (shows compatibility for the TextEncoder object)
    • encodeInto
      • __compat (shows compatibility for the encodeInto method)
    • encode
      • __compat (shows compatibility for the encode method)

License

Created by Matt Kane. Includes data from MDN.

Published under the CC0 (no rights reserved).

Readme

Keywords

Package Sidebar

Install

npm i runtime-compat-data

Weekly Downloads

5

Version

0.0.5

License

CC0-1.0

Unpacked Size

742 kB

Total Files

9

Last publish

Collaborators

  • ascorbic