normalize-pkg 
Normalize values in package.json to improve compatibility, programmatic readability and usefulness with third party libs.
Install
Install with npm
$ npm i normalize-pkg --save
Install with bower
$ bower install normalize-pkg --save
Usage
var normalize = require('normalize-pkg');
var pkg = require('./package');
normalize(pkg);
Schema
normalize-pkg takes a schema, where each key on the schema represents a property name on package.json. A default schema is used but it can easily be overridden.
Keys
Schema property keys represent the properties you want on your package.json. For example, here is are a couple of properties from the default schema:
{
name: {
type: 'string',
value: function (key, val, config) {
return val || utils.projectName(process.cwd());
}
},
description: {
type: 'string',
default: ''
},
version: {
type: 'string',
default: '0.1.0'
}
}
Schema properties
The foll
type
: native javascript type. If the property is defined and it's type does not match this value an error is thrownvalue
: This can be any type of value. If it's a function, it will be called and passed the key
and value
currently defined for the property, and the entire config
as the last argument. If it's any other value, that value will be used and will overwrite any existing value. If you only want to use a value if it's undefined, use default
instead or a value
function if conditional logic is required.default
: Set the default value to use when the property is undefined. Only necessary if value
is not defined.
Options
When an options object is passed as the second argument it will be used to extend or override properties on the existing schema.
normalize(pkg, {
name: {
value: 'foo'
},
version: {
value: function(key, val) {
return value;
}
}
});
Related projects
update: Update the year in all files in a project using glob patterns. | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb-cli on November 06, 2015.