normalize-pkg
Advanced tools
Comparing version 0.1.5 to 0.1.6
70
index.js
@@ -1,5 +0,15 @@ | ||
const unique = require('unique-words'); | ||
const common = require('common-words'); | ||
const utils = require('./lib/utils'); | ||
const log = require('verbalize'); | ||
/*! | ||
* normalize-pkg <https://github.com/jonschlinkert/normalize-pkg> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert, contributors. | ||
* Licensed under the MIT license. | ||
*/ | ||
'use strict'; | ||
var isObject = require('is-plain-object'); | ||
var extend = require('mixin-deep'); | ||
var typeOf = require('kind-of'); | ||
var utils = require('./lib/utils'); | ||
var log = require('verbalize'); | ||
log.runner = 'normalize-pkg'; | ||
@@ -19,10 +29,13 @@ | ||
normalize.author = function (pkg, options) { | ||
options = options || {}; | ||
var name = '', url = ''; | ||
options = extend({}, options); | ||
pkg = extend({}, pkg); | ||
if (typeof pkg.author === 'object') { | ||
var name = ''; | ||
var url = ''; | ||
if (isObject(pkg.author)) { | ||
utils.msg.isCorrect('author'); | ||
return pkg; | ||
} else if (typeof pkg.author === 'undefined') { | ||
} else if (pkg.author == null) { | ||
if (pkg.authors && pkg.authors.length === 1) { | ||
@@ -40,3 +53,3 @@ utils.msg.fixingProperty('author'); | ||
} else if (typeof pkg.author === 'string') { | ||
} else if (typeOf(pkg.author)) { | ||
utils.msg.isMissing('author'); | ||
@@ -70,7 +83,7 @@ utils.msg.fixingProperty('author'); | ||
if (typeof pkg.repository === 'object') { | ||
if (isObject(pkg.repository)) { | ||
utils.msg.isCorrect('repository'); | ||
return pkg; | ||
} else if (typeof pkg.repository === 'undefined') { | ||
} else if (typeOf(pkg.repository) === 'undefined') { | ||
if (pkg.repositories && pkg.repositories.length === 1) { | ||
@@ -89,3 +102,3 @@ utils.msg.isMissing('repository'); | ||
} else if (typeof pkg.repository === 'string') { | ||
} else if (typeOf(pkg.repository) === 'string') { | ||
utils.msg.fixingProperty('repository'); | ||
@@ -123,11 +136,11 @@ url = pkg.repository; | ||
if (typeof pkg.bugs === 'object') { | ||
if (isObject(pkg.bugs)) { | ||
utils.msg.isCorrect('bugs'); | ||
return pkg; | ||
} else if (typeof pkg.bugs === 'undefined') { | ||
} else if (typeOf(pkg.bugs) === 'undefined') { | ||
utils.msg.isMissing('bugs'); | ||
utils.msg.addingProperty('bugs'); | ||
} else if (typeof pkg.bugs === 'string') { | ||
} else if (typeOf(pkg.bugs) === 'string') { | ||
utils.msg.fixingProperty('bugs'); | ||
@@ -164,3 +177,3 @@ url = pkg.bugs; | ||
} else if (typeof pkg.license === 'object') { | ||
} else if (isObject(pkg.license)) { | ||
utils.msg.fixingProperty('license'); | ||
@@ -171,3 +184,3 @@ type = pkg.license.type; | ||
} else if (typeof pkg.license === 'string') { | ||
} else if (typeOf(pkg.license) === 'string') { | ||
utils.msg.fixingProperty('license'); | ||
@@ -184,3 +197,3 @@ | ||
} else if (typeof pkg.license === 'undefined') { | ||
} else if (typeOf(pkg.license) === 'undefined') { | ||
utils.msg.isMissing('license'); | ||
@@ -211,25 +224,6 @@ utils.msg.addingProperty('license'); | ||
normalize.keywords = function (pkg, options) { | ||
options = options || {}; | ||
var keywords = pkg.keywords || []; | ||
normalize.keywords = require('normalize-keywords'); | ||
if (typeof pkg.keywords === 'undefined') { | ||
utils.msg.isMissing('keywords'); | ||
utils.msg.addingProperty('keywords'); | ||
} else if (pkg.keywords && Array.isArray(pkg.keywords)) { | ||
utils.msg.fixingProperty('keywords'); | ||
keywords = unique(pkg.keywords); | ||
} else { | ||
// If none of the above, something is amiss | ||
return utils.msg.isMalformed('keywords'); | ||
} | ||
pkg.keywords = utils.difference(keywords, common).sort(); | ||
return pkg; | ||
}; | ||
/** | ||
@@ -236,0 +230,0 @@ * All |
{ | ||
"name": "normalize-pkg", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Normalize values in package.json to improve compatibility, programmatic readability and usefulness with third party libs.", | ||
@@ -31,2 +31,5 @@ "author": { | ||
], | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
}, | ||
"main": "index.js", | ||
@@ -41,12 +44,15 @@ "engines": { | ||
"dependencies": { | ||
"common-words": "~0.1.3", | ||
"cwd": "~0.3.1", | ||
"is-plain-object": "^0.1.0", | ||
"kind-of": "^0.1.0", | ||
"minimist": "0.0.8", | ||
"unique-words": "0.0.2", | ||
"mixin-deep": "^0.1.0", | ||
"normalize-keywords": "^0.1.0", | ||
"verbalize": "~0.1.2" | ||
}, | ||
"devDependencies": { | ||
"verb": "~0.1.20", | ||
"chai": "~1.9.1" | ||
"mocha": "*", | ||
"should": "^4.0.4", | ||
"verb": "^0.2.15" | ||
} | ||
} |
@@ -1,23 +0,17 @@ | ||
# normalize-pkg [](http://badge.fury.io/js/normalize-pkg) | ||
# normalize-pkg [](http://badge.fury.io/js/normalize-pkg) | ||
> Normalize values in package.json to improve compatibility, programmatic readability and usefulness with third party libs. | ||
<!-- toc --> | ||
* [Quickstart](#quickstart) | ||
* [Usage](#usage) | ||
* [args](#args) | ||
* [Normalized values](#normalized-values) | ||
* [license](#license) | ||
* [bugs](#bugs) | ||
* [author](#author) | ||
* [repository](#repository) | ||
* [Authors](#authors) | ||
* [License](#license) | ||
## Install | ||
#### Install with [npm](npmjs.org): | ||
<!-- toc stop --> | ||
## Quickstart | ||
Install with [npm](npmjs.org): | ||
```bash | ||
npm i normalize-pkg --save-dev | ||
``` | ||
## Run tests | ||
```bash | ||
npm i -g normalize-pkg | ||
npm test | ||
``` | ||
@@ -27,2 +21,10 @@ | ||
### API | ||
```js | ||
var normalize = require('normalize-pkg'); | ||
``` | ||
### CLI | ||
Run `normalize` in the command line to normalize the following properties in `package.json`: | ||
@@ -35,3 +37,2 @@ | ||
### args | ||
@@ -49,7 +50,9 @@ If you want to specify the source `package.json` to normalize, or the destination to write to, you can use this format: | ||
## Normalized values | ||
## Normalized properties | ||
Currently, only the following values are normalized. If any of the values is missing, a polite warning will be logged, but nothing will be modified. | ||
### license | ||
## license | ||
@@ -80,3 +83,3 @@ If `license` is formatted as a string: | ||
### bugs | ||
## bugs | ||
@@ -101,3 +104,3 @@ If `bugs` is formatted as a string: | ||
### author | ||
## author | ||
@@ -123,3 +126,3 @@ If `author` is formatted as a string: | ||
### repository | ||
## repository | ||
@@ -147,11 +150,11 @@ If `repository` is formatted as a string: | ||
## Authors | ||
## Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert, contributors. | ||
Copyright (c) 2014 Jon Schlinkert, contributors. | ||
Released under the MIT license | ||
@@ -161,2 +164,2 @@ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 26, 2014._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 26, 2014._ |
@@ -1,3 +0,12 @@ | ||
var expect = require('chai').expect; | ||
/*! | ||
* normalize-pkg <https://github.com/jonschlinkert/normalize-pkg> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert, contributors. | ||
* Licensed under the MIT license. | ||
*/ | ||
'use strict'; | ||
var should = require('should'); | ||
// Local libs | ||
@@ -23,3 +32,3 @@ var pkg = require('../'); | ||
}; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
@@ -44,3 +53,3 @@ }); | ||
}; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
@@ -58,3 +67,3 @@ }); | ||
}; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
@@ -81,3 +90,3 @@ }); | ||
}; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
@@ -103,3 +112,3 @@ }); | ||
}; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
@@ -118,3 +127,3 @@ }); | ||
}; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
@@ -138,3 +147,3 @@ }); | ||
}; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
@@ -153,3 +162,3 @@ }); | ||
}; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
@@ -175,3 +184,3 @@ }); | ||
}; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
@@ -183,3 +192,3 @@ }); | ||
var actual = pkg.license({license: 'MIT'}, {license: true}); | ||
expect(actual).to.eql({license: 'MIT'}); | ||
actual.should.eql({license: 'MIT'}); | ||
}); | ||
@@ -199,3 +208,3 @@ }); | ||
var actual = pkg.license(fixture); | ||
expect(actual).to.eql(fixture); | ||
actual.should.eql(fixture); | ||
}); | ||
@@ -220,3 +229,3 @@ }); | ||
var expected = fixture; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
@@ -234,5 +243,5 @@ }); | ||
}; | ||
expect(actual).to.eql(expected); | ||
actual.should.eql(expected); | ||
}); | ||
}); | ||
}); |
506
157
22623
7
3
15
+ Addedis-plain-object@^0.1.0
+ Addedkind-of@^0.1.0
+ Addedmixin-deep@^0.1.0
+ Addednormalize-keywords@^0.1.0
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedis-plain-object@0.1.0(transitive)
+ Addedkind-of@0.1.2(transitive)
+ Addedmixin-deep@0.1.0(transitive)
+ Addednormalize-keywords@0.1.6(transitive)
- Removedcommon-words@~0.1.3
- Removedunique-words@0.0.2