Skip to content

packageRepositoryUrl

Generated reference page for the packageRepositoryUrl function export.

Signatures

ts
function packageRepositoryUrl(pkg: PackageJsonData): string | undefined;

Members

Members

packageRepositoryUrl

Resolve a package's repository field to a browsable https:// URL.

Handles the locator formats npm accepts:

  • object form: { "type": "git", "url": "git+https://github.com/u/r.git" }
  • https/git/ssh URLs (git+ prefix and .git suffix stripped)
  • scp-style locators: git@github.com:u/r.git
  • shorthands: github:u/r, gitlab:u/r, bitbucket:u/r, and bare u/r (GitHub, per npm convention)

Returns undefined when the field is absent or unrecognised.

ts
(pkg: PackageJsonData): string | undefined;

Examples

ts
packageRepositoryUrl({ repository: 'git+https://github.com/u/r.git' });
// 'https://github.com/u/r'

See Also

Released under the MIT License.