Skip to content

Commit

Permalink
Fixes #49: Default to unknown if licenses null and added ISC support
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Oct 20, 2015
1 parent ba946dd commit 981eeda
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ exports.init = function(options, callback) {
inputError = null;

Object.keys(data).sort().forEach(function(item) {
if (!data[item].licenses) {
/*istanbul ignore else*/
if (colorize) {
data[item].licenses = chalk.bold.red(UNKNOWN);
} else {
data[item].licenses = UNKNOWN;
}
}
if (options.unknown) {
if (data[item].licenses && data[item].licenses !== UNKNOWN) {
if (data[item].licenses.indexOf('*') > -1) {
Expand Down
6 changes: 6 additions & 0 deletions lib/license.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
var MIT_LICENSE = /ermission is hereby granted, free of charge, to any/;
var BSD_LICENSE = /edistribution and use in source and binary forms, with or withou/;
var WTFPL_LICENSE = /DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE/;
var ISC_LICENSE = /The ISC License/;
var MIT = /MIT\b/;
var BSD = /BSD\b/;
var ISC = /ISC\b/;
var APACHE = /Apache License\b/;
var WTFPL = /WTFPL\b/;

Expand All @@ -13,12 +15,16 @@ module.exports = function(str) {
}
if (typeof str === 'undefined' || !str) {
return 'Undefined';
} else if (ISC_LICENSE.test(str)) {
return 'ISC*';
} else if (MIT_LICENSE.test(str)) {
return 'MIT*';
} else if (BSD_LICENSE.test(str)) {
return 'BSD*';
} else if (WTFPL_LICENSE.test(str)) {
return 'WTFPL*';
} else if (ISC.test(str)) {
return 'ISC*';
} else if (MIT.test(str)) {
return 'MIT*';
} else if (BSD.test(str)) {
Expand Down
16 changes: 16 additions & 0 deletions tests/license.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ var tests = {
assert.equal(data, 'WTFPL*');
}
},
'ISC check': {
topic: function() {
return license('asdfasdf\nThe ISC License\nasdfasdf');
},
'should return ISC': function(data) {
assert.equal(data, 'ISC*');
}
},
'ISC word check': {
topic: function() {
return license('asdf\nasdf\nISC\nasdf\n');
},
'should return ISC': function(data) {
assert.equal(data, 'ISC*');
}
},
'Check for null': {
topic: function() {
return license('this is empty, hi');
Expand Down

0 comments on commit 981eeda

Please sign in to comment.