packageRepositoryUrl
Resolve a manifest'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/sshURLs (git+prefix and.gitsuffix stripped)- scp-style locators:
git@github.com:u/r.git - shorthands:
github:u/r,gitlab:u/r,bitbucket:u/r, and bareu/r(GitHub, per npm convention)
Returns undefined when the field is absent or unrecognised — or, with { require: true }, throws instead and the return type is string. (The narrowing cannot key off the input type alone: a present repository may still be an empty string, a url-less object, or an unparseable locator, so the string promise is backed by the runtime check.)
- Import:
@kjanat/dreamcli/config - Export kind: function
- Declared in:
src/core/config/repository-url.ts - Source link:
src/core/config/repository-url.ts:65
Signatures
Overload 1
function packageRepositoryUrl(pkg: PackageJsonData, options: PackageRepositoryUrlOptions & { require: true; }): string;Overload 2
function packageRepositoryUrl(pkg: PackageJsonData, options?: PackageRepositoryUrlOptions): string | undefined;Members
Members
packageRepositoryUrl
Resolve a manifest'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/sshURLs (git+prefix and.gitsuffix stripped)- scp-style locators:
git@github.com:u/r.git - shorthands:
github:u/r,gitlab:u/r,bitbucket:u/r, and bareu/r(GitHub, per npm convention)
Returns undefined when the field is absent or unrecognised — or, with { require: true }, throws instead and the return type is string. (The narrowing cannot key off the input type alone: a present repository may still be an empty string, a url-less object, or an unparseable locator, so the string promise is backed by the runtime check.)
(pkg: PackageJsonData, options: PackageRepositoryUrlOptions & { require: true; }): string;packageRepositoryUrl
Resolve a manifest repository URL, returning undefined for absent or invalid locators.
(pkg: PackageJsonData, options?: PackageRepositoryUrlOptions): string | undefined;Examples
packageRepositoryUrl({ repository: 'git+https://github.com/u/r.git' });
// 'https://github.com/u/r'
const url: string = packageRepositoryUrl(pkg, { require: true });
// throws CLIError when pkg.repository is missing or unrecognised