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

@journeyapps/ts-browser-compat

v0.1.2

Published

Check TypeScript projects for browser compatibility

Downloads

516

Readme

ts-browser-compat

Check TypeScript projects for browser compatibility, using MDN browser-compat-data - the same data that powers caniuse.com.

Important note: This uses heuristics to report usage of APIs that may not be supported. The heuristics are not accurate in all cases - manually check the results.

Simple Usage

npx @journeyapps/ts-browser-compat -b firefox:55 -b safari_ios:13

Sample output:

AbortController - firefox 57, safari_ios 12.2
  src/client.ts:196
AbortController.abort - firefox 57, safari_ios 12.2
  src/client.ts:210
AbortController.signal - firefox 57, safari_ios 12.2
  src/client.ts:202
Blob.arrayBuffer - firefox 69, safari_ios 14
  src/convert.ts:64
Blob.text - firefox 69, safari_ios 14
  src/convert.ts:87
  src/convert.ts:93

Limitations

This project works by cross-referencing type references from DOM and built-in libraries in TypeScript, to the MDN browser compatibility data.

  • No support for checking CSS.
  • No support for checking HTML.
  • No support for checking DOM events.
  • Does not check for supported JavaScript syntax. Use target in tsconfig.json for this.
  • Limited support for checking JavaScript source files: It only works as well as the TypeScript compiler can infer the types.
  • Unpredictable results when a browser lists partial support for an API.
  • Potential for inaccuracies with mapping the TypeScript definition to the compatibility data.
  • Does not automatically build or check referenced projects.
  • Does not check implementation of dependencies with type declarations.
  • Does not detect safe API usage using guard statements.

Usage in a project

For regular use, add as a dependency:

npm install --save-dev @journeyapps/ts-browser-compat

Then create a ts-browser-compat.json config file:

{
  // List of minimum browser versions
  "browsers": {
    "firefox": "55",
    "safari_ios": "13"
  },
  // Optional path to TypeScript projects - defaults to current dir
  "path": ["src", "web"],
  //
  "polyfills": [
    // Mark a specific property or method as implemented
    "Promise.finally",
    // This only matches the contructor, no properties or methods
    "AbortController",
    // This matches the constructor and all properties and methods
    "Blob.*"
  ],
  "ignore": [
    // Same as polyfills. Use this to indicate that the code handles missing APIs in a way other than polyfilling.
  ],
  // By default, TypeScript's type checker is run, to ensure that TypeScript errors don't prevent these checks from working.
  // It can be disabled to speed up the checks.
  "skipTypeCheck": true
}

To ignore a single API usage, add // @tsbc-ignore on the previous line. If an API is used in many places, wrap it in an internal module, or add it to the polyfills or ignore lists.