node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

bitbucket-url-to-object

bitbucket-url-to-object Build Status

A node module that extracts useful properties like user and repo from various flavors of bitbucket URLs.

There's also a GitHub equivalent to this library: github-url-to-object.

Installation

npm install bitbucket-url-to-object --save

Usage

Pass whatever flavor of bitbucket URL you like:

var bb = require('bitbucket-url-to-object')
 
bb('monkey/business')
bb('bitbucket:monkey/business')
bb('https://bitbucket.org/monkey/business')
bb('https://bitbucket.org/monkey/business.git')
bb('http://bitbucket.org/monkey/business')
bb('git://bitbucket.org/monkey/business.git')

Here's what you'll get:

{
  user: 'monkey',
  repo: 'business',
  branch: 'master',
  https_url: 'https://bitbucket.org/monkey/business',
  tarball_url: 'https://bitbucket.org/monkey/business/get/master.tar.gz'
  travis_url: 'https://travis-ci.org/monkey/business',
}

The shorthand format lets you specify a branch:

  bb('monkey/business#nachos')
{
  user: 'monkey',
  repo: 'business',
  branch: 'nachos',
  https_url: 'https://bitbucket.org/monkey/business/tree/nachos',
  tarball_url: 'https://bitbucket.org/monkey/business/get/nachos.tar.gz'
  travis_url: 'https://travis-ci.org/monkey/business',
}

If you provide a non-bitbucket URL or a falsy value, you'll get null.

Test

npm install
npm test

License

MIT