Parse the things that can be arguments to `npm install`
ISC License
Parses package name and specifier passed to commands like npm install
or
npm cache add
, or as found in package.json
dependency sections.
var assert = require("assert")
var npa = require("npm-package-arg")
// Pass in the descriptor, and it'll return an object
try {
var parsed = npa("@bar/[email protected]")
} catch (ex) {
…
}
var npa = require('npm-package-arg')
npm install
, like:[email protected]
, @bar/[email protected]
, foo@user/foo
, http://x.com/foo.tgz
,git+https://github.com/user/foo
, bitbucket:user/foo
, foo.tar.gz
,../foo/bar/
or bar
. If the arg you provide doesn't have a specifierfoo
then the specifier will default to latest
.process.cwd()
Throws if the package name is invalid, a dist-tag is invalid or a URL's protocol is not supported.
foo
or @bar/foo
.1.2
, ^1.7.17
, http://x.com/foo.tgz
, git+https://github.com/user/foo
,bitbucket:user/foo
, file:foo.tar.gz
or file:../foo/bar/
. If notlatest
.process.cwd()
Throws if the package name is invalid, a dist-tag is invalid or a URL's protocol is not supported.
Returns the purl (package URL) form of the given package name/spec.
[email protected]
or @bar/[email protected]
.https://registry.npmjs.org
.Throws if the package name is invalid, or the supplied arg can't be resolved to a purl.
The objects that are returned by npm-package-arg contain the following keys:
type
- One of the following strings:
git
- A git repotag
- A tagged version, like "foo@latest"
version
- A specific version number, like "[email protected]"
range
- A version range, like "[email protected]"
file
- A local .tar.gz
, .tar
or .tgz
file.directory
- A local directory.remote
- An http url (presumably to a tgz)alias
- A specifier with an alias, like myalias@npm:[email protected]
registry
- If true this specifier refers to a resource hosted on atag
, version
and range
types.name
- If known, the name
field expected in the resulting pkg.scope
- If a name is something like @org/module
then the scope
@org
. If it doesn't have a scoped name, thennull
.escapedName
- A version of name
escaped to match the npm scoped packagesname
is null
, escapedName
will also be null
.rawSpec
- The specifier part that was parsed out in calls to npa(arg)
,spec
in calls to `npa.resolve(name, spec).saveSpec
- The normalized specifier, for saving to package.json files.null
for registry dependencies.fetchSpec
- The version of the specifier to be used to fetch thisnull
for shortcuts to hosted git dependencies as there isn'tgitRange
- If set, this is a semver specifier to match against git tags withgitCommittish
- If set, this is the specific committish to use with a git dependency.hosted
- If from === 'hosted'
then this will be a hosted-git-info
raw
- The original un-modified string that was provided. If called asnpa.resolve(name, spec)
then this will be name + '@' + spec
.subSpec
- If type === 'alias'
, this is a Result Object for parsing the