normalize-package-data
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -20,3 +20,3 @@ module.exports = normalize | ||
if(!strict) strict = false | ||
if(!warn) warn = function(msg) { /* noop */ } | ||
if(!warn || data.private) warn = function(msg) { /* noop */ } | ||
@@ -23,0 +23,0 @@ if (data.scripts && |
{ | ||
"name": "normalize-package-data", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"author": "Meryn Stol <merynstol@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Normalizes data that can be found in package.json files.", |
@@ -24,4 +24,6 @@ # normalize-package-data [![Build Status](https://travis-ci.org/meryn/normalize-package-data.png?branch=master)](https://travis-ci.org/meryn/normalize-package-data) | ||
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. | ||
#### Strict mode | ||
You may activate strict validation by passing true as the second argument. | ||
```javascript | ||
@@ -31,2 +33,16 @@ normalizeData = require('normalize-package-data') | ||
warnFn = function(msg) { console.error(msg) } | ||
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. | ||
#### Warnings | ||
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. | ||
```javascript | ||
normalizeData = require('normalize-package-data') | ||
packageData = fs.readfileSync("package.json") | ||
warnFn = function(msg) { console.error(msg) } | ||
normalizeData(packageData, warnFn) | ||
@@ -36,4 +52,6 @@ // packageData is now normalized. Any number of warnings may have been logged. | ||
If you don't provide a warning function, `normalizeData` functions silently. | ||
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`, no warnings will be generated. | ||
### Potential exceptions | ||
@@ -45,3 +63,3 @@ | ||
* The value of `name` field gets trimmed. | ||
* The value of `name` field gets trimmed (unless in strict mode). | ||
* The value of the `version` field gets cleaned by `semver.clean`. See [documentation for the semver module](https://github.com/isaacs/node-semver). | ||
@@ -48,0 +66,0 @@ * If `name` and/or `version` fields are missing, they are set to empty strings. |
@@ -97,3 +97,13 @@ var test = require('tap').test | ||
warnings.length = 0 | ||
expect = [] | ||
normalize({private: true | ||
,name:"name" | ||
,version:"1.2.5" | ||
,scripts:{server:"start",tests:"test"}}, warn) | ||
t.same(warnings, expect) | ||
t.end(); | ||
}) |
44084
1208
99