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

@esm.sh/import-map

v0.4.0

Published

A import map parser and resolver.

Readme

@esm.sh/import-map

An Import Maps parser and resolver, with features:

  • Parse import maps from JSON/HTML
  • Resolve specifiers to URLs using import map matching rules
  • Add npm/jsr/github modules from esm.sh CDN
  • Generate integrity entries for added modules

Installation

npm i @esm.sh/import-map

API

new ImportMap(init?: ImportMapRaw, baseURL?: string)

Create an import map instance:

import { ImportMap } from "@esm.sh/import-map";

const im = new ImportMap();

You can also initialize from a raw object:

const im = new ImportMap({
  config: { cdn: "https://esm.sh", target: "es2022" },
  imports: { react: "https://esm.sh/[email protected]/es2022/react.mjs" },
  scopes: {
    "https://esm.sh/": {
      scheduler: "https://esm.sh/[email protected]/es2022/scheduler.mjs",
    },
  },
  integrity: {
    "https://esm.sh/[email protected]/es2022/react.mjs": "sha384-...",
  },
});

parseFromJson(json: string, baseURL?: string)

Parse an import map from JSON text. Preserves and validates config, imports, scopes, and integrity.

import { parseFromJson } from "@esm.sh/import-map";

const im = parseFromJson(`{
  "imports": {
    "react": "https://esm.sh/[email protected]/es2022/react.mjs"
  }
}`);

parseFromHtml(html: string, baseURL?: string)

Parse the first <script type="importmap"> from HTML (browser environment). Returns an empty import map if no importmap script tag is found.

import { parseFromHtml } from "@esm.sh/import-map";

const im = parseFromHtml(`<script type="importmap">
  {
    "imports": {
      "react": "https://esm.sh/[email protected]/es2022/react.mjs"
    }
  }
</script>`);

Note: This function requires a browser environment.

ImportMap.addImport(specifier: string, noSRI?: boolean)

The addImport method fetches package metadata from esm.sh CDN and adds an entry (plus relevant deps) to the map.

Supported specifiers include:

Behavior highlights:

  • adds top-level entries into imports
  • adds nested deps into scopes when needed
  • cleans up empty scopes
  • updates integrity unless noSRI is true
import { ImportMap } from "@esm.sh/import-map";

const im = new ImportMap();
await im.addImport("react-dom@19/client");

setFetcher(fetcher: (url: string | URL) => Promise<Response>)

Override the default fetch used internally by addImport. This is useful for caching metadata responses, or to use a custom fetch implementation.

// Use a custom fetch with cache.
setFetcher(cacheFetch);

// Restore default behavior.
setFetcher(globalThis.fetch);

ImportMap.resolve(specifier: string, containingFile: string)

The resolve method resolves a specifier using import-map matching rules:

const [url, ok] = im.resolve("react", "file:///app/main.ts");

Returns [resolvedUrl, true] when matched, otherwise [originalSpecifier, false].

ImportMap.raw

The raw getter returns a clean, key-ordered import-map object (ImportMapRaw):

const raw = im.raw;
// {
//   config?: { ... },
//   imports?: { ... },
//   scopes?: { ... },
//   integrity?: { ... },
// }

isSupportImportMap()

function isSupportImportMap() returns whether the current browser supports import maps.

import { isSupportImportMap } from "@esm.sh/import-map";

const supported = isSupportImportMap();

Development

bun test
bun run build

License

MIT