1.1.1 • Published 3 months ago

cdn-resolve v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

cdn-resolve

npm version npm downloads

Resolves packages to their relative CDN URLS.

Features

  • Resolves a package name to a CDN URL
  • Supports all major CDNs (esm.sh, skypack, unpkg, jsdelivr, etc.)
  • Resolves types

📦 Installation

npm install cdn-resolve

📚 Usage

Resolve React from esm.sh

import { buildCDNUrl } from "cdn-resolve";

// You can also import the esm builder directly
import { buildESMUrl } from "cdn-resolve/esm";

const esm = buildCDNUrl("esm");

esm("swr", {
  alias: {
    react: "preact/compat"
  }
});
// => https://esm.sh/swr?alias=react:preact/compat

buildESMUrl("swr", {
  alias: {
    react: "preact/compat"
  }
});

// => https://esm.sh/swr?alias=react:preact/compat

Resolve typedefs for React from esm.sh

import { buildESMUrl } from "cdn-resolve/esm";

const resolved = buildESMUrl("swr@2.1.1", {
  alias: {
    react: "preact/compat"
  }
});

const typesUrl = await resolveESMTypes(resolved);

// => https://esm.sh/v135/swr@2.1.1/X-YS9yZWFjdDpwcmVhY3QvY29tcGF0/core/dist/index.d.ts

Parse a Package Name

import { parsePackage } from "cdn-resolve";

const parsed = parsePackage("vue");

// => {
//   "name": "vue",
//   "version": "latest",
// }

const parsedWithVersion = parsePackage("vue@3.2.47");

// => {
//   "name": "vue",
//   "version": "3.2.47",
// }

const parsedWithPathAndVersion = parsePackage("vue@3.2.47/package.json");

// => {
//   "name": "vue",
//   "version": "3.2.47",
//   "path": "package.json"
// }

📄 License

Published under MIT License.

1.1.1

3 months ago

1.1.0

3 months ago

1.0.1

4 months ago

1.0.0

4 months ago

0.1.5

11 months ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago