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 🙏

© 2026 – Pkg Stats / Ryan Hefner

koa-esm-transform

v1.0.0-pre.1

Published

Middleware for Koa servers that transforms standard JavaScript modules to earlier versions of JavaScript and/or AMD modules (inlining loader script @polymer/esm-amd-loader into the HTML), for use with older browsers.

Readme

koa-esm-transform

Middleware for Koa servers that transforms standard JavaScript modules to earlier versions of JavaScript and/or AMD modules (inlining loader script @polymer/esm-amd-loader into the HTML), for use with older browsers.

Consider an HTML file containing the following inline JavaScript module:

<script type="module">
import {someFunction} from './some-module.js';
someFunction();
</script>

The koa-esm-to-amd middleware would transform that HTML code to something like the following:

<script>
// An inline loader script from `@polymer/esm-amd-loader` package
// which adds the `define` function used below.
</script>
<script>
define(["./some-module.js"], function (someModule) {
  someModule.someFunction();
});
</script>

Because this is middleware, you can use it in a simple static file server as well with a proxy server. This makes it possible to use in front of a test server such as the one karma starts up. (See koa-karma-proxy for examples.)

Note: HTML and JavaScript are parsed on every request for those content-types, it is intended for use in development context to facilitate build-free testing/iteration as opposed to in a high volume production web server.

How it works

By default, a set of babel transform plugins are chosen based on the known capabilities of the browser/user-agent identified in the Koa Context for the request.

When the downstream server returns HTML content, it is scanned for module script tags (e.g. <script type="module">). Any src attribute values are appended with the __esmTransform query parameter. The query parameter is added because the middleware needs to distinguish between scripts that are being imported as a module vs a traditional script and this can't necessarily be determined by looking at the script itself.

Inline module script content and URLs with the __esmTransform query parameter have their import specifiers appended with the __esmTransform to indicate the requested content should be treated as a module and compiled with the selected babel plugins.

Depending on plugins being used, certain support scripts will also be inlined into the HTML, such as @polymer/esm-amd-loader and regenerator-runtime.

Options

  • babelPlugins: Either an Array of babel plugins (e.g. [require('@babel/plugin-transform-modules-amd')]) or a Function that takes a Koa Context and returns an Array of babel plugins (ctx) => []. Providing a value for this option will override the default behavior of the middleware's capabilities-based babel plugin selection.
  • exclude: An array of requested paths or minimatch based patterns to match requested paths that should be excluded from any process/rewriting by the middleware.
  • queryParam: You can redefine the appended query parameter string from __esmTransform as something else.
  • logger: Middleware will call debug, info, warn and error methods on console to log events. If you use a different logger for your application, provide it here.
  • logLevel: Set a minimum level for events to be logged to override the default level of info.