Skip to content

Instantly share code, notes, and snippets.

@phlinhng
Last active July 10, 2021 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phlinhng/d2faca87338eeceb8ee44aa22cf02b39 to your computer and use it in GitHub Desktop.
Save phlinhng/d2faca87338eeceb8ee44aa22cf02b39 to your computer and use it in GitHub Desktop.
let github2jsdelivr = (_url) => {
regex = {"blob": /(.+)github.com\/(.+)\/(.+)\/blob\/(.+)\/(.+)/,
"tree": /(.+)github.com\/(.+)\/(.+)\/blob\/(.+)\/(.+)/};
if(_url.match(regex.tree)){
return _url.replace(regex.tree, "$1cdn.jsdelivr.net/gh/$2/$3@$4/$5");
}else if(_url.match(regex.blob)){
return _url.replace(regex.blob, "$1cdn.jsdelivr.net/gh/$2/$4@$4/$5");
}else{
return _url;
}
}
console.log(github2jsdelivr(process.argv[2]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment