NPM.PackageSpec (NPM v0.6.0)

Copy Markdown View Source

Parse npm package specifiers into structured data.

npm supports multiple specifier formats:

lodash          # name only (latest)
lodash@^4.0     # name with range
@scope/pkg@1.0  # scoped with range
npm:react@^18   # alias
file:../local   # file reference
git+https://... # git reference
https://...tgz  # URL tarball

Summary

Functions

Parse a package specifier string.

Check if a specifier targets the registry.

Format a spec back to a string like name@range.

Types

t()

@type t() :: %{
  raw: String.t(),
  name: String.t(),
  range: String.t() | nil,
  type: :registry | :alias | :file | :git | :url
}

Functions

parse(spec)

@spec parse(String.t()) :: t()

Parse a package specifier string.

registry?(arg1)

@spec registry?(t()) :: boolean()

Check if a specifier targets the registry.

to_string(map)

@spec to_string(t()) :: String.t()

Format a spec back to a string like name@range.