UNPKG

vite-plugin-debugger

Version:

A vite plugin provide the debugger tools for mobile devices.

29 lines (28 loc) 1.23 kB
import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; //#region src/helpers/index.ts const transformCDN = async (pkg, cdn) => { if (!["eruda", "vConsole"].includes(pkg)) throw new Error(`The package "${pkg}" is not supported for CDN transformation.`); if (![ "jsdelivr", "unpkg", "cdnjs", "staticfile" ].includes(cdn)) throw new Error(`The CDN "${cdn}" is not supported for "${pkg}".`); if (cdn === "jsdelivr") return `https://cdn.jsdelivr.net/npm/${pkg.toLowerCase()}`; if (cdn === "unpkg") return `https://unpkg.com/${pkg}`; if (cdn === "cdnjs") { const { version } = await fetch(`https://api.cdnjs.com/libraries/${pkg}?fields=version`).then((res) => res.json()); return `https://cdnjs.cloudflare.com/ajax/libs/${pkg}/${version}/${pkg.toLowerCase()}.min.js`; } if (cdn === "staticfile") { const { version, filename } = await fetch(`https://api.staticfile.net/libraries/${pkg}`).then((res) => res.json()); return `https://cdn.staticfile.net/${pkg}/${version}/${filename}`; } return ""; }; const readFileContent = (path) => { return readFileSync(fileURLToPath(new URL(path, import.meta.url)), "utf-8"); }; //#endregion export { transformCDN as n, readFileContent as t };