Skip to main content

XpmPackage.parsePackageSpecifier() method

Parses an npm package specifier into its components.

Signature

parsePackageSpecifier({ npmPackageSpecifier, }: {
npmPackageSpecifier: string;
}): JsonPackageSpecifier;

Parameters

Parameter

Type

Description

{ npmPackageSpecifier, }

{ npmPackageSpecifier: string; }

Returns

JsonPackageSpecifier

The parsed package specifier components.

Exceptions

XpmInputError If the specifier is not a valid package name format.

Remarks

npm package specifiers can take several forms:

  • Unscoped without version: package-name
  • Unscoped with version: package-name@1.2.3
  • Scoped without version: @scope/package-name
  • Scoped with version: @scope/package-name@1.2.3

Parsing strategy:

  1. If specifier starts with @, extract scope and handle scoped format.
  2. Split on / to separate scope from name@version.
  3. Split the second part on @ to separate name from version.
  4. For unscoped packages, split directly on @ to separate name from version.

The parser handles all valid npm package specifier formats and returns structured components for downstream processing. Invalid formats with multiple slashes are rejected.


Generated via tsdoc2docusaurus 1.3.0-pre by API Extractor/Documenter 7.55.2.