Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spdx-satisfies

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spdx-satisfies - npm Package Compare versions

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(

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc