packageRepositoryUrl
Generated reference page for the packageRepositoryUrl function export.
- Import:
@kjanat/dreamcli - Export kind: function
- Declared in:
src/core/config/package-json.ts - Source link:
src/core/config/package-json.ts:492
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 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/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 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/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): 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 unrecognisedpackageRepositoryUrl({ 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