normalize-pkg

Normalize values in package.json.
Install
Install with npm:
$ npm install normalize-pkg --save
Install with bower
$ bower install normalize-pkg --save
Usage
var config = require('./')();
var pkg = config.normalize(require('./package'));
Features
Normalizes most package.json fields, and:
- converts
repository
objects to a string - stringifies
author
object - stringifies each "person" object in
maintainers
, contributors
and collaborators
- converts
licenses
arrays and objects to a license
string - removes files that don't exist from
bin
, main
and the files
array - adds
cli.js
to bin
if it exists - creates
keywords
array from name
if not defined
See the schema, normalizers, and unit tests for more examples.
Normalizing fields
Fields are normalized using a schema (powered by map-schema).
Defaults
Defaults are based on npm recommendations. When a required or recommended field is missing, normalize-pkg
attempts to create the field if valid data can be found in the repository.
Example
The following:
var config = require('./')();
var pkg = config.normalize({});
console.log(pkg);
Results
Since an empty object was passed, normalize-pkg
was smart enough to fill in missing fields looking for info in the project. In this case, specifically from parsing .git
config and using any defaults defined on the schema.
{ name: 'normalize-pkg',
version: '0.1.0',
homepage: 'https://github.com/jonschlinkert/normalize-pkg',
repository: 'jonschlinkert/normalize-pkg',
license: 'MIT',
files: [ 'index.js' ],
main: 'index.js',
engines: { node: '>= 0.10.0' },
keywords: [ 'normalize', 'pkg' ] }
Options
options.pick
Type
: array
Default: undefined
Filter the resulting object to contain only the specified keys.
options.omit
Type
: array
Default: undefined
Remove the specified keys from the resulting object.
Customize
Pass a fields
object on the options to customize any fields on the schema (also define extend: true
if you want the field to extend a field that is already defined):
var pkg = config.normalize(require('./package'), {
extend: true,
fields: {
name: {
normalize: function() {
return 'bar'
}
}
}
});
console.log(pkg.name);
Related projects
You might also be interested in these projects:
update: Easily keep anything in your project up-to-date by installing the updaters you want to use… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
This file was generated by verb, v, on March 27, 2016.