0.1.0 • Published 3 years ago

infer-repo-url v0.1.0

Weekly downloads
-
License
Unlicense
Repository
github
Last release
3 years ago

infer-repo-url npm version

Infer repo URL from package.json or .git/config.

Overview

From the CWD or the given path, try to infer the repo URL from the repository field of package.json, otherwise fall back to the origin remote in .git/config.

You can chose to only use the package.json or .git/config logic, and you can get the full hosted-git-info object if you want to instead of the browse URL that's returned by default.

Installation

npm install infer-repo-url

Usage

const inferRepoUrl = require('infer-repo-url')

async function main () {
  const url = await inferRepoUrl() // Read `repository` from `package.json`, fall back to `origin` remote in `.git/config`
  const url = await inferRepoUrl.fromPackage() // Only read from `package.json`
  const url = await inferRepoUrl.fromGit() // Only read from `.git/config`

  // Same with `/path/to/repo/package.json` and `/path/to/repo/.git/config`
  const url = await inferRepoUrl('/path/to/repo')
  const url = await inferRepoUrl.fromPackage('/path/to/repo')
  const url = await inferRepoUrl.fromGit('/path/to/repo')

  // Get the full hosted-git-info object.
  const info = await inferRepoUrl.full()
  const info = await inferRepoUrl.full.fromPackage()
  const info = await inferRepoUrl.full.fromGit('/path/to/repo')
}

main()