repo-utils

Utils for normalizing and formatting repo data.
Install
Install with npm:
$ npm install repo-utils --save
Usage
var repoUtils = require('repo-utils');
API
Get the name for a repository from: - github repository path (owner/project-name) - github URL - absolute file path to a directory on the local file system (. and '' may be used as aliases for the current working directory)
Params
cwd {String}: Absolute file path or github URL
returns {String}: Project name
Example
repoUtils.name(process.cwd());
repoUtils.name('.');
repoUtils.name();
repoUtils.name('https://github.com/jonschlinkert/repo-utils');
repoUtils.name('jonschlinkert/repo-utils');
Create a github repository string in the form of owner/name, from: - full github repository URL - object returned from url.parse - list of arguments in the form of owner, name
Params
owner {String}: Repository owner
name {String}: Repository name
returns {String}: Reps
Example
repoUtils.repository('jonschlinkert', 'micromatch');
repoUtils.repository({owner: 'jonschlinkert', repository: 'micromatch'});
repoUtils.repository('https://github.com/jonschlinkert/micromatch');
Create a homepage URL from a github repository path or github repository URL.
Params
repository {String}: Repository in the form of owner/project-name
options {Object}
returns {String}: Formatted github homepage url.
Example
repoUtils.homepage('jonschlinkert/repo-utils');
Create a GitHub issues URL.
Params
repository {String}: Repository in the form of owner/project-name or full github project URL.
options {Object}
returns {String}
Example
repoUtils.isses('jonschlinkert/micromatch');
Create a GitHub bugs URL. Alias for .issues.
Params
repository {String}: Repository in the form of owner/project-name
options {Object}
returns {String}
Example
repoUtils.bugs('jonschlinkert/micromatch');
Create a github https URL.
Params
repository {String}: Repository in the form of owner/project-name
options {Object|String}: Options object or optional branch
branch {String}: Optionally specify a branch
returns {String}
Example
repoUtils.https('jonschlinkert/micromatch');
Create a travis URL.
Params
repository {String}: Repository in the form of owner/project-name
options {Object|String}: Options object or optional branch
branch {String}: Optionally specify a branch
returns {String}
Example
repoUtils.travis('jonschlinkert/micromatch');
Create a URL for a file in a github repository.
Params
repository {String}: Repository in the form of owner/project-name or full GitHub repository URL.
branch {String}: Optionally specify a branch
path {String}: Path to the file, relative to the repository root.
returns {String}
Example
repoUtils.file('https://github.com/jonschlinkert/micromatch', 'README.md');
repoUtils.raw('jonschlinkert/micromatch', 'README.md');
Create a github "raw" content URL.
Params
repository {String}: Repository in the form of owner/project-name
options {Object|String}: Options object or optional branch
branch {String}: Optionally specify a branch
returns {String}
Example
repoUtils.raw('https://github.com/jonschlinkert/micromatch', 'README.md');
repoUtils.raw('jonschlinkert/micromatch', 'README.md');
Return true if the given string looks like a github URL.
Params
str {String}: URL to test
returns {Boolean}
Example
utils.isGithubUrl('https://github.com/whatever');
utils.isGithubUrl('https://foo.com/whatever');
Parse a GitHub repository URL or repository owner/project-name into an object.
Params
repositoryURL {String}: Full repository URL, or repository path in the form of owner/project-name
options {Object}
returns {Boolean}
Example
repoUtils.parse('https://raw.githubusercontent.com/jonschlinkert/micromatch/master/README.md');
{ protocol: 'https:',
slashes: true,
hostname: 'raw.githubusercontent.com',
host: 'raw.githubusercontent.com',
pathname: 'https://raw.githubusercontent.com/foo/bar/master/README.md',
path: '/foo/bar/master/README.md',
href: 'https://raw.githubusercontent.com/foo/bar/master/README.md',
owner: 'foo',
name: 'bar',
repo: 'foo/bar',
repository: 'foo/bar',
branch: 'master' }
Parse a GitHub repository path or URL by calling repo.parseUrl(), then expands it into an object of URLs. (the object also includes properties returned from .parse()). A file path maybe be passed as the second argument to include raw and file properties in the result.
Params
repository {String}
file {String}: Optionally pass a repository file path.
returns {String}
Example
repoUtils.expand('https://github.com/abc/xyz.git', 'README.md');
{ protocol: 'https:',
slashes: true,
hostname: 'github.com',
host: 'github.com',
pathname: 'https://github.com/abc/xyz.git',
path: '/abc/xyz.git',
href: 'https://github.com/abc/xyz.git',
owner: 'abc',
name: 'xyz',
repo: 'abc/xyz',
repository: 'abc/xyz',
branch: 'master',
host_api: 'api.github.com',
host_raw: 'https://raw.githubusercontent.com',
api: 'https://api.github.com/repos/abc/xyz',
tarball: 'https://api.github.com/repos/abc/xyz/tarball/master',
clone: 'https://github.com/abc/xyz',
zip: 'https://github.com/abc/xyz/archive/master.zip',
https: 'https://github.com/abc/xyz',
travis: 'https://travis-ci.org/abc/xyz',
file: 'https://github.com/abc/xyz/blob/master/README.md',
raw: 'https://raw.githubusercontent.com/abc/xyz/master/README.md' }
Coverage
As of March 29, 2016:
Statements : 71.19% ( 126/177 )
Branches : 59.13% ( 68/115 )
Functions : 59.09% ( 13/22 )
Lines : 71.59% ( 126/176 )
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
This file was generated by verb, v, on March 29, 2016.