SPDX License Expression Syntax parser
spdx.valid('Invalid-Identifier'); // => null
spdx.valid('GPL-2.0'); // => true
spdx.valid('GPL-2.0+'); // => true
spdx.valid('LicenseRef-23'); // => true
spdx.valid('LicenseRef-MIT-Style-1'); // => true
spdx.valid('DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2'); // => true
spdx.valid('(LGPL-2.1 OR MIT)'); // => true
spdx.valid('(LGPL-2.1 OR MIT OR BSD-3-Clause)'); // => true
spdx.valid('(LGPL-2.1 AND MIT)'); // => true
spdx.valid('(LGPL-2.1 AND MIT AND BSD-2-Clause)'); // => true
spdx.valid('(GPL-2.0+ WITH Bison-exception-2.2)'); // => true
var firstAST = {
left: {license: 'LGPL-2.1'},
conjunction: 'or',
right: {
left: {license: 'BSD-3-Clause'},
conjunction: 'and',
right: {license: 'MIT'}
}
};
spdx.parse('(LGPL-2.1 OR BSD-3-Clause AND MIT)'); // => firstAST
var secondAST = {
left: {license: 'MIT'},
conjunction: 'and',
right: {
left: {license: 'LGPL-2.1', plus: true},
conjunction: 'and',
right: {license: 'BSD-3-Clause'}
}
};
spdx.parse('(MIT AND (LGPL-2.1+ AND BSD-3-Clause))'); // => secondAST
spdx.valid('MIT '); // => false
spdx.valid(' MIT'); // => false
spdx.valid('MIT AND BSD-3-Clause'); // => false
Array.isArray(spdx.licenses); // => true
spdx.licenses.indexOf('ISC') > -1; // => true
spdx.licenses.indexOf('Apache-1.7') > -1; // => false
spdx.licenses.every(function(element) {
return typeof element === 'string';
}); // => true
Array.isArray(spdx.exceptions); // => true
spdx.exceptions.indexOf('GCC-exception-3.1') > -1; // => true
spdx.exceptions.every(function(element) {
return typeof element === 'string';
}); // => true
spdx.gt('GPL-3.0', 'GPL-2.0'); // => true
spdx.lt('MPL-1.0', 'MPL-2.0'); // => true
spdx.gt('LPPL-1.3a', 'LPPL-1.0'); // => true
spdx.gt('LPPL-1.3a', 'LPPL-1.3a'); // => false
spdx.gt('MIT', 'ISC'); // => false
try {
spdx.gt('(MIT OR ISC)', 'GPL-3.0');
} catch (error) {
error.message; // => '"(MIT OR ISC)" is not a simple license identifier'
}
spdx.satisfies('MIT', 'MIT'); // => true
spdx.satisfies('MIT', '(ISC OR MIT)'); // => true
spdx.satisfies('Zlib', '(ISC OR (MIT OR Zlib))'); // => true
spdx.satisfies('GPL-3.0', '(ISC OR MIT)'); // => false
spdx.satisfies('GPL-2.0', 'GPL-2.0+'); // => true
spdx.satisfies('GPL-3.0', 'GPL-2.0+'); // => true
spdx.satisfies('GPL-1.0', 'GPL-2.0+'); // => false
spdx.satisfies('GPL-2.0', 'GPL-2.0+ WITH Bison-exception-2.2'); // => false
spdx.satisfies('GPL-3.0 WITH Bison-exception-2.2', 'GPL-2.0+ WITH Bison-exception-2.2'); // => true
spdx.satisfies('(MIT OR GPL-2.0)', '(ISC OR MIT)'); // => true
spdx.satisfies('(MIT AND GPL-2.0)', '(MIT OR GPL-2.0)'); // => true
spdx.satisfies('(MIT AND GPL-2.0)', '(ISC OR GPL-2.0)'); // => false
spdx.specificationVersion; // => '2.0'
spdx.implementationVersion; // => package.version
The Software Package Data Exchange (SPDX) specification is the work of the Linux Foundation and its contributors, and is licensed under the terms of the Creative Commons Attribution License 3.0 Unported (SPDX: "CC-BY-3.0"). "SPDX" is a United States federally registered trademark of the Linux Foundation.