-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from jslicense/array
Change API to `satisfies(SPDX Expression, Array of Approved Licenses)`
- Loading branch information
Showing
6 changed files
with
128 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,14 @@ | ||
`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')) | ||
|
||
assert(satisfies('MIT', '(ISC OR MIT)')) | ||
assert(satisfies('Zlib', '(ISC OR (MIT OR Zlib))')) | ||
assert(!satisfies('GPL-3.0', '(ISC OR MIT)')) | ||
|
||
assert(satisfies('GPL-2.0', 'GPL-2.0+')) | ||
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+')) | ||
assert(satisfies('LGPL-3.0-only', 'LGPL-3.0-or-later')) | ||
assert(satisfies('GPL-2.0', 'GPL-2.0+')) | ||
assert(satisfies('GPL-2.0-only', 'GPL-2.0+')) | ||
assert(satisfies('GPL-2.0', 'GPL-2.0-or-later')) | ||
|
||
assert(!satisfies( | ||
'GPL-2.0', | ||
'GPL-2.0+ WITH Bison-exception-2.2' | ||
)) | ||
|
||
assert(satisfies( | ||
'GPL-3.0 WITH Bison-exception-2.2', | ||
'GPL-2.0+ WITH Bison-exception-2.2' | ||
)) | ||
|
||
assert(satisfies('(MIT OR GPL-2.0)', '(ISC OR MIT)')) | ||
assert(satisfies('(MIT AND GPL-2.0)', '(MIT AND GPL-2.0)')) | ||
assert(satisfies('MIT AND GPL-2.0 AND ISC', 'MIT AND GPL-2.0 AND ISC')) | ||
assert(satisfies('MIT AND GPL-2.0 AND ISC', 'ISC AND GPL-2.0 AND MIT')) | ||
assert(satisfies('(MIT OR GPL-2.0) AND ISC', 'MIT AND ISC')) | ||
assert(satisfies('MIT AND ISC', '(MIT OR GPL-2.0) AND ISC')) | ||
assert(satisfies('MIT AND ISC', '(MIT AND GPL-2.0) OR ISC')) | ||
assert(satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'Apache-2.0 AND ISC')) | ||
assert(satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'Apache-2.0 OR ISC')) | ||
assert(satisfies('(MIT AND GPL-2.0)', '(MIT OR GPL-2.0)')) | ||
assert(satisfies('(MIT AND GPL-2.0)', '(GPL-2.0 AND MIT)')) | ||
assert(satisfies('MIT', '(GPL-2.0 OR MIT) AND (MIT OR ISC)')) | ||
assert(satisfies('MIT AND ICU', '(MIT AND GPL-2.0) OR (ISC AND (Apache-2.0 OR ICU))')) | ||
assert(!satisfies('(MIT AND GPL-2.0)', '(ISC OR GPL-2.0)')) | ||
assert(!satisfies('MIT AND (GPL-2.0 OR ISC)', 'MIT')) | ||
assert(!satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'MIT')) | ||
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+'])) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"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"]] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
var 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) |