"Fossies" - the Fresh Open Source Software Archive

Member "node-v12.18.4-win-x64/node_modules/npm/node_modules/normalize-package-data/README.md" (14 Feb 2020, 7328 Bytes) of package /windows/www/node-v12.18.4-win-x64.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.

normalize-package-data Build Status

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 read-package-json to normalize the data it reads from a package.json file. In turn, read-package-json is used by npm and various npm-related tools.


npm install normalize-package-data


Basic usage is really simple. You call the function that normalize-package-data exports. Let’s call it normalizeData.

normalizeData = require('normalize-package-data')
packageData = require("./package.json")
// packageData is now normalized

Strict mode

You may activate strict validation by passing true as the second argument.

normalizeData = require('normalize-package-data')
packageData = require("./package.json")
normalizeData(packageData, true)
// packageData is now normalized

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.


Optionally, you may pass a “warning” function. It gets called whenever the normalizeData function encounters something that doesn’t look right. It indicates less than perfect input data.

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

You may combine strict validation with warnings by passing true as the second argument, and warnFn as third.

When private field is set to true, warnings will be suppressed.

Potential exceptions

If the supplied data has an invalid name or version vield, normalizeData will throw an error. Depending on where you call normalizeData, you may want to catch these errors so can pass them to a callback.

What normalization (currently) entails

Rules for name field

If name field is given, the value of the name field must be a string. The string may not:

Rules for version field

If version field is given, the value of the version field must be a valid semver string, as determined by the semver.valid method. See documentation for the semver module.

Rules for license field

The license field should be a valid SPDX license expression or one of the special values allowed by validate-npm-package-license. See documentation for the license field in package.json.


This package contains code based on read-package-json written by Isaac Z. Schlueter. Used with permisson.


normalize-package-data is released under the BSD 2-Clause License.
Copyright (c) 2013 Meryn Stol