Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

repo-utils

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

repo-utils

Utils for normalizing and formatting repo data.

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23K
decreased by-2.93%
Maintainers
1
Weekly downloads
 
Created
Source

repo-utils NPM version NPM downloads Build Status

Utils for normalizing and formatting repo data.

Install

Install with npm:

$ npm install repo-utils --save

Usage

var repoUtils = require('repo-utils');

API

.name

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());
//=> 'repo-utils'
repoUtils.name('.');
//=> 'repo-utils'
repoUtils.name();
//=> 'repo-utils'

repoUtils.name('https://github.com/jonschlinkert/repo-utils');
//=> 'repo-utils'
repoUtils.name('jonschlinkert/repo-utils');
//=> 'repo-utils'

.repository

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');
//=> 'jonschlinkert/micromatch'

repoUtils.repository({owner: 'jonschlinkert', repository: 'micromatch'});
//=> 'jonschlinkert/micromatch'

repoUtils.repository('https://github.com/jonschlinkert/micromatch');
//=> 'jonschlinkert/micromatch'

.homepage

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');
//=> 'https://github.com/jonchlinkert/repo-utils'

.issues

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');
//=> 'https://github.com/jonchlinkert/micromatch/issues'

.bugs

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');
//=> 'https://github.com/jonchlinkert/micromatch/issues'

.https

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');
//=> 'https://github.com/jonchlinkert/micromatch'

.travis

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');
//=> 'https://travis-ci.org/jonschlinkert/micromatch'

.file

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');
//=> 'https://raw.githubusercontent.com/jonschlinkert/micromatch/master/README.md'

repoUtils.raw('jonschlinkert/micromatch', 'README.md');
//=> 'https://raw.githubusercontent.com/jonschlinkert/micromatch/master/README.md'

.raw

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');
//=> 'https://raw.githubusercontent.com/jonschlinkert/micromatch/master/README.md'

repoUtils.raw('jonschlinkert/micromatch', 'README.md');
//=> 'https://raw.githubusercontent.com/jonschlinkert/micromatch/master/README.md'

.isGithubUrl

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');
//=> true
utils.isGithubUrl('https://foo.com/whatever');
//=> false

.parseUrl

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

// see the tests for supported formats
repoUtils.parse('https://raw.githubusercontent.com/jonschlinkert/micromatch/master/README.md');

// results in:
{ 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' }

.expandUrl

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

// see the tests for supported formats
repoUtils.expand('https://github.com/abc/xyz.git', 'README.md');

// results in:
{ 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.

Keywords

FAQs

Package last updated on 29 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc