What is spdx-compare?
The spdx-compare npm package is used to compare SPDX license identifiers. It helps in determining if two SPDX license identifiers are equivalent or if one is a subset of the other. This is particularly useful in license compliance and management scenarios.
What are spdx-compare's main functionalities?
Compare two SPDX license identifiers for equality
This feature allows you to compare two SPDX license identifiers to check if they are exactly the same. In this example, it compares 'MIT' with 'MIT' and returns true.
const spdxCompare = require('spdx-compare');
const license1 = 'MIT';
const license2 = 'MIT';
const areEqual = spdxCompare(license1, license2);
console.log(`Are the licenses equal? ${areEqual}`);
Compare two SPDX license identifiers for subset relationship
This feature allows you to check if one SPDX license identifier is a subset of another. In this example, it checks if 'MIT' is a subset of 'MIT OR Apache-2.0' and returns true.
const spdxCompare = require('spdx-compare');
const license1 = 'MIT';
const license2 = 'MIT OR Apache-2.0';
const isSubset = spdxCompare.subset(license1, license2);
console.log(`Is the first license a subset of the second? ${isSubset}`);
Other packages similar to spdx-compare
spdx-satisfies
The spdx-satisfies package is used to check if a given license satisfies a given SPDX expression. It is similar to spdx-compare in that it deals with SPDX license identifiers, but it focuses more on checking if a license meets the criteria of an SPDX expression rather than direct comparison.
spdx-correct
The spdx-correct package is used to correct common misspellings and variations of SPDX license identifiers. While spdx-compare focuses on comparing licenses, spdx-correct helps in normalizing and correcting license identifiers to their standard SPDX forms.
Compare SPDX license expressions
npm i --save spdx-compare
In JavaScript:
compare.gt('GPL-3.0', 'GPL-2.0');
compare.lt('MPL-1.0', 'MPL-2.0');
compare.gt('LPPL-1.3a', 'LPPL-1.0');
compare.gt('LPPL-1.3c', 'LPPL-1.3a');
compare.gt('MIT', 'ISC');
compare.gt('OSL-1.0', 'OPL-1.0');
compare.gt('AGPL-3.0', 'AGPL-1.0');
try {
compare.gt('(MIT OR ISC)', 'GPL-3.0');
} catch (error) {
error.message;
}