npm-package-arg
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
hosted-git-info | 2.8.9 | 7.92 kB | ISC | prod | |
semver | 5.7.2 | 17.45 kB | ISC | prod |
npm-package-arg is a Node.js package providing parsing capabilities for package names and their specifiers, commonly working in conjunction with commands like npm install
or npm cache add
. It efficiently deciphers arguments that could be passed to npm install
. Besides, it is also capable of understanding the dependencies mentioned in package.json
files.
You can use npm-package-arg to parse package names and their versions, git repos, http URLs, and more. Here's a basic usage example:
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/foo@1.2")
} catch (ex) {
// handle exception
}
The function npa(arg[, where])
parses an arg
string that you might pass to npm install
, returning a result object if the parsing is successful or throwing an error if not. The where
optional argument specifies the path to resolve file paths relative to, and defaults to process.cwd()
.
Using npa.resolve(name, spec[, where])
, you can resolve a module name and specifier to a npm install
-friendly string, and have it relative to a specified where
path.
The function npa.toPurl(arg, reg)
can be used to get the package URL of a given package name/spec.
Example usage:
try {
var resolved = npa.resolve('@foo/bar', '^1.0.0', './some/path')
} catch (ex) {
// handle exception
}
The official documents providing all the detailed information regarding npm-package-arg can be found in npm-package-arg's GitHub README hosted at https://github.com/npm/npm-package-arg. This README presents comprehensive information including examples of several possible arguments, describing how the package functions, how to use it, and explaining the structure of the output.