Skip to content

Instantly share code, notes, and snippets.

@matthew-gerstman
Last active July 20, 2019 18:22
Show Gist options
  • Save matthew-gerstman/f325685c860c4ef8da1493dc9f6fc731 to your computer and use it in GitHub Desktop.
Save matthew-gerstman/f325685c860c4ef8da1493dc9f6fc731 to your computer and use it in GitHub Desktop.
function handleAsManyLicenseCases(data, licenseID) {
const returnableLicense = {
allLicenses: [],
licenseStatement: licenseID,
spdx: {
osi: false,
fsf: false,
fsfAndOsi: false,
deprecated: false,
},
};
if (typeof data.license === 'string') {
const spdxCheck = checkSpdx(data.license);
returnableLicense.spdx = spdxCheck; // just directly assign the returned value to the module
returnableLicense.allLicenses.push(data.license);
} else if (typeof data.right.license === 'string') {
// we're going to need both data for left and right for this one
const spdxCheckLeft = checkSpdx(data.left.license);
const spdxCheckRight = checkSpdx(data.right.license);
// now we need to assign
returnableLicense.spdx.osi =
spdxCheckLeft.osi === true && spdxCheckRight.osi === true;
returnableLicense.spdx.fsf =
spdxCheckLeft.fsf === true && spdxCheckRight.fsf === true;
returnableLicense.spdx.fsfAndOsi =
spdxCheckLeft.fsfAndOsi === true && spdxCheckRight.fsfAndOsi === true;
returnableLicense.spdx.deprecated =
spdxCheckLeft.deprecated === true && spdxCheckRight.deprecated === true;
returnableLicense.allLicenses.push(data.left.license, data.right.license);
} else if (typeof data.right.left.license === 'string') {
const spdxCheckLeft = checkSpdx(data.left.license);
const spdxCheckRightLeft = checkSpdx(data.right.license);
const spdxCheckRightRight = checkSpdx(data.right.license);
returnableLicense.spdx.osi =
spdxCheckLeft.osi === true &&
spdxCheckRightLeft.osi === true &&
spdxCheckRightRight.osi === true;
returnableLicense.spdx.fsf =
spdxCheckLeft.fsf === true &&
spdxCheckRightLeft.fsf === true &&
spdxCheckRightRight.osi === true;
returnableLicense.spdx.fsfAndOsi =
spdxCheckLeft.fsfAndOsi === true &&
spdxCheckRightLeft.fsfAndOsi === true &&
spdxCheckRightRight.osi === true;
returnableLicense.spdx.deprecated =
spdxCheckLeft.deprecated === true &&
spdxCheckRightLeft.deprecated === true &&
spdxCheckRightRight.osi === true;
returnableLicense.allLicenses.push(
data.left.license,
data.right.left.license,
);
}
return returnableLicense;
}
function checkSpdx(licenseToCheck) {
const spdx = {
osi: OSI.includes(licenseToCheck),
fsf: FSF.includes(licenseToCheck),
fsfAndOsi: FSFandOSI.includes(licenseToCheck),
deprecated: deprecated.includes(licenseToCheck),
};
return spdx;
}
console.log(buildDefinitionsAndValidation('MIT'));
console.log(buildDefinitionsAndValidation('MIT OR CC0-1.0'));
console.log(buildDefinitionsAndValidation('MIT OR (CC0-1.0 AND ISC)'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment