https://github.com/luxass/cdn-resolve
📦 Resolves packages to their CDN url
https://github.com/luxass/cdn-resolve
cdn esm jsdelivr skypack unpkg
Last synced: over 1 year ago
JSON representation
📦 Resolves packages to their CDN url
- Host: GitHub
- URL: https://github.com/luxass/cdn-resolve
- Owner: luxass
- License: mit
- Created: 2023-03-27T17:50:47.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T20:51:33.000Z (over 1 year ago)
- Last Synced: 2025-03-10T21:33:51.850Z (over 1 year ago)
- Topics: cdn, esm, jsdelivr, skypack, unpkg
- Language: TypeScript
- Homepage:
- Size: 485 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# cdn-resolve
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
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
```sh
npm install cdn-resolve
```
## 📚 Usage
Resolve React from [esm.sh](https://esm.sh)
```js
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](https://esm.sh)
```js
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
```js
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](./LICENSE).
[npm-version-src]: https://img.shields.io/npm/v/cdn-resolve?style=flat&colorA=18181B&colorB=4169E1
[npm-version-href]: https://npmjs.com/package/cdn-resolve
[npm-downloads-src]: https://img.shields.io/npm/dm/cdn-resolve?style=flat&colorA=18181B&colorB=4169E1
[npm-downloads-href]: https://npmjs.com/package/cdn-resolve