public github file to jsdelivr
github-to-jsdelivr.jsJavaScript

github-to-jsdelivr.js

function githubToJsDelivr(url) {
  // Example GitHub URL:
  // https://github.com/username/repo/blob/branch/path/to/file.js

  const regex =
    /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.+)$/;
  const match = url.match(regex);
  if (!match) return null;

  const [, user, repo, branch, path] = match;
  // Build jsDelivr CDN URL
  return `https://cdn.jsdelivr.net/gh/${user}/${repo}@${branch}/${path}`;
}
Updated: 9/27/2025