pax_global_header00006660000000000000000000000064147373351330014523gustar00rootroot0000000000000052 comment=939c23d674a471102a1551b76280c0bbbb84f062 jslicense-spdx-satisfies.js-6e11221/000077500000000000000000000000001473733513300173245ustar00rootroot00000000000000jslicense-spdx-satisfies.js-6e11221/.github/000077500000000000000000000000001473733513300206645ustar00rootroot00000000000000jslicense-spdx-satisfies.js-6e11221/.github/workflows/000077500000000000000000000000001473733513300227215ustar00rootroot00000000000000jslicense-spdx-satisfies.js-6e11221/.github/workflows/ci.yml000066400000000000000000000006621473733513300240430ustar00rootroot00000000000000name: CI on: [push] jobs: build: runs-on: ubuntu-latest strategy: fail-fast: false matrix: node: ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} check-latest: true - run: npm install - run: npm test env: CI: true jslicense-spdx-satisfies.js-6e11221/.gitignore000066400000000000000000000000151473733513300213100ustar00rootroot00000000000000node_modules jslicense-spdx-satisfies.js-6e11221/CONTRIBUTING.md000066400000000000000000000004211473733513300215520ustar00rootroot00000000000000Please stick to ES5 syntax: `var`, `function`, and so on. This is a very simple package. Several users run it indirectly, via CLI tools, on old versions of Node.js. Please mention that you license your contributions on the same [MIT License terms](LICENSE) in your PRs. jslicense-spdx-satisfies.js-6e11221/LICENSE000066400000000000000000000020761473733513300203360ustar00rootroot00000000000000The MIT License Copyright (c) spdx-satisfies.js contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jslicense-spdx-satisfies.js-6e11221/README.md000066400000000000000000000011541473733513300206040ustar00rootroot00000000000000`satisfies(SPDX license expression, array of approved licenses)` Approved licenses may be simple license identifiers like `MIT`, plus-ranges like `EPL-2.0+`, or licenses with exceptions like `Apache-2.0 WITH LLVM`. They may _not_ be compound expressions using `AND` or `OR`. ```javascript var assert = require('assert') var satisfies = require('spdx-satisfies') assert(satisfies('MIT', ['MIT', 'ISC', 'BSD-2-Clause', 'Apache-2.0'])) assert(satisfies('GPL-2.0 OR MIT', ['MIT'])) assert(!satisfies('GPL-2.0 AND MIT', ['MIT'])) assert(satisfies('GPL-3.0', ['GPL-2.0+'])) assert(!satisfies('GPL-1.0', ['GPL-2.0+'])) ``` jslicense-spdx-satisfies.js-6e11221/examples.json000066400000000000000000000021121473733513300220310ustar00rootroot00000000000000{ "returnTrue": [ ["MIT", ["MIT"]], ["MIT", ["ISC", "MIT"]], ["Zlib", ["ISC", "MIT", "Zlib"]], ["GPL-2.0", ["GPL-2.0+"]], ["GPL-3.0", ["GPL-2.0+"]], ["GPL-1.0+", ["GPL-2.0+"]], ["GPL-2.0-only", ["GPL-2.0-only"]], ["GPL-3.0-only", ["GPL-2.0+"]], ["LGPL-3.0-only", ["LGPL-3.0-or-later"]], ["GPL-2.0", ["GPL-2.0+"]], ["GPL-2.0-only", ["GPL-2.0+"]], ["GPL-2.0", ["GPL-2.0-or-later"]], ["GPL-3.0 WITH Bison-exception-2.2", ["GPL-2.0+ WITH Bison-exception-2.2"]], ["(MIT OR GPL-2.0)", ["ISC", "MIT"]], ["(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)", ["Apache-2.0", "ISC"]], ["(MIT AND GPL-2.0)", ["MIT", "GPL-2.0"]] ], "returnFalse": [ ["GPL-3.0", ["ISC", "MIT"]], ["GPL-1.0", ["GPL-2.0+"]], ["GPL-2.0", ["GPL-2.0+ WITH Bison-exception-2.2"]], ["(MIT AND GPL-2.0)", ["ISC", "GPL-2.0"]], ["MIT AND (GPL-2.0 OR ISC)", ["MIT"]], ["(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)", ["MIT"]] ], "throwErrors": [ ["MIT AND ISC", ["(MIT OR GPL-2.0) AND ISC"]], ["MIT AND ISC", ["(MIT AND GPL-2.0)", "ISC"]] ] } jslicense-spdx-satisfies.js-6e11221/index.js000066400000000000000000000105631473733513300207760ustar00rootroot00000000000000var compare = require('spdx-compare') var parse = require('spdx-expression-parse') var ranges = require('spdx-ranges') function rangesAreCompatible (first, second) { return ( first.license === second.license || ranges.some(function (range) { return ( licenseInRange(first.license, range) && licenseInRange(second.license, range) ) }) ) } function licenseInRange (license, range) { return ( range.indexOf(license) !== -1 || range.some(function (element) { return ( Array.isArray(element) && element.indexOf(license) !== -1 ) }) ) } function identifierInRange (identifier, range) { return ( identifier.license === range.license || compare.gt(identifier.license, range.license) || compare.eq(identifier.license, range.license) ) } function licensesAreCompatible (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 } } } } function replaceGPLOnlyOrLaterWithRanges (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('-only', '') delete argument.plus } } else if (argument.left && argument.right) { argument.left = replaceGPLOnlyOrLaterWithRanges(argument.left) argument.right = replaceGPLOnlyOrLaterWithRanges(argument.right) } return argument } function endsWith (string, substring) { return string.indexOf(substring) === string.length - substring.length } function licenseString (e) { if (e.hasOwnProperty('noassertion')) return 'NOASSERTION' if (e.license) { return ( e.license + (e.plus ? '+' : '') + (e.exception ? ('WITH ' + e.exception) : '') ) } } // Expand the given expression into an equivalent array where each member is an array of licenses AND'd // together and the members are OR'd together. For example, `(MIT OR ISC) AND GPL-3.0` expands to // `[[GPL-3.0 AND MIT], [ISC AND MIT]]`. Note that within each array of licenses, the entries are // normalized (sorted) by license name. function expand (expression) { return sort(expandInner(expression)) } function expandInner (expression) { if (!expression.conjunction) return [{ [licenseString(expression)]: expression }] if (expression.conjunction === 'or') return expandInner(expression.left).concat(expandInner(expression.right)) if (expression.conjunction === 'and') { var left = expandInner(expression.left) var right = expandInner(expression.right) return left.reduce(function (result, l) { right.forEach(function (r) { result.push(Object.assign({}, l, r)) }) return result }, []) } } function sort (licenseList) { var sortedLicenseLists = licenseList .filter(function (e) { return Object.keys(e).length }) .map(function (e) { return Object.keys(e).sort() }) return sortedLicenseLists.map(function (list, i) { return list.map(function (license) { return licenseList[i][license] }) }) } function isANDCompatible (parsedExpression, parsedLicenses) { return parsedExpression.every(function (element) { return parsedLicenses.some(function (approvedLicense) { return licensesAreCompatible(element, approvedLicense) }) }) } function satisfies (spdxExpression, arrayOfLicenses) { var parsedExpression = expand(replaceGPLOnlyOrLaterWithRanges(parse(spdxExpression))) var parsedLicenses = arrayOfLicenses.map(function (l) { return replaceGPLOnlyOrLaterWithRanges(parse(l)) }) for (const parsed of parsedLicenses) { if (parsed.hasOwnProperty('conjunction')) { throw new Error('Approved licenses cannot be AND or OR expressions.') } } return parsedExpression.some(function (o) { return isANDCompatible(o, parsedLicenses) }) } module.exports = satisfies jslicense-spdx-satisfies.js-6e11221/package.json000066400000000000000000000021041473733513300216070ustar00rootroot00000000000000{ "name": "spdx-satisfies", "description": "test whether SPDX expressions satisfy licensing criteria", "version": "6.0.0", "author": "Kyle E. Mitchell (https://kemitchell.com)", "contributors": [ "Kyle E. Mitchell (https://kemitchell.com)", "Dan Butvinik ", "Jeff McAffer " ], "dependencies": { "spdx-compare": "^1.0.0", "spdx-expression-parse": "^3.0.0", "spdx-ranges": "^2.0.0" }, "devDependencies": { "defence-cli": "^3.0.1", "replace-require-self": "^1.1.1", "standard": "^11.0.0" }, "keywords": [ "SPDX", "law", "legal", "license", "metadata", "package", "package.json", "standards" ], "license": "MIT", "repository": "kemitchell/spdx-satisfies.js", "files": [ "index.js" ], "scripts": { "test": "npm run test:suite && npm run test:readme", "test:suite": "node test.js", "test:readme": "defence -i javascript README.md | replace-require-self | node", "lint": "standard" } } jslicense-spdx-satisfies.js-6e11221/test.js000066400000000000000000000021461473733513300206440ustar00rootroot00000000000000var assert = require('assert') var examples = require('./examples.json') var satisfies = require('./') var failed = false function write (string) { process.stdout.write(string) } function label (example) { write('satisfies(' + JSON.stringify(example[0]) + ', ' + JSON.stringify(example[1]) + ')') } examples.returnTrue.forEach(function (example) { label(example) try { assert(satisfies(example[0], example[1]) === true) } catch (error) { failed = true write(' did not return true\n') return } write(' returned true\n') }) // False Examples examples.returnFalse.forEach(function (example) { label(example) try { assert(satisfies(example[0], example[1]) === false) } catch (error) { failed = true write(' did not return false\n') return } write(' returned false\n') }) // Invalid License Arrays examples.throwErrors.forEach(function (example) { label(example) try { satisfies(example[0], example[1]) } catch (error) { write(' threw an exception\n') return } failed = true write(' did not throw an exception\n') }) process.exit(failed ? 1 : 0)