New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

normalize-pkg

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalize-pkg - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

65

index.js

@@ -1,2 +0,1 @@

const fs = require('fs');
const unique = require('unique-words');

@@ -18,3 +17,4 @@ const utils = require('./lib/utils');

normalize.author = function (pkg) {
normalize.author = function (pkg, options) {
options = options || {};
var name = '', url = '';

@@ -64,3 +64,4 @@

normalize.repo = function (pkg) {
normalize.repo = function (pkg, options) {
options = options || {};
var type = '', url = '';

@@ -115,3 +116,4 @@

normalize.bugs = function (pkg) {
normalize.bugs = function (pkg, options) {
options = options || {};
var url = '';

@@ -150,38 +152,42 @@

*/
normalize.license = function (pkg) {
normalize.license = function (pkg, options) {
options = options || {};
var type = '', url = '';
if (typeof pkg.license === 'object') {
utils.msg.isCorrect('license');
// Already formatted as an array, return.
if (pkg.licenses && pkg.licenses.length > 0) {
utils.msg.isCorrect('licenses');
return pkg;
} else if (typeof pkg.license === 'undefined') {
if (pkg.licenses && pkg.licenses.length === 1) {
utils.msg.fixingProperty('license');
} else if (typeof pkg.license === 'object') {
utils.msg.fixingProperty('license');
type = pkg.license.type;
url = pkg.license.url;
delete pkg.license;
type = pkg.licenses[0].type;
url = pkg.licenses[0].url;
delete pkg.licenses;
} else if (typeof pkg.license === 'string') {
utils.msg.fixingProperty('license');
} else {
utils.msg.isMissing('license');
utils.msg.addingProperty('license');
if (options.license && options.license === true) {
return pkg;
}
} else if (typeof pkg.license === 'string') {
utils.msg.fixingProperty('license');
var inferred = utils.inferLicenseURL(pkg.license);
type = inferred.type;
url = inferred.url;
delete pkg.license;
} else if (typeof pkg.license === 'undefined') {
utils.msg.isMissing('license');
utils.msg.addingProperty('license');
} else {
// If none of the above, something is amiss
return utils.msg.isMalformed('license');
utils.msg.isMalformed('license');
}
pkg.license = {
pkg.licenses = [{
type: type,
url: url
};
}];

@@ -199,3 +205,4 @@ return pkg;

normalize.keywords = function (pkg) {
normalize.keywords = function (pkg, options) {
options = options || {};
var keywords = pkg.keywords || [];

@@ -229,9 +236,9 @@

normalize.all = function(pkg) {
pkg = normalize.author(pkg);
pkg = normalize.repo(pkg);
pkg = normalize.bugs(pkg);
pkg = normalize.license(pkg);
pkg = normalize.keywords(pkg);
normalize.all = function(pkg, options) {
pkg = normalize.author(pkg, options);
pkg = normalize.repo(pkg, options);
pkg = normalize.bugs(pkg, options);
pkg = normalize.license(pkg, options);
pkg = normalize.keywords(pkg, options);
return pkg;
};

@@ -29,10 +29,17 @@ const log = require('verbalize');

exports.inferLicenseURL = function(str) {
var type = str, url = '';
var type = str,
url;
if (contains(str, '://')) {
url = str;
}
if (contains(str, 'MIT')) {
url = 'http://opensource.org/licenses/MIT';
type = 'MIT';
url = url || 'http://opensource.org/licenses/MIT';
}
if (contains(str, 'Apache')) {
url = 'http://www.apache.org/licenses/LICENSE-2.0.html';
type = 'Apache-2.0';
url = url || 'http://www.apache.org/licenses/LICENSE-2.0.html';
}

@@ -42,6 +49,8 @@

if (contains(str, '2')) {
url = 'http://www.gnu.org/licenses/gpl-2.0.txt';
type = 'GPL-2.0';
url = url || 'http://www.gnu.org/licenses/gpl-2.0.txt';
}
if (contains(str, '3')) {
url = 'http://www.gnu.org/licenses/gpl-3.0.txt';
type = 'GPL-3.0';
url = url || 'http://www.gnu.org/licenses/gpl-3.0.txt';
}

@@ -48,0 +57,0 @@ }

{
"name": "normalize-pkg",
"version": "0.1.1",
"version": "0.1.2",
"description": "Normalize values in package.json to improve compatibility, programmatic readability and usefulness with third party libs.",

@@ -9,9 +9,16 @@ "author": {

},
"homepage": "https://github.com/jonschlinkert/normalize-pkg/",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/jonschlinkert/normalize-pkg/blob/master/LICENSE-MIT"
}
],
"repository": {
"type": "git",
"url": "git://github.com/jonschlinkert/normalize-pkg.git"
},
"bugs": {
"url": "https://github.com/jonschlinkert/normalize-pkg/issues"
},
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/normalize-pkg/blob/master/LICENSE-MIT"
},
"keywords": [

@@ -42,7 +49,3 @@ "fix",

"chai": "~1.9.1"
},
"repository": {
"type": "",
"url": ""
}
}
}

@@ -11,6 +11,6 @@ var expect = require('chai').expect;

describe('normalizeAuthor', function () {
describe('author', function () {
describe('when the `author` property is a string:', function () {
it('should return an object, using the value from `author` to populate `author.name`', function () {
var actual = pkg.normalizeAuthor({
var actual = pkg.author({
author: 'Jon Schlinkert'

@@ -30,3 +30,3 @@ });

it('should convert the `authors` array into an `author` object', function () {
var actual = pkg.normalizeAuthor({
var actual = pkg.author({
authors: [

@@ -51,3 +51,3 @@ {

it('should return an `author` object with empty values', function () {
var actual = pkg.normalizeAuthor({});
var actual = pkg.author({});
var expected = {

@@ -69,6 +69,6 @@ author: {

describe('normalizeRepo', function () {
describe('repo', function () {
describe('when the `repository` property is a string:', function () {
it('should return an object, using the value from `repository` to populate `repository.type`', function () {
var actual = pkg.normalizeRepo({
var actual = pkg.repo({
repository: 'https://github.com/assemble/verb.git'

@@ -88,3 +88,3 @@ });

it('should convert the `repositories` array into a `repository` object', function () {
var actual = pkg.normalizeRepo({
var actual = pkg.repo({
repositories: [

@@ -111,3 +111,3 @@ {

it('should return a `repository` object with empty values', function () {
var actual = pkg.normalizeRepo({});
var actual = pkg.repo({});
var expected = {

@@ -129,6 +129,6 @@ repository: {

describe('normalizeBugs', function () {
describe('bugs', function () {
describe('when no `bugs` property exists:', function () {
it('should return a `bugs` object with empty values', function () {
var actual = pkg.normalizeBugs({});
var actual = pkg.bugs({});
var expected = {

@@ -145,3 +145,3 @@ bugs: {

it('should return an object, using the value from `bugs` to populate `bugs.url`', function () {
var actual = pkg.normalizeBugs({
var actual = pkg.bugs({
bugs: 'https://github.com/assemble/verb.git'

@@ -164,14 +164,12 @@ });

describe('normalizeLicense', function () {
describe('license', function () {
describe('when the `license` property is a string:', function () {
it('should return an object, using the value from `license` to populate `license.type`', function () {
var actual = pkg.normalizeLicense({
license: 'MIT'
});
it('should return an array, using the value from `license` to populate `license.type`, and inferring the URL from the type.', function () {
var actual = pkg.license({license: 'MIT'}, {license: false});
var expected = {
license: {
licenses: [{
type: 'MIT',
url: 'http://opensource.org/licenses/MIT'
}
}]
};

@@ -182,5 +180,12 @@ expect(actual).to.eql(expected);

describe('when the `license` property is a string, and `license: true` is defined in the options:', function () {
it('should return the license property as a string.', function () {
var actual = pkg.license({license: 'MIT'}, {license: true});
expect(actual).to.eql({license: 'MIT'});
});
});
describe('when no `license` property exists, but a `licenses` property exists with only one license:', function () {
it('should convert the `licenses` array into a `license` object', function () {
var actual = pkg.normalizeLicense({
var fixture = {
licenses: [

@@ -192,11 +197,5 @@ {

]
});
var expected = {
license: {
type: 'Apache',
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
}
};
expect(actual).to.eql(expected);
var actual = pkg.license(fixture);
expect(actual).to.eql(fixture);
});

@@ -219,3 +218,3 @@ });

};
var actual = pkg.normalizeLicense(fixture);
var actual = pkg.license(fixture);
var expected = fixture;

@@ -228,8 +227,8 @@ expect(actual).to.eql(expected);

it('should return a `license` object with empty values', function () {
var actual = pkg.normalizeLicense({});
var actual = pkg.license({});
var expected = {
license: {
licenses: [{
type: '',
url: ''
}
}]
};

@@ -236,0 +235,0 @@ expect(actual).to.eql(expected);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc