Skip to content

Commit

Permalink
FEATURE: Add support for Public Domain licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
dancrumb committed Jul 12, 2017
1 parent 8b74fa1 commit 0c55770
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
3 changes: 3 additions & 0 deletions lib/license.js
Expand Up @@ -12,6 +12,7 @@ var APACHE = /Apache License\b/;
var WTFPL = /WTFPL\b/;
// https://creativecommons.org/publicdomain/zero/1.0/
var CC0_1_0 = /The\s+person\s+who\s+associated\s+a\s+work\s+with\s+this\s+deed\s+has\s+dedicated\s+the\s+work\s+to\s+the\s+public\s+domain\s+by\s+waiving\s+all\s+of\s+his\s+or\s+her\s+rights\s+to\s+the\s+work\s+worldwide\s+under\s+copyright\s+law,\s+including\s+all\s+related\s+and\s+neighboring\s+rights,\s+to\s+the\s+extent\s+allowed\s+by\s+law.\s+You\s+can\s+copy,\s+modify,\s+distribute\s+and\s+perform\s+the\s+work,\s+even\s+for\s+commercial\s+purposes,\s+all\s+without\s+asking\s+permission./i; // jshint ignore:line
var PUBLIC_DOMAIN = /[Pp]ublic [Dd]omain/;


module.exports = function(str) {
Expand Down Expand Up @@ -46,6 +47,8 @@ module.exports = function(str) {
return 'Apache*';
} else if (CC0_1_0.test(str)) {
return 'CC0-1.0*';
} else if(PUBLIC_DOMAIN.test(str)) {
return 'Public Domain';
}
return null;
};
64 changes: 37 additions & 27 deletions tests/license.js
Expand Up @@ -66,36 +66,46 @@ describe('license parser', function() {
assert.equal(data, 'CC0-1.0*');
});

it('Public Domain check', function() {
var data = license('Public Domain');
assert.equal(data, 'Public Domain');
data = license('public domain');
assert.equal(data, 'Public Domain');
data = license('Public domain');
assert.equal(data, 'Public Domain');
});


it('Check for null', function() {
var data = license('this is empty, hi');
assert.equal(data, null);
});

describe('SPDX licenses', function() {

it('should parse a basic SPDX license', function() {
var data = [
'MIT',
'LGPL-2.0',
'Apache-2.0',
'BSD-2-Clause'
];
data.forEach(function (licenseType) {
assert.equal(license(licenseType), licenseType);
});
});

it('should parse more complicated license expressions', function() {
var data = [
'(GPL-2.0+ WITH Bison-exception-2.2)',
'LGPL-2.0 OR (ISC AND BSD-3-Clause+)',
'Apache-2.0 OR ISC OR MIT',
];
data.forEach(function (licenseType) {
assert.equal(license(licenseType), licenseType);
});

});

});
describe('SPDX licenses', function() {

it('should parse a basic SPDX license', function() {
var data = [
'MIT',
'LGPL-2.0',
'Apache-2.0',
'BSD-2-Clause'
];
data.forEach(function(licenseType) {
assert.equal(license(licenseType), licenseType);
});
});

it('should parse more complicated license expressions', function() {
var data = [
'(GPL-2.0+ WITH Bison-exception-2.2)',
'LGPL-2.0 OR (ISC AND BSD-3-Clause+)',
'Apache-2.0 OR ISC OR MIT',
];
data.forEach(function(licenseType) {
assert.equal(license(licenseType), licenseType);
});

});

});
});

0 comments on commit 0c55770

Please sign in to comment.