\href{https://travis-ci.org/npm/npm-package-arg}{\texttt{ }}

Parses package name and specifier passed to commands like {\ttfamily npm install} or {\ttfamily npm cache add}, or as found in {\ttfamily package.\+json} dependency sections.\hypertarget{md_sfcode_node_modules_npm_registry_fetch_node_modules_npm_package_arg_README_autotoc_md18580}{}\doxysection{EXAMPLES}\label{md_sfcode_node_modules_npm_registry_fetch_node_modules_npm_package_arg_README_autotoc_md18580}

\begin{DoxyCode}{0}
\DoxyCodeLine{var assert = require("{}assert"{})}
\DoxyCodeLine{var npa = require("{}npm-\/package-\/arg"{})}
\DoxyCodeLine{}
\DoxyCodeLine{// Pass in the descriptor, and it'll return an object}
\DoxyCodeLine{try \{}
\DoxyCodeLine{  var parsed = npa("{}@bar/foo@1.2"{})}
\DoxyCodeLine{\} catch (ex) \{}
\DoxyCodeLine{  …}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_npm_registry_fetch_node_modules_npm_package_arg_README_autotoc_md18581}{}\doxysection{USING}\label{md_sfcode_node_modules_npm_registry_fetch_node_modules_npm_package_arg_README_autotoc_md18581}
`var npa = require(\textquotesingle{}npm-\/package-\/arg')\`{}\hypertarget{md_sfcode_node_modules_npm_registry_fetch_node_modules_npm_package_arg_README_autotoc_md18582}{}\doxysubsection{var result = npa($<$em$>$arg$<$/em$>$\mbox{[}, $<$em$>$where$<$/em$>$\mbox{]})}\label{md_sfcode_node_modules_npm_registry_fetch_node_modules_npm_package_arg_README_autotoc_md18582}

\begin{DoxyItemize}
\item {\itshape arg} -\/ a string that you might pass to {\ttfamily npm install}, like\+: {\ttfamily foo@1.\+2}, {\ttfamily @bar/foo@1.\+2}, {\ttfamily foo@user/foo}, {\ttfamily \href{http://x.com/foo.tgz}{\texttt{ http\+://x.\+com/foo.\+tgz}}}, {\ttfamily git+https\+://github.com/user/foo}, {\ttfamily bitbucket\+:user/foo}, {\ttfamily foo.\+tar.\+gz}, {\ttfamily ../foo/bar/} or {\ttfamily bar}. If the {\itshape arg} you provide doesn\textquotesingle{}t have a specifier part, eg {\ttfamily foo} then the specifier will default to {\ttfamily latest}.
\item {\itshape where} -\/ Optionally the path to resolve file paths relative to. Defaults to {\ttfamily process.\+cwd()}
\end{DoxyItemize}

{\bfseries{Throws}} if the package name is invalid, a dist-\/tag is invalid or a URL\textquotesingle{}s protocol is not supported.\hypertarget{md_sfcode_node_modules_npm_registry_fetch_node_modules_npm_package_arg_README_autotoc_md18583}{}\doxysubsection{var result = npa.\+resolve($<$em$>$name$<$/em$>$, $<$em$>$spec$<$/em$>$\mbox{[}, $<$em$>$where$<$/em$>$\mbox{]})}\label{md_sfcode_node_modules_npm_registry_fetch_node_modules_npm_package_arg_README_autotoc_md18583}

\begin{DoxyItemize}
\item {\itshape name} -\/ The name of the module you want to install. For example\+: {\ttfamily foo} or {\ttfamily @bar/foo}.
\item {\itshape spec} -\/ The specifier indicating where and how you can get this module. Something like\+: {\ttfamily 1.\+2}, {\ttfamily $^\wedge$1.7.\+17}, {\ttfamily \href{http://x.com/foo.tgz}{\texttt{ http\+://x.\+com/foo.\+tgz}}}, {\ttfamily git+https\+://github.com/user/foo}, {\ttfamily bitbucket\+:user/foo}, {\ttfamily \href{file:foo.tar.gz}{\texttt{ file\+:foo.\+tar.\+gz}}} or {\ttfamily \href{file:../foo/bar/}{\texttt{ file\+:../foo/bar/}}}. If not included then the default is {\ttfamily latest}.
\item {\itshape where} -\/ Optionally the path to resolve file paths relative to. Defaults to {\ttfamily process.\+cwd()}
\end{DoxyItemize}

{\bfseries{Throws}} if the package name is invalid, a dist-\/tag is invalid or a URL\textquotesingle{}s protocol is not supported.\hypertarget{md_sfcode_node_modules_npm_registry_fetch_node_modules_npm_package_arg_README_autotoc_md18584}{}\doxysection{RESULT OBJECT}\label{md_sfcode_node_modules_npm_registry_fetch_node_modules_npm_package_arg_README_autotoc_md18584}
The objects that are returned by npm-\/package-\/arg contain the following keys\+:


\begin{DoxyItemize}
\item {\ttfamily type} -\/ One of the following strings\+:
\begin{DoxyItemize}
\item {\ttfamily git} -\/ A git repo
\item {\ttfamily tag} -\/ A tagged version, like {\ttfamily \char`\"{}foo@latest\char`\"{}}
\item {\ttfamily version} -\/ A specific version number, like {\ttfamily \char`\"{}foo@1.\+2.\+3\char`\"{}}
\item {\ttfamily range} -\/ A version range, like {\ttfamily \char`\"{}foo@2.\+x\char`\"{}}
\item {\ttfamily file} -\/ A local {\ttfamily .tar.\+gz}, {\ttfamily .tar} or {\ttfamily .tgz} file.
\item {\ttfamily directory} -\/ A local directory.
\item {\ttfamily remote} -\/ An http url (presumably to a tgz)
\end{DoxyItemize}
\item {\ttfamily registry} -\/ If true this specifier refers to a resource hosted on a registry. This is true for {\ttfamily tag}, {\ttfamily version} and {\ttfamily range} types.
\item {\ttfamily name} -\/ If known, the {\ttfamily name} field expected in the resulting pkg.
\item {\ttfamily scope} -\/ If a name is something like {\ttfamily @org/module} then the {\ttfamily scope} field will be set to {\ttfamily @org}. If it doesn\textquotesingle{}t have a scoped name, then scope is {\ttfamily null}.
\item {\ttfamily escaped\+Name} -\/ A version of {\ttfamily name} escaped to match the npm scoped packages specification. Mostly used when making requests against a registry. When {\ttfamily name} is {\ttfamily null}, {\ttfamily escaped\+Name} will also be {\ttfamily null}.
\item {\ttfamily raw\+Spec} -\/ The specifier part that was parsed out in calls to {\ttfamily npa(arg)}, or the value of {\ttfamily spec} in calls to {\ttfamily npa.\+resolve(name, spec). $\ast$}save\+Spec{\ttfamily -\/ The normalized specifier, for saving to package.\+json files. }null{\ttfamily for registry dependencies. $\ast$}fetch\+Spec{\ttfamily -\/ The version of the specifier to be used to fetch this resource.}null\`{} for shortcuts to hosted git dependencies as there isn\textquotesingle{}t just one URL to try with them.
\item {\ttfamily git\+Range} -\/ If set, this is a semver specifier to match against git tags with
\item {\ttfamily git\+Committish} -\/ If set, this is the specific committish to use with a git dependency.
\item {\ttfamily hosted} -\/ If `from === \textquotesingle{}hosted'{\ttfamily then this will be a}hosted-\/git-\/info\`{} object. This property is not included when serializing the object as JSON.
\item {\ttfamily raw} -\/ The original un-\/modified string that was provided. If called as {\ttfamily npa.\+resolve(name, spec)} then this will be `name + '@\textquotesingle{} + spec\`{}. 
\end{DoxyItemize}