"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm-package-arg/README.md" (17 Oct 2016, 4151 Bytes) of archive /windows/misc/atom-windows.zip:

As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.


Parse package name and specifier passed to commands like npm install or npm cache add. This just parses the text given– it’s worth noting that npm has further logic it applies by looking at your disk to figure out what ambiguous specifiers are. If you want that logic, please see realize-package-specifier.

Arguments look 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 or bar


```javascript var assert = require(“assert”) var npa = require(“npm-package-arg”)

// Pass in the descriptor, and it’ll return an object var parsed = npa(“@bar/foo@1.2”)

// Returns an object like: { raw: ‘@bar/foo@1.2’, // what was passed in name: ‘@bar/foo’, // the name of the package escapedName: ‘@bar%2ffoo’, // the escaped name, for making requests against a registry scope: ‘@bar’, // the scope of the package, or null type: ‘range’, // the type of specifier this is spec: ‘>=1.2.0 <1.3.0’, // the expanded specifier rawSpec: ‘1.2’ // the specifier as passed in }

// Parsing urls pointing at hosted git services produces a variation: var parsed = npa(“git+https://github.com/user/foo”)

// Returns an object like: { raw: ‘git+https://github.com/user/foo’, scope: null, name: null, escapedName: null, rawSpec: ‘git+https://github.com/user/foo’, spec: ‘user/foo’, type: ‘hosted’, hosted: { type: ‘github’, ssh: ‘git@github.com:user/foo.git’, sshurl: ‘git+ssh://git@github.com/user/foo.git’, https: ‘https://github.com/user/foo.git’, directUrl: ‘https://raw.githubusercontent.com/user/foo/master/package.json’ } }

// 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”) }) ```


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

Parses arg and returns a result object detailing what arg is.

arg – a package descriptor, like: foo@1.2, or foo@user/foo, or http://x.com/foo.tgz, or git+https://github.com/user/foo


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

If you only include a name and no specifier part, eg, foo or foo@ then a default of latest will be used (as of 4.1.0). This is contrast with previous behavior where * was used.