Socket
Socket
Sign inDemoInstall

cdn-resolve

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cdn-resolve

Resolves import paths to their CDN equivalents


Version published
Weekly downloads
10
decreased by-64.29%
Maintainers
0
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 30 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc