Coder Social home page Coder Social logo

ruyadorno / npm-package-arg Goto Github PK

View Code? Open in Web Editor NEW

This project forked from npm/npm-package-arg

0.0 1.0 0.0 1.14 MB

Parse the things that can be arguments to `npm install`

Home Page: http://npm.im/npm-package-arg

License: ISC License

JavaScript 100.00%

npm-package-arg's Introduction

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/[email protected]")
} 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: [email protected], @bar/[email protected], 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.

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 "[email protected]"
    • range - A version range, like "[email protected]"
    • file - A local .tar.gz, .tar or .tgz file.
    • directory - A local directory.
    • remote - An http url (presumably to a tgz)
  • 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.

npm-package-arg's People

Contributors

ajcrites avatar andreeib avatar ashleygwilliams avatar bacra avatar darcyclarke avatar dguettler avatar dylang avatar iarna avatar isaacs avatar nexdrew avatar nlf avatar othiym23 avatar ruyadorno avatar zkat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.