npmawesome: parse and reuse GitHub URLs with hosted-git-info
About the author
Other popular posts
This is a guest post from Alex Gorbatchev over at npmawesome.com. Nodejitsu loved what npmawesome.com was doing and is now supporting the project.
hosted-git-info (GitHub: npm/hosted-git-info, License: ISC) 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('email@example.com: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.
Checkout the runnable example and github example repository.