Gathering detailed insights and metrics for npm-package-arg
Gathering detailed insights and metrics for npm-package-arg
Gathering detailed insights and metrics for npm-package-arg
Gathering detailed insights and metrics for npm-package-arg
Parse the things that can be arguments to `npm install`
npm install npm-package-arg
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.3
Supply Chain
100
Quality
85
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
2,657,344,416
Last Day
842,315
Last Week
17,037,713
Last Month
74,466,212
Last Year
779,061,419
ISC License
130 Stars
259 Commits
42 Forks
27 Watchers
3 Branches
89 Contributors
Updated on Jun 19, 2025
Minified
Minified + Gzipped
Latest Version
12.0.2
Package Id
npm-package-arg@12.0.2
Unpacked Size
21.33 kB
Size
7.82 kB
File Count
4
NPM Version
11.1.0
Node Version
22.13.1
Published on
Feb 05, 2025
Cumulative downloads
Total Downloads
Last Day
-11.1%
842,315
Compared to previous day
Last Week
-8.2%
17,037,713
Compared to previous week
Last Month
3.5%
74,466,212
Compared to previous month
Last Year
27.9%
779,061,419
Compared to previous year
3
Parses package name and specifier passed to commands like npm install
or
npm cache add
, or as found in package.json
dependency sections.
1const assert = require("assert") 2const npa = require("npm-package-arg") 3 4// Pass in the descriptor, and it'll return an object 5try { 6 const parsed = npa("@bar/foo@1.2") 7} catch (ex) { 8 … 9}
const npa = require('npm-package-arg')
npm install
, like:
foo@1.2
, @bar/foo@1.2
, 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 specifier
part, eg foo
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 not
included then the default is latest
.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.
foo@1.0.0
or @bar/foo@2.0.0-alpha.1
.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 "foo@1.2.3"
range
- A version range, like "foo@2.x"
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:foo@1.2.3
registry
- If true this specifier refers to a resource hosted on a
registry. This is true for tag
, 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
field will be set to @org
. If it doesn't have a scoped name, then
scope is null
.escapedName
- A version of name
escaped to match the npm scoped packages
specification. Mostly used when making requests against a registry. When
name
is null
, escapedName
will also be null
.rawSpec
- The specifier part that was parsed out in calls to npa(arg)
,
or the value of spec
in calls to npa.resolve(name, spec)
.saveSpec
- The normalized specifier, for saving to package.json files.
null
for registry dependencies. See note below about how this is (not) encoded.fetchSpec
- The version of the specifier to be used to fetch this
resource. null
for shortcuts to hosted git dependencies as there isn't
just one URL to try with them.gitRange
- 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
object. This property is not included when serializing the object as
JSON.raw
- The original un-modified string that was provided. If called as
npa.resolve(name, spec)
then this will be name + '@' + spec
.subSpec
- If type === 'alias'
, this is a Result Object for parsing the
target specifier for the alias.TLDR: file:
urls are NOT uri encoded.
Historically, npm would uri decode file package args, but did not do any uri encoding for the saveSpec
. This meant that it generated incorrect saveSpecs for directories with characters that looked like encoded uri characters, and also that it could not parse directories with some unencoded uri characters (such as %
).
In order to fix this, and to not break all existing versions of npm, this module now parses all file package args as not being uri encoded. And in order to not break all of the package.json files npm has made in the past, it also does not uri encode the saveSpec. This includes package args that start with file:
. This does mean that npm file:
package args are not RFC compliant, and making them so constitutes quite a breaking change.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
all changesets reviewed
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More