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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mport

v1.0.0

Published

A lightweight utility for dynamically importing ES modules from npm CDNs (jsDelivr, JSPM, Unpkg) with race conditions for fastest response.

Readme

MPort

npm version license

MPort is a lightweight ESM utility for dynamically importing modules from npm CDNs such as jsDelivr, JSPM, and Unpkg. It races multiple CDN origins to fetch the fastest available resource and returns both the imported module and the URL used.

Installation

Unironically, the best way to install MPort in the browser is to use a CDN. You can import it directly in your HTML file:

<script type="module">
  import mport from "https://cdn.jsdelivr.net/npm/[email protected]/index.mjs";
  const { default: _ } = await mport("[email protected]");
</script>

But it's also available directly as an npm packaged.

npm install mport

Usage

Use default export, import in the same way that you would use dynamic import():

import mport from "...";
// Import by specifier string: 'package@version[/path]'
const { default } = await mport("[email protected]");

Create custom mport function by defining CDN origins:

import { MPort } from "...";
const mport = MPort({
  cdns: ["cdn.jsdelivr.net/npm/", "ga.jspm.io/npm:", "unpkg.com/"],
});
// Import by specifier string: 'package@version[/path]'
const module = await mport("[email protected]");
console.log(module); // The imported module namespace
// Import with options object
const module = await mport({
  name: "spintax",
  version: "1.1.2",
  path: "src/index.mjs",
});

With chosen url:

import { MPortURL as MPort } from "...";
const mport = MPort();
const [module, url] = await mport("[email protected]");
console.log(url); // The CDN URL that succeeded first

Custom Origins

Pass one or more custom CDN origins to the factory:

const mportCustom = MPort("my.cdn.example.com/", "another.cdn/");

For security, we this library prepends the origins with https://

API

MPort({cdns, useCache, cacheKey='mport-cache'})

  • cdns (string[]): Optional list of CDN origin prefixes. Defaults to:
    • 'cdn.jsdelivr.net/npm/'
    • 'ga.jspm.io/npm:'
    • 'unpkg.com/'
  • useCache (string): Name of cache to use. Options:'localhost', undefined
    • 'localhost': Use the browser's localStorage to cache the module.
    • undefined: Use the browser's cache.
  • cacheKey (string): Key to use for the cache. Defaults to 'mport-cache'.
  • Returns: A function (input) => Promise<module>.

Input

  • input can be:
    • A specifier string: 'name@version[/path]'.
    • An options object:
      • name (string): Package name.
      • version (string, optional): Package version or tag (default 'latest').
      • path (string, optional): Sub-path inside the package.

Return Value

A Promise that resolves to a module (any): The imported ES module namespace.

MPortURL(...origins)

MPortURL functions similarly to MPort, but returns a tuple of the imported module and the URL used: A function (input) => Promise<[module, url]>.

Module Compatibility

MPort is designed for modern Ecmascript modules. It may not work using CommonJS modules.

e.g. Use "lodash-es" instead of "lodash".

Firefox Compatibility

Currently, this does not work with Firefox. Adding a second argument to import causes an error: Uncaught SyntaxError: missing )

I suspect that this is an issue with SpiderMonkey's static analysis/compilations as it occurs even when not on the executable path.

This makes it particularly difficult to work around, so there is a separate export for Firefox, mport/firefox that lacks two features:

- automatic path resolution -- you must specify the path to the main file within the module

- ability to pass an options object to the import function

The API is otherwise identical

import mport from "mport/firefox";
const module = await mport("[email protected]/src/index.mjs");

TypeScript

This package includes TypeScript declarations. Importing in TS environments will pick up types.d.ts.

Demo

Run the included demo:

node demo.mjs

License

MIT