spdx-satisfies 0.1.1 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) spdx-satisfies.js contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the "Software"),
7
+ to deal in the Software without restriction, including without limitation
8
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ and/or sell copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included
13
+ in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
+ OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1 +1,40 @@
1
- Test whether SPDX expressions satisfy given licensing criteria
1
+ ```javascript
2
+ var assert = require('assert')
3
+ var satisfies = require('spdx-satisfies')
4
+
5
+ assert(satisfies('MIT', 'MIT'))
6
+
7
+ assert(satisfies('MIT', '(ISC OR MIT)'))
8
+ assert(satisfies('Zlib', '(ISC OR (MIT OR Zlib))'))
9
+ assert(!satisfies('GPL-3.0', '(ISC OR MIT)'))
10
+
11
+ assert(satisfies('GPL-2.0', 'GPL-2.0+'))
12
+ assert(satisfies('GPL-3.0', 'GPL-2.0+'))
13
+ assert(satisfies('GPL-1.0+', 'GPL-2.0+'))
14
+ assert(!satisfies('GPL-1.0', 'GPL-2.0+'))
15
+ assert(satisfies('GPL-2.0-only', 'GPL-2.0-only'))
16
+ assert(satisfies('GPL-3.0-only', 'GPL-2.0+'))
17
+
18
+ assert(!satisfies(
19
+ 'GPL-2.0',
20
+ 'GPL-2.0+ WITH Bison-exception-2.2'
21
+ ))
22
+
23
+ assert(satisfies(
24
+ 'GPL-3.0 WITH Bison-exception-2.2',
25
+ 'GPL-2.0+ WITH Bison-exception-2.2'
26
+ ))
27
+
28
+ assert(satisfies('(MIT OR GPL-2.0)', '(ISC OR MIT)'))
29
+ assert(satisfies('(MIT AND GPL-2.0)', '(MIT AND GPL-2.0)'))
30
+ assert(satisfies('MIT AND GPL-2.0 AND ISC', 'MIT AND GPL-2.0 AND ISC'))
31
+ assert(satisfies('(MIT OR GPL-2.0) AND ISC', 'MIT AND ISC'))
32
+ assert(satisfies('MIT AND ISC', '(MIT OR GPL-2.0) AND ISC'))
33
+ assert(satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'Apache-2.0 AND ISC'))
34
+ assert(satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'Apache-2.0 OR ISC'))
35
+ assert(satisfies('(MIT AND GPL-2.0)', '(MIT OR GPL-2.0)'))
36
+ assert(satisfies('(MIT AND GPL-2.0)', '(GPL-2.0 AND MIT)'))
37
+ assert(!satisfies('(MIT AND GPL-2.0)', '(ISC OR GPL-2.0)'))
38
+ assert(!satisfies('MIT AND (GPL-2.0 OR ISC)', 'MIT'))
39
+ assert(!satisfies('(MIT OR Apache-2.0) AND (ISC OR GPL-2.0)', 'MIT'))
40
+ ```
package/index.js ADDED
@@ -0,0 +1,119 @@
1
+ var compare = require('spdx-compare')
2
+ var parse = require('spdx-expression-parse')
3
+ var ranges = require('spdx-ranges')
4
+
5
+ var rangesAreCompatible = function (first, second) {
6
+ return (
7
+ first.license === second.license ||
8
+ ranges.some(function (range) {
9
+ return (
10
+ licenseInRange(first.license, range) &&
11
+ licenseInRange(second.license, range)
12
+ )
13
+ })
14
+ )
15
+ }
16
+
17
+ function licenseInRange (license, range) {
18
+ return (
19
+ range.indexOf(license) !== -1 ||
20
+ range.some(function (element) {
21
+ return (
22
+ Array.isArray(element) &&
23
+ element.indexOf(license) !== -1
24
+ )
25
+ })
26
+ )
27
+ }
28
+
29
+ var identifierInRange = function (identifier, range) {
30
+ return (
31
+ identifier.license === range.license ||
32
+ compare.gt(identifier.license, range.license) ||
33
+ compare.eq(identifier.license, range.license)
34
+ )
35
+ }
36
+
37
+ var licensesAreCompatible = function (first, second) {
38
+ if (first.exception !== second.exception) {
39
+ return false
40
+ } else if (second.hasOwnProperty('license')) {
41
+ if (second.hasOwnProperty('plus')) {
42
+ if (first.hasOwnProperty('plus')) {
43
+ // first+, second+
44
+ return rangesAreCompatible(first, second)
45
+ } else {
46
+ // first, second+
47
+ return identifierInRange(first, second)
48
+ }
49
+ } else {
50
+ if (first.hasOwnProperty('plus')) {
51
+ // first+, second
52
+ return identifierInRange(second, first)
53
+ } else {
54
+ // first, second
55
+ return first.license === second.license
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ var recurseLeftAndRight = function (first, second) {
62
+ var firstConjunction = first.conjunction
63
+ var secondConjunction = second.conjunction
64
+
65
+ if (firstConjunction === 'and' && secondConjunction === 'and') {
66
+ return (
67
+ (recurse(first.left, second.left) && recurse(first.right, second.right)) ||
68
+ (recurse(first.left, second.right) && recurse(first.right, second.left))
69
+ )
70
+ } else if (firstConjunction === 'and') {
71
+ return (
72
+ recurse(first.left, second) &&
73
+ recurse(first.right, second)
74
+ )
75
+ } else if (firstConjunction === 'or') {
76
+ return (
77
+ recurse(first.left, second) ||
78
+ recurse(first.right, second)
79
+ )
80
+ }
81
+ }
82
+
83
+ var recurse = function (first, second) {
84
+ if (first.hasOwnProperty('conjunction')) {
85
+ return recurseLeftAndRight(first, second)
86
+ } else if (second.hasOwnProperty('conjunction')) {
87
+ return recurseLeftAndRight(second, first)
88
+ } else {
89
+ return licensesAreCompatible(first, second)
90
+ }
91
+ }
92
+
93
+ function normalizeGPLIdentifiers (argument) {
94
+ var license = argument.license
95
+ if (license) {
96
+ if (endsWith(license, '-or-later')) {
97
+ argument.license = license.replace('-or-later', '')
98
+ argument.plus = true
99
+ } else if (endsWith(license, '-only')) {
100
+ argument.license = license.replace('-or-later', '')
101
+ delete argument.plus
102
+ }
103
+ } else {
104
+ argument.left = normalizeGPLIdentifiers(argument.left)
105
+ argument.right = normalizeGPLIdentifiers(argument.right)
106
+ }
107
+ return argument
108
+ }
109
+
110
+ function endsWith (string, substring) {
111
+ return string.indexOf(substring) === string.length - 1
112
+ }
113
+
114
+ module.exports = function (first, second) {
115
+ return recurse(
116
+ normalizeGPLIdentifiers(parse(first)),
117
+ normalizeGPLIdentifiers(parse(second))
118
+ )
119
+ }
package/package.json CHANGED
@@ -1,19 +1,36 @@
1
1
  {
2
2
  "name": "spdx-satisfies",
3
3
  "description": "test whether SPDX expressions satisfy licensing criteria",
4
- "version": "0.1.1",
4
+ "version": "4.0.1",
5
5
  "author": "Kyle E. Mitchell <kyle@kemitchell.com> (https://kemitchell.com)",
6
+ "contributors": [
7
+ "Kyle E. Mitchell <kyle@kemitchell.com> (https://kemitchell.com)",
8
+ "Dan Butvinik <butvinik@outlook.com>"
9
+ ],
6
10
  "dependencies": {
7
- "spdx": "0.4.x",
8
- "spdx-compare": "0.1.x"
11
+ "spdx-compare": "^1.0.0",
12
+ "spdx-expression-parse": "^3.0.0",
13
+ "spdx-ranges": "^2.0.0"
9
14
  },
10
15
  "devDependencies": {
11
- "tape": "4.x"
16
+ "defence-cli": "^2.0.1",
17
+ "replace-require-self": "^1.1.1",
18
+ "standard": "^11.0.0"
12
19
  },
20
+ "keywords": [
21
+ "SPDX",
22
+ "law",
23
+ "legal",
24
+ "license",
25
+ "metadata",
26
+ "package",
27
+ "package.json",
28
+ "standards"
29
+ ],
13
30
  "license": "MIT",
14
- "main": "spdx-satisfies.js",
15
31
  "repository": "kemitchell/spdx-satisfies.js",
16
32
  "scripts": {
17
- "test": "tape test.js"
33
+ "test": "defence -i javascript README.md | replace-require-self | node",
34
+ "lint": "standard"
18
35
  }
19
36
  }
package/test.log ADDED
@@ -0,0 +1,70 @@
1
+
2
+ > spdx-satisfies@4.0.0 test /home/kyle/spdx-satisfies.js
3
+ > defence -i javascript README.md | replace-require-self | node
4
+
5
+ first is {"left":{"license":"ISC"},"conjunction":"or","right":{"license":"MIT"}}
6
+ second is {"license":"MIT"}
7
+ first is {"left":{"license":"ISC"},"conjunction":"or","right":{"left":{"license":"MIT"},"conjunction":"or","right":{"license":"Zlib"}}}
8
+ second is {"license":"Zlib"}
9
+ first is {"left":{"license":"MIT"},"conjunction":"or","right":{"license":"Zlib"}}
10
+ second is {"license":"Zlib"}
11
+ first is {"left":{"license":"ISC"},"conjunction":"or","right":{"license":"MIT"}}
12
+ second is {"license":"GPL-3.0"}
13
+ first is {"left":{"license":"MIT"},"conjunction":"or","right":{"license":"GPL-2.0"}}
14
+ second is {"left":{"license":"ISC"},"conjunction":"or","right":{"license":"MIT"}}
15
+ first is {"left":{"license":"ISC"},"conjunction":"or","right":{"license":"MIT"}}
16
+ second is {"license":"MIT"}
17
+ first is {"left":{"license":"MIT"},"conjunction":"and","right":{"license":"GPL-2.0"}}
18
+ second is {"left":{"license":"MIT"},"conjunction":"and","right":{"license":"GPL-2.0"}}
19
+ first is {"left":{"license":"MIT"},"conjunction":"and","right":{"left":{"license":"GPL-2.0"},"conjunction":"and","right":{"license":"ISC"}}}
20
+ second is {"left":{"license":"MIT"},"conjunction":"and","right":{"left":{"license":"GPL-2.0"},"conjunction":"and","right":{"license":"ISC"}}}
21
+ first is {"left":{"license":"GPL-2.0"},"conjunction":"and","right":{"license":"ISC"}}
22
+ second is {"left":{"license":"GPL-2.0"},"conjunction":"and","right":{"license":"ISC"}}
23
+ first is {"left":{"left":{"license":"MIT"},"conjunction":"or","right":{"license":"GPL-2.0"}},"conjunction":"and","right":{"license":"ISC"}}
24
+ second is {"left":{"license":"MIT"},"conjunction":"and","right":{"license":"ISC"}}
25
+ first is {"left":{"license":"MIT"},"conjunction":"or","right":{"license":"GPL-2.0"}}
26
+ second is {"license":"MIT"}
27
+ first is {"left":{"license":"MIT"},"conjunction":"and","right":{"license":"ISC"}}
28
+ second is {"left":{"left":{"license":"MIT"},"conjunction":"or","right":{"license":"GPL-2.0"}},"conjunction":"and","right":{"license":"ISC"}}
29
+ first is {"left":{"license":"MIT"},"conjunction":"or","right":{"license":"GPL-2.0"}}
30
+ second is {"license":"MIT"}
31
+ first is {"left":{"left":{"license":"MIT"},"conjunction":"or","right":{"license":"Apache-2.0"}},"conjunction":"and","right":{"left":{"license":"ISC"},"conjunction":"or","right":{"license":"GPL-2.0"}}}
32
+ second is {"left":{"license":"Apache-2.0"},"conjunction":"and","right":{"license":"ISC"}}
33
+ first is {"left":{"license":"MIT"},"conjunction":"or","right":{"license":"Apache-2.0"}}
34
+ second is {"license":"Apache-2.0"}
35
+ first is {"left":{"license":"ISC"},"conjunction":"or","right":{"license":"GPL-2.0"}}
36
+ second is {"license":"ISC"}
37
+ first is {"left":{"left":{"license":"MIT"},"conjunction":"or","right":{"license":"Apache-2.0"}},"conjunction":"and","right":{"left":{"license":"ISC"},"conjunction":"or","right":{"license":"GPL-2.0"}}}
38
+ second is {"left":{"license":"Apache-2.0"},"conjunction":"or","right":{"license":"ISC"}}
39
+ first is {"left":{"license":"MIT"},"conjunction":"or","right":{"license":"Apache-2.0"}}
40
+ second is {"left":{"license":"Apache-2.0"},"conjunction":"or","right":{"license":"ISC"}}
41
+ first is {"left":{"license":"Apache-2.0"},"conjunction":"or","right":{"license":"ISC"}}
42
+ second is {"license":"MIT"}
43
+ first is {"left":{"license":"Apache-2.0"},"conjunction":"or","right":{"license":"ISC"}}
44
+ second is {"license":"Apache-2.0"}
45
+ first is {"left":{"license":"ISC"},"conjunction":"or","right":{"license":"GPL-2.0"}}
46
+ second is {"left":{"license":"Apache-2.0"},"conjunction":"or","right":{"license":"ISC"}}
47
+ first is {"left":{"license":"Apache-2.0"},"conjunction":"or","right":{"license":"ISC"}}
48
+ second is {"license":"ISC"}
49
+ first is {"left":{"license":"MIT"},"conjunction":"and","right":{"license":"GPL-2.0"}}
50
+ second is {"left":{"license":"MIT"},"conjunction":"or","right":{"license":"GPL-2.0"}}
51
+ first is {"left":{"license":"MIT"},"conjunction":"or","right":{"license":"GPL-2.0"}}
52
+ second is {"license":"MIT"}
53
+ first is {"left":{"license":"MIT"},"conjunction":"or","right":{"license":"GPL-2.0"}}
54
+ second is {"license":"GPL-2.0"}
55
+ first is {"left":{"license":"MIT"},"conjunction":"and","right":{"license":"GPL-2.0"}}
56
+ second is {"left":{"license":"GPL-2.0"},"conjunction":"and","right":{"license":"MIT"}}
57
+ first is {"left":{"license":"MIT"},"conjunction":"and","right":{"license":"GPL-2.0"}}
58
+ second is {"left":{"license":"ISC"},"conjunction":"or","right":{"license":"GPL-2.0"}}
59
+ first is {"left":{"license":"ISC"},"conjunction":"or","right":{"license":"GPL-2.0"}}
60
+ second is {"license":"MIT"}
61
+ first is {"left":{"license":"MIT"},"conjunction":"and","right":{"left":{"license":"GPL-2.0"},"conjunction":"or","right":{"license":"ISC"}}}
62
+ second is {"license":"MIT"}
63
+ first is {"left":{"license":"GPL-2.0"},"conjunction":"or","right":{"license":"ISC"}}
64
+ second is {"license":"MIT"}
65
+ first is {"left":{"left":{"license":"MIT"},"conjunction":"or","right":{"license":"Apache-2.0"}},"conjunction":"and","right":{"left":{"license":"ISC"},"conjunction":"or","right":{"license":"GPL-2.0"}}}
66
+ second is {"license":"MIT"}
67
+ first is {"left":{"license":"MIT"},"conjunction":"or","right":{"license":"Apache-2.0"}}
68
+ second is {"license":"MIT"}
69
+ first is {"left":{"license":"ISC"},"conjunction":"or","right":{"license":"GPL-2.0"}}
70
+ second is {"license":"MIT"}
Binary file
package/spdx-satisfies.js DELETED
@@ -1,58 +0,0 @@
1
- var spdx = require('spdx')
2
- var compare = require('spdx-compare')
3
-
4
- module.exports = (function() {
5
- var rangesAreCompatible = function(first, second) {
6
- return (
7
- first.license === second.license ||
8
- ranges.some(function(range) {
9
- return (
10
- range.indexOf(first.license) > -1 &&
11
- range.indexOf(second.license) ) }) ) }
12
-
13
- var identifierInRange = function(identifier, range) {
14
- return (
15
- identifier.license === range.license ||
16
- compare.gt(identifier.license, range.license) ) }
17
-
18
- var licensesAreCompatible = function(first, second) {
19
- if (first.exception !== second.exception) {
20
- return false }
21
- else if (second.hasOwnProperty('license')) {
22
- if (second.hasOwnProperty('plus')) {
23
- if (first.hasOwnProperty('plus')) {
24
- // first+, second+
25
- return rangesAreCompatible(first, second) }
26
- else {
27
- // first, second+
28
- return identifierInRange(first, second) } }
29
- else {
30
- if (first.hasOwnProperty('plus')) {
31
- // first+, second
32
- return identifierInRange(second, first) }
33
- else {
34
- // first, second
35
- return first.license === second.license } } } }
36
-
37
- var recurseLeftAndRight = function(first, second) {
38
- var firstConjunction = first.conjunction
39
- if (firstConjunction === 'and') {
40
- return (
41
- recurse(first.left, second) &&
42
- recurse(first.right, second) ) }
43
- else if (firstConjunction === 'or') {
44
- return (
45
- recurse(first.left, second) ||
46
- recurse(first.right, second) ) } }
47
-
48
- var recurse = function(first, second) {
49
- if (first.hasOwnProperty('conjunction')) {
50
- return recurseLeftAndRight(first, second) }
51
- else if (second.hasOwnProperty('conjunction')) {
52
- return recurseLeftAndRight(second, first) }
53
- else {
54
- return licensesAreCompatible(first, second) } }
55
-
56
- return function(first, second) {
57
- return recurse(spdx.parse(first), spdx.parse(second)) } })()
58
-