parsePackageRepository
Parse the repository field from package.json into a structured object.
Supports all npm-specified formats:
- Object form:
{ "type": "git", "url": "...", "directory": "..." } - GitHub shorthand:
"owner/repo"or"github:owner/repo" - Platform shorthands:
"gitlab:owner/repo","bitbucket:owner/repo" - Gist shorthand:
"gist:<id>" - URL forms:
git+https://,https://,git://,git@SSH,git+ssh://
Returns undefined for null, undefined, arrays, or values that cannot
be matched to any recognised format.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
repository | unknown | The repository field value from package.json. |
Returns
Section titled “Returns”PackageRepository | undefined — A parsed PackageRepository object, or undefined if the
input cannot be parsed.
Examples
Section titled “Examples”Parse the npm canonical object form
Section titled “Parse the npm canonical object form”Parses the full object form written by npm publish.
Parse npm shorthand forms
Section titled “Parse npm shorthand forms”npm accepts “owner/repo”, “github:owner/repo”, “gitlab:owner/repo” etc. as shorthand.
Related Types
Section titled “Related Types”PackageRepository
Section titled “PackageRepository”Structured representation of a parsed repository field from package.json.
