hosted-git-info by Rebecca Turner of the NPM Inc is another fantastic ulitify module for parsing, breaking down and reusing GitHub, BitBucket and GitLab project URLs. It has a simple API and comes with full test coverage.
npm install hosted-git-info
var hostedGitInfo = require('hosted-git-info'); var info = hostedGitInfo.fromUrl('firstname.lastname@example.org:npmawesome/example-hosted-git-info.git'); console.log(JSON.stringify(info, null, 2));
Once you have results object, a few convinience methods are provided for your enjoyment.
console.log(info.file('/package.json')); console.log(info.shortcut()); console.log(info.browse()); console.log(info.bugs()); console.log(info.docs()); console.log(info.https()); console.log(info.sshurl()); console.log(info.ssh()); console.log(info.path());
I like that Rebecca Turner released version 1.0 instead of forever iterating on 0.0.x which has been the trend in the last couple of years. I’m a strong advocate of 1.0 releases as soon as it makes sense.