spdx-satisfies
Advanced tools
Comparing version 0.1.3 to 4.0.0
154
index.js
@@ -0,58 +1,112 @@ | ||
var compare = require('spdx-compare') | ||
var parse = require('spdx-expression-parse') | ||
var compare = require('spdx-compare') | ||
var ranges = require('spdx-ranges') | ||
module.exports = (function() { | ||
var rangesAreCompatible = function(first, second) { | ||
return ( | ||
first.license === second.license || | ||
ranges.some(function(range) { | ||
return ( | ||
range.indexOf(first.license) > -1 && | ||
range.indexOf(second.license) ) }) ) } | ||
var rangesAreCompatible = function (first, second) { | ||
return ( | ||
first.license === second.license || | ||
ranges.some(function (range) { | ||
return ( | ||
licenseInRange(first.license, range) && | ||
licenseInRange(second.license, range) | ||
) | ||
}) | ||
) | ||
} | ||
var identifierInRange = function(identifier, range) { | ||
function licenseInRange (license, range) { | ||
return ( | ||
range.indexOf(license) !== -1 || | ||
range.some(function (element) { | ||
return ( | ||
Array.isArray(element) && | ||
element.indexOf(license) !== -1 | ||
) | ||
}) | ||
) | ||
} | ||
var identifierInRange = function (identifier, range) { | ||
return ( | ||
identifier.license === range.license || | ||
compare.gt(identifier.license, range.license) || | ||
compare.eq(identifier.license, range.license) | ||
) | ||
} | ||
var licensesAreCompatible = function (first, second) { | ||
if (first.exception !== second.exception) { | ||
return false | ||
} else if (second.hasOwnProperty('license')) { | ||
if (second.hasOwnProperty('plus')) { | ||
if (first.hasOwnProperty('plus')) { | ||
// first+, second+ | ||
return rangesAreCompatible(first, second) | ||
} else { | ||
// first, second+ | ||
return identifierInRange(first, second) | ||
} | ||
} else { | ||
if (first.hasOwnProperty('plus')) { | ||
// first+, second | ||
return identifierInRange(second, first) | ||
} else { | ||
// first, second | ||
return first.license === second.license | ||
} | ||
} | ||
} | ||
} | ||
var recurseLeftAndRight = function (first, second) { | ||
var firstConjunction = first.conjunction | ||
if (firstConjunction === 'and') { | ||
return ( | ||
identifier.license === range.license || | ||
compare.gt(identifier.license, range.license) ) } | ||
recurse(first.left, second) && | ||
recurse(first.right, second) | ||
) | ||
} else if (firstConjunction === 'or') { | ||
return ( | ||
recurse(first.left, second) || | ||
recurse(first.right, second) | ||
) | ||
} | ||
} | ||
var licensesAreCompatible = function(first, second) { | ||
if (first.exception !== second.exception) { | ||
return false } | ||
else if (second.hasOwnProperty('license')) { | ||
if (second.hasOwnProperty('plus')) { | ||
if (first.hasOwnProperty('plus')) { | ||
// first+, second+ | ||
return rangesAreCompatible(first, second) } | ||
else { | ||
// first, second+ | ||
return identifierInRange(first, second) } } | ||
else { | ||
if (first.hasOwnProperty('plus')) { | ||
// first+, second | ||
return identifierInRange(second, first) } | ||
else { | ||
// first, second | ||
return first.license === second.license } } } } | ||
var recurse = function (first, second) { | ||
if (first.hasOwnProperty('conjunction')) { | ||
return recurseLeftAndRight(first, second) | ||
} else if (second.hasOwnProperty('conjunction')) { | ||
return recurseLeftAndRight(second, first) | ||
} else { | ||
return licensesAreCompatible(first, second) | ||
} | ||
} | ||
var recurseLeftAndRight = function(first, second) { | ||
var firstConjunction = first.conjunction | ||
if (firstConjunction === 'and') { | ||
return ( | ||
recurse(first.left, second) && | ||
recurse(first.right, second) ) } | ||
else if (firstConjunction === 'or') { | ||
return ( | ||
recurse(first.left, second) || | ||
recurse(first.right, second) ) } } | ||
function normalizeGPLIdentifiers (argument) { | ||
var license = argument.license | ||
if (license) { | ||
if (endsWith(license, '-or-later')) { | ||
argument.license = license.replace('-or-later', '') | ||
argument.plus = true | ||
} else if (endsWith(license, '-only')) { | ||
argument.license = license.replace('-or-later', '') | ||
delete argument.plus | ||
} | ||
} else { | ||
argument.left = normalizeGPLIdentifiers(argument.left) | ||
argument.right = normalizeGPLIdentifiers(argument.right) | ||
} | ||
return argument | ||
} | ||
var recurse = function(first, second) { | ||
if (first.hasOwnProperty('conjunction')) { | ||
return recurseLeftAndRight(first, second) } | ||
else if (second.hasOwnProperty('conjunction')) { | ||
return recurseLeftAndRight(second, first) } | ||
else { | ||
return licensesAreCompatible(first, second) } } | ||
function endsWith (string, substring) { | ||
return string.indexOf(substring) === string.length - 1 | ||
} | ||
return function(first, second) { | ||
return recurse(parse(first), parse(second)) } })() | ||
module.exports = function (first, second) { | ||
return recurse( | ||
normalizeGPLIdentifiers(parse(first)), | ||
normalizeGPLIdentifiers(parse(second)) | ||
) | ||
} |
{ | ||
"name": "spdx-satisfies", | ||
"description": "test whether SPDX expressions satisfy licensing criteria", | ||
"version": "0.1.3", | ||
"version": "4.0.0", | ||
"author": "Kyle E. Mitchell <kyle@kemitchell.com> (https://kemitchell.com)", | ||
"dependencies": { | ||
"spdx-compare": "^0.1.2", | ||
"spdx-expression-parse": "^1.0.0" | ||
"spdx-compare": "^1.0.0", | ||
"spdx-expression-parse": "^3.0.0", | ||
"spdx-ranges": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"defence-cli": "^1.0.1" | ||
"defence-cli": "^2.0.1", | ||
"replace-require-self": "^1.1.1", | ||
"standard": "^11.0.0" | ||
}, | ||
@@ -26,4 +29,5 @@ "keywords": [ | ||
"scripts": { | ||
"test": "defence -i javascript README.md | sed 's!spdx-satisfies!./!' | node" | ||
"test": "defence -i javascript README.md | replace-require-self | node", | ||
"lint": "standard" | ||
} | ||
} |
@@ -13,3 +13,6 @@ ```javascript | ||
assert(satisfies('GPL-3.0', 'GPL-2.0+')) | ||
assert(satisfies('GPL-1.0+', 'GPL-2.0+')) | ||
assert(!satisfies('GPL-1.0', 'GPL-2.0+')) | ||
assert(satisfies('GPL-2.0-only', 'GPL-2.0-only')) | ||
assert(satisfies('GPL-3.0-only', 'GPL-2.0+')) | ||
@@ -16,0 +19,0 @@ assert(!satisfies( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5668
103
1
32
3
3
+ Addedspdx-ranges@^2.0.0
+ Addedarray-find-index@1.0.2(transitive)
+ Addedspdx-compare@1.0.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedspdx-ranges@2.1.1(transitive)
- Removedspdx-compare@0.1.2(transitive)
- Removedspdx-expression-parse@1.0.4(transitive)
- Removedspdx-ranges@1.0.1(transitive)
Updatedspdx-compare@^1.0.0
Updatedspdx-expression-parse@^3.0.0