UNPKG

cdn-resolve

Version:

Resolves import paths to their CDN equivalents

23 lines (21 loc) 649 B
import { parsePackage } from "./parse-DfZc17eY.js"; //#region src/unpkg.ts /** * Builds the URL for the specified module on unpkg.com. * @param {string} module - The name of the module. * @param {UnpkgOptions} options - configuration options. * @returns {URL} The URL for the module on unpkg.com. */ function buildUnpkgUrl(module, options) { try { const pkg = parsePackage(module); const url = new URL(pkg.full, "https://unpkg.com/"); if (options?.meta) url.searchParams.set("meta", "true"); if (options?.module) url.searchParams.set("module", "true"); return url; } catch { return void 0; } } //#endregion export { buildUnpkgUrl };