Skip to content

Commit

Permalink
add option for filtering out deprecated ids (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kemitchell authored and shinnn committed Apr 7, 2017
1 parent 350e66a commit cf8a97b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ function hasValidSpdxLicenseId(license) {
return !license.licenseId.endsWith('+');
}

function isNotDeprecated(license) {
return !license.isDeprecatedLicenseId;
}

function getLicenseId(license) {
return license.licenseId;
}

function extractSpdxLicenseIds(response) {
return response.body.licenses.filter(hasValidSpdxLicenseId).map(getLicenseId);
function extractSpdxLicenseIds(omitDeprecated) {
return function(response) {
var results = response.body.licenses.filter(hasValidSpdxLicenseId);
if (omitDeprecated) {
results = results.filter(isNotDeprecated);
}
return results.map(getLicenseId);
};
}

module.exports = function getSpdxLicenseIds(options) {
Expand All @@ -31,5 +41,5 @@ module.exports = function getSpdxLicenseIds(options) {
}, options, {
json: true
}))
.then(extractSpdxLicenseIds);
.then(extractSpdxLicenseIds(options && options.omitDeprecated));
};
10 changes: 9 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getSpdxLicenseIds = require('.');
const test = require('tape');

test('getSpdxLicenseIds()', t => {
t.plan(5);
t.plan(6);

t.strictEqual(getSpdxLicenseIds.name, 'getSpdxLicenseIds', 'should have a function name.');

Expand All @@ -26,6 +26,14 @@ test('getSpdxLicenseIds()', t => {
);
}).catch(t.fail);

getSpdxLicenseIds({omitDeprecated: true}).then(ids => {
t.strictEqual(
ids.includes('WXwindows'),
false,
'should be fulfilled with an array that doesn\'t include any deprecated identifiers.'
);
}).catch(t.fail);

getSpdxLicenseIds({json: false}).then(t.fail, err => {
t.strictEqual(
err.message,
Expand Down

0 comments on commit cf8a97b

Please sign in to comment.