11.0.1 • Published 7 months ago

npm-package-arg v11.0.1

Weekly downloads
6,076,151
License
ISC
Repository
github
Last release
7 months ago

npm-package-arg

Build Status

Parses package name and specifier passed to commands like npm install or npm cache add, or as found in package.json dependency sections.

EXAMPLES

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) {
  …
}

USING

var npa = require('npm-package-arg')

var result = npa(arg, where)

  • arg - a string that you might pass to 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.
  • where - Optionally the path to resolve file paths relative to. Defaults to process.cwd()

Throws if the package name is invalid, a dist-tag is invalid or a URL's protocol is not supported.

var result = npa.resolve(name, spec, where)

  • name - The name of the module you want to install. For example: foo or @bar/foo.
  • spec - The specifier indicating where and how you can get this module. Something like: 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.
  • where - Optionally the path to resolve file paths relative to. Defaults to process.cwd()

Throws if the package name is invalid, a dist-tag is invalid or a URL's protocol is not supported.

var purl = npa.toPurl(arg, reg)

Returns the purl (package URL) form of the given package name/spec.

  • arg - A package/version string. For example: foo@1.0.0 or @bar/foo@2.0.0-alpha.1.
  • reg - Optionally the URL to the package registry. If not specified, assumes the default https://registry.npmjs.org.

Throws if the package name is invalid, or the supplied arg can't be resolved to a purl.

RESULT OBJECT

The objects that are returned by npm-package-arg contain the following keys:

  • type - One of the following strings:
    • git - A git repo
    • 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"
    • 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.
  • 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 with
  • gitCommittish - 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.
npm-pick-manifestnpmnpm-registry-fetchpacote@lerna/conventional-commits@lerna/create@lerna/npm-dist-tag@lerna/npm-install@lerna/npm-publish@lerna/package@lerna/package-graphinit-package-jsonlerna@schematics/update@evocateur/npm-registry-fetch@angular/cli@megasaur/add@megasaur/bootstrap@megasaur/conventional-commits@megasaur/create@megasaur/map-to-registry@megasaur/npm-install@megasaur/package@megasaur/package-graph@megasaur/publishcordova-fetchcordova-createkilli8n-react-native-fast-image@cashremit/cr-streamline-icons@adobe/aio-cli-plugin-cna@frxf/frxfregenie@jttechnic/interpreter@saeon/ol-react@saeon/quick-formcogoportutilsgtpmgtmp@mink-opn/build-tokens@gratico/npmfpd@everything-registry/sub-chunk-2341@gigster/gig-utils@buganto/client@billogram/janitor@binarybutterfly/k-cli@cdk8s-extensions/argo-rollout@byted-apaas/cli-plugins-loader@cnpmjs/rapid@chrisy163/auto-update-package@clinpm/npm-registry-client@beisen/monorepo-package@beisen/npmunpkgfs@cleveradssolutions/cas.cordova.mintegral@ibm-wch-sdk/cli@ibm-wch/cli-create-layout-react@ibm-wch/cli-create-layout-react-vue@kuinox/testpackagethatnooneshoulduse@kuinox/testpackagethatnooneshoulduseever@lando/core@marinaga/bananize@likely-cli/package@lerna-lite/core@lerna-lite/publish@lerna-lite/version@lerna/legacy-package-management@lerna/map-to-registryqxf2006hf0216qap_install@jasonssun/npmpublish-current-version@iold/old-corepxnpminstalldatetimemodulepzmtestpyreswap-sdk@jakenewby/ember-cli@lugia/mega-utils@lugia/cli-package@lugia/npm-utils@gitlab/untamper-my-lockfile@merlion/ape-core@merna/add@merna/bootstrap@merna/conventional-commits@merna/create@merna/map-to-registry@merna/npm-dist-tag@merna/npm-install@merna/npm-publish@mishguru/selfupdatereact-picky-with-clear@micro-app/shared-utilsreact-native-video-typo@merna/package@merna/package-graph@merna/publish@jduarter/expo-clitomo-cli
11.0.1

7 months ago

11.0.0

7 months ago

10.0.0

1 year ago

10.1.0

1 year ago

9.1.2

1 year ago

9.1.1

1 year ago

9.1.0

2 years ago

9.0.2

2 years ago

9.0.1

2 years ago

9.0.0

2 years ago

8.1.5

3 years ago

8.1.4

3 years ago

8.1.3

3 years ago

8.1.2

3 years ago

8.1.1

3 years ago

8.1.0

3 years ago

8.0.1

4 years ago

8.0.0

4 years ago

7.0.0

4 years ago

6.1.1

5 years ago

6.1.0

6 years ago

6.0.0

6 years ago

5.1.2

7 years ago

5.1.1

7 years ago

5.1.0

7 years ago

5.0.1

7 years ago

5.0.0

7 years ago

4.2.1

7 years ago

4.2.0

8 years ago

4.1.1

8 years ago

4.1.0

8 years ago

4.0.2

9 years ago

4.0.1

9 years ago

4.0.0

9 years ago

3.1.1

9 years ago

3.1.0

9 years ago

3.0.0

9 years ago

2.1.3

9 years ago

2.1.2

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.4

10 years ago

2.0.3

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago