Package Exports
- npm-package-arg
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (npm-package-arg) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
npm-package-arg
Parse the things that can be arguments to npm install
Takes an argument like foo@1.2
, or foo@user/foo
, or
http://x.com/foo.tgz
, or git+https://github.com/user/foo
, and
figures out what type of thing it is.
USAGE
var assert = require("assert")
var npa = require("npm-package-arg")
// Pass in the descriptor, and it'll return an object
var parsed = npa("foo@1.2")
// Returns an object like:
// {
// name: "foo", // The bit in front of the @
// type: "range", // the type of descriptor this is
// spec: "1.2" // the specifier for this descriptor
// }
// Completely unreasonable invalid garbage throws an error
// Make sure you wrap this in a try/catch if you have not
// already sanitized the inputs!
assert.throws(function() {
npa("this is not \0 a valid package name or url")
})
For more examples, see the test file.
Result Objects
The objects that are returned by npm-package-arg contain the following fields:
name
- If known, thename
field expected in the resulting pkg.type
- One of the following strings:git
- A git repogithub
- A github shorthand, likeuser/project
tag
- A tagged version, like"foo@latest"
version
- A specific version number, like"foo@1.2.3"
range
- A version range, like"foo@2.x"
local
- A local file or folder pathremote
- An http url (presumably to a tgz)
spec
- The "thing". URL, the range, git repo, etc.raw
- The original un-modified string that was provided.rawSpec
- The part after thename@...
, as it was originally provided.scope
- If a name is something like@org/module
then thescope
field will be set toorg
. If it doesn't have a scoped name, then scope isnull
.