Skip to content

luxass/cdn-resolve

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

cdn-resolve

npm version npm downloads

Resolves packages to their relative CDN URLS.

Note

Skypack was recently removed in version v2.0.0, since it wa unmainted and new code was breaking it. So if you are using Skypack, please use version v1.4.1

Features

  • Resolves a package name to a CDN URL
  • Supports all major CDNs (esm.sh, 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("[email protected]", {
  alias: {
    react: "preact/compat"
  }
});

const typesUrl = await resolveESMTypes(resolved);

// => https://esm.sh/v135/[email protected]/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("[email protected]");

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

const parsedWithPathAndVersion = parsePackage("[email protected]/package.json");

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

๐Ÿ“„ License

Published under MIT License.

About

๐Ÿ“ฆ Resolves packages to their CDN url

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Contributors 2

  •  
  •