normalize-\/package-\/data exports a function that normalizes package metadata. This data is typically found in a package.\+json file, but in principle could come from any source -\/ for example the npm registry.

normalize-\/package-\/data is used by \href{https://npmjs.org/package/read-package-json}{\texttt{ read-\/package-\/json}} to normalize the data it reads from a package.\+json file. In turn, read-\/package-\/json is used by \href{https://npmjs.org/package/npm}{\texttt{ npm}} and various npm-\/related tools.\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18340}{}\doxysection{Installation}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18340}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm install normalize-\/package-\/data }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18341}{}\doxysection{Usage}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18341}
Basic usage is really simple. You call the function that normalize-\/package-\/data exports. Let\textquotesingle{}s call it {\ttfamily normalize\+Data}.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeData = require('normalize-\/package-\/data')}
\DoxyCodeLine{packageData = require("{}./package.json"{})}
\DoxyCodeLine{normalizeData(packageData)}
\DoxyCodeLine{// packageData is now normalized }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18342}{}\doxysubsubsection{Strict mode}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18342}
You may activate strict validation by passing true as the second argument.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeData = require('normalize-\/package-\/data')}
\DoxyCodeLine{packageData = require("{}./package.json"{})}
\DoxyCodeLine{normalizeData(packageData, true)}
\DoxyCodeLine{// packageData is now normalized }

\end{DoxyCode}


If strict mode is activated, only Semver 2.\+0 version strings are accepted. Otherwise, Semver 1.\+0 strings are accepted as well. Packages must have a name, and the name field must not have contain leading or trailing whitespace.\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18343}{}\doxysubsubsection{Warnings}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18343}
Optionally, you may pass a \char`\"{}warning\char`\"{} function. It gets called whenever the {\ttfamily normalize\+Data} function encounters something that doesn\textquotesingle{}t look right. It indicates less than perfect input data.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeData = require('normalize-\/package-\/data')}
\DoxyCodeLine{packageData = require("{}./package.json"{})}
\DoxyCodeLine{warnFn = function(msg) \{ console.error(msg) \}}
\DoxyCodeLine{normalizeData(packageData, warnFn)}
\DoxyCodeLine{// packageData is now normalized. Any number of warnings may have been logged. }

\end{DoxyCode}


You may combine strict validation with warnings by passing {\ttfamily true} as the second argument, and {\ttfamily warn\+Fn} as third.

When {\ttfamily private} field is set to {\ttfamily true}, warnings will be suppressed.\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18344}{}\doxysubsection{Potential exceptions}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18344}
If the supplied data has an invalid name or version vield, {\ttfamily normalize\+Data} will throw an error. Depending on where you call {\ttfamily normalize\+Data}, you may want to catch these errors so can pass them to a callback.\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18345}{}\doxysection{What normalization (currently) entails}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18345}

\begin{DoxyItemize}
\item The value of {\ttfamily name} field gets trimmed (unless in strict mode).
\item The value of the {\ttfamily version} field gets cleaned by {\ttfamily semver.\+clean}. See \href{https://github.com/isaacs/node-semver}{\texttt{ documentation for the semver module}}.
\item If {\ttfamily name} and/or {\ttfamily version} fields are missing, they are set to empty strings.
\item If {\ttfamily files} field is not an array, it will be removed.
\item If {\ttfamily bin} field is a string, then {\ttfamily bin} field will become an object with {\ttfamily name} set to the value of the {\ttfamily name} field, and {\ttfamily bin} set to the original string value.
\item If {\ttfamily man} field is a string, it will become an array with the original string as its sole member.
\item If {\ttfamily keywords} field is string, it is considered to be a list of keywords separated by one or more white-\/space characters. It gets converted to an array by splitting on {\ttfamily \textbackslash{}s+}.
\item All people fields ({\ttfamily author}, {\ttfamily maintainers}, {\ttfamily contributors}) get converted into objects with name, email and url properties.
\item If {\ttfamily bundled\+Dependencies} field (a typo) exists and {\ttfamily bundle\+Dependencies} field does not, {\ttfamily bundled\+Dependencies} will get renamed to {\ttfamily bundle\+Dependencies}.
\item If the value of any of the dependencies fields ({\ttfamily dependencies}, {\ttfamily dev\+Dependencies}, {\ttfamily optional\+Dependencies}) is a string, it gets converted into an object with familiar {\ttfamily name=$>$value} pairs.
\item The values in {\ttfamily optional\+Dependencies} get added to {\ttfamily dependencies}. The {\ttfamily optional\+Dependencies} array is left untouched.
\item As of v2\+: Dependencies that point at known hosted git providers (currently\+: github, bitbucket, gitlab) will have their URLs canonicalized, but protocols will be preserved.
\item As of v2\+: Dependencies that use shortcuts for hosted git providers ({\ttfamily org/proj}, {\ttfamily github\+:org/proj}, {\ttfamily bitbucket\+:org/proj}, {\ttfamily gitlab\+:org/proj}, {\ttfamily gist\+:docid}) will have the shortcut left in place. (In the case of github, the {\ttfamily org/proj} form will be expanded to {\ttfamily github\+:org/proj}.) THIS MARKS A BREAKING CHANGE FROM V1, where the shorcut was previously expanded to a URL.
\item If {\ttfamily description} field does not exist, but {\ttfamily readme} field does, then (more or less) the first paragraph of text that\textquotesingle{}s found in the readme is taken as value for {\ttfamily description}.
\item If {\ttfamily repository} field is a string, it will become an object with {\ttfamily url} set to the original string value, and {\ttfamily type} set to {\ttfamily \char`\"{}git\char`\"{}}.
\item If {\ttfamily repository.\+url} is not a valid url, but in the style of \char`\"{}\mbox{[}owner-\/name\mbox{]}/\mbox{[}repo-\/name\mbox{]}\char`\"{}, {\ttfamily repository.\+url} will be set to git+https\+://github.com/\mbox{[}owner-\/name\mbox{]}/\mbox{[}repo-\/name\mbox{]}.git
\item If {\ttfamily bugs} field is a string, the value of {\ttfamily bugs} field is changed into an object with {\ttfamily url} set to the original string value.
\item If {\ttfamily bugs} field does not exist, but {\ttfamily repository} field points to a repository hosted on Git\+Hub, the value of the {\ttfamily bugs} field gets set to an url in the form of \href{https://github.com/}{\texttt{ https\+://github.\+com/}}\mbox{[}owner-\/name\mbox{]}/\mbox{[}repo-\/name\mbox{]}/issues . If the repository field points to a Git\+Hub Gist repo url, the associated http url is chosen.
\item If {\ttfamily bugs} field is an object, the resulting value only has email and url properties. If email and url properties are not strings, they are ignored. If no valid values for either email or url is found, bugs field will be removed.
\item If {\ttfamily homepage} field is not a string, it will be removed.
\item If the url in the {\ttfamily homepage} field does not specify a protocol, then http is assumed. For example, {\ttfamily myproject.\+org} will be changed to {\ttfamily \href{http://myproject.org}{\texttt{ http\+://myproject.\+org}}}.
\item If {\ttfamily homepage} field does not exist, but {\ttfamily repository} field points to a repository hosted on Git\+Hub, the value of the {\ttfamily homepage} field gets set to an url in the form of \href{https://github.com/}{\texttt{ https\+://github.\+com/}}\mbox{[}owner-\/name\mbox{]}/\mbox{[}repo-\/name\mbox{]}\#readme . If the repository field points to a Git\+Hub Gist repo url, the associated http url is chosen.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18346}{}\doxysubsection{Rules for name field}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18346}
If {\ttfamily name} field is given, the value of the name field must be a string. The string may not\+:


\begin{DoxyItemize}
\item start with a period.
\item contain the following characters\+: {\ttfamily /@\textbackslash{}s+\%}
\item contain any characters that would need to be encoded for use in urls.
\item resemble the word {\ttfamily node\+\_\+modules} or {\ttfamily favicon.\+ico} (case doesn\textquotesingle{}t matter).
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18347}{}\doxysubsection{Rules for version field}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18347}
If {\ttfamily version} field is given, the value of the version field must be a valid {\itshape semver} string, as determined by the {\ttfamily semver.\+valid} method. See \href{https://github.com/isaacs/node-semver}{\texttt{ documentation for the semver module}}.\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18348}{}\doxysubsection{Rules for license field}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18348}
The {\ttfamily license} field should be a valid {\itshape SPDX license expression} or one of the special values allowed by \href{https://npmjs.com/package/validate-npm-package-license}{\texttt{ validate-\/npm-\/package-\/license}}. See \href{https://docs.npmjs.com/files/package.json\#license}{\texttt{ documentation for the license field in package.\+json}}.\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18349}{}\doxysection{Credits}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18349}
This package contains code based on read-\/package-\/json written by Isaac Z. Schlueter. Used with permisson.\hypertarget{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18350}{}\doxysection{License}\label{md_sfcode_node_modules_normalize_package_data_README_autotoc_md18350}
normalize-\/package-\/data is released under the \href{http://opensource.org/licenses/MIT}{\texttt{ BSD 2-\/Clause License}}. ~\newline
 Copyright (c) 2013 Meryn Stol ~\newline
 