Skip to content

Commit 12805a4

Browse files
committed
Add explanation to README
1 parent 33aeaf6 commit 12805a4

File tree

1 file changed

+62
-24
lines changed

1 file changed

+62
-24
lines changed

README.md

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1+
This package parses SPDX license expression strings describing license terms, like [package.json license strings](https://docs.npmjs.com/files/package.json#license), into consistently structured ECMAScript objects. The npm command-line interface depends on this package, as do many automatic license-audit tools.
2+
3+
In a nutshell:
4+
15
```javascript
26
var parse = require('spdx-expression-parse')
37
var assert = require('assert')
48

59
assert.deepEqual(
10+
// Licensed under the terms of the Two-Clause BSD License.
11+
parse('BSD-2-Clause'),
12+
{license: 'BSD-2-Clause'}
13+
)
14+
15+
assert.throws(function () {
16+
// An invalid SPDX license expression.
17+
// Should be `Apache-2.0`.
18+
parse('Apache 2')
19+
})
20+
21+
assert.deepEqual(
22+
// Dual licensed under LGPL 2.1 or a combination of the Three-Clause
23+
// BSD License and the MIT License.
624
parse('(LGPL-2.1 OR BSD-3-Clause AND MIT)'),
725
{
826
left: {license: 'LGPL-2.1'},
@@ -14,32 +32,52 @@ assert.deepEqual(
1432
}
1533
}
1634
)
35+
```
1736

18-
assert.deepEqual(
19-
parse('(MIT AND (LGPL-2.1+ AND BSD-3-Clause))'),
20-
{
21-
left: {license: 'MIT'},
22-
conjunction: 'and',
23-
right: {
24-
left: {license: 'LGPL-2.1', plus: true},
25-
conjunction: 'and',
26-
right: {license: 'BSD-3-Clause'}
27-
}
28-
}
29-
)
37+
The syntax comes from the [Software Package Data eXchange (SPDX)](https://spdx.org/), a standard from the [Linux Foundation](https://www.linuxfoundation.org) for shareable data about software package license terms. SPDX aims to make sharing and auditing license data easy, especially for users of open-source software.
38+
39+
The bulk of the SPDX standard describes syntax and semantics of XML metadata files. This package implements two lightweight, plain-text components of that larger standard:
40+
41+
1. The [license list](https://spdx.org/licenses), a mapping from specific string identifiers, like `Apache-2.0`, to standard form license texts and bolt-on license exceptions. The [spdx-license-ids](https://www.npmjs.com/package/spdx-exceptions) and [spdx-exceptions](https://www.npmjs.com/package/spdx-license-ids) packages implement the license list. They are development dependencies of this package.
42+
43+
Any license identifier from the license list is a valid license expression:
44+
45+
```javascript
46+
require('spdx-license-ids').forEach(function (id) {
47+
assert.deepEqual(parse(id), {license: id})
48+
})
49+
```
3050

31-
// We handle all the bare SPDX license and exception ids as well.
32-
require('spdx-license-ids').forEach(function (id) {
33-
assert.deepEqual(parse(id), {license: id})
34-
require('spdx-exceptions').forEach(function (e) {
51+
So is any license identifier `WITH` a standardized license exception:
52+
53+
```javascript
54+
require('spdx-license-ids').forEach(function (id) {
55+
require('spdx-exceptions').forEach(function (e) {
56+
assert.deepEqual(
57+
parse(id + ' WITH ' + e),
58+
{license: id, exception: e}
59+
)
60+
})
61+
})
62+
```
63+
64+
2. The license expression language, for describing simple and complex license terms, like `MIT` for MIT-licensed and `(GPL-2.0 OR Apache-2.0)` for dual-licensing under GPL 2.0 and Apache 2.0. This package implements the license expression language.
65+
66+
```javascript
3567
assert.deepEqual(
36-
parse(id + ' WITH ' + e),
37-
{license: id, exception: e}
68+
// Licensed under a combination of the MIT License and a combination
69+
// of LGPL 2.1 (or a later version) and the Three-Clause BSD License.
70+
parse('(MIT AND (LGPL-2.1+ AND BSD-3-Clause))'),
71+
{
72+
left: {license: 'MIT'},
73+
conjunction: 'and',
74+
right: {
75+
left: {license: 'LGPL-2.1', plus: true},
76+
conjunction: 'and',
77+
right: {license: 'BSD-3-Clause'}
78+
}
79+
}
3880
)
39-
})
40-
})
41-
```
42-
43-
---
81+
```
4482

45-
[The Software Package Data Exchange (SPDX) specification](http://spdx.org) is the work of the [Linux Foundation](http://www.linuxfoundation.org) and its contributors, and is licensed under the terms of [the Creative Commons Attribution License 3.0 Unported (SPDX: "CC-BY-3.0")](http://spdx.org/licenses/CC-BY-3.0). "SPDX" is a United States federally registered trademark of the Linux Foundation.
83+
The Linux Foundation and its contributors license the SPDX standard under the terms of [the Creative Commons Attribution License 3.0 Unported (SPDX: "CC-BY-3.0")](http://spdx.org/licenses/CC-BY-3.0). "SPDX" is a United States federally registered trademark of the Linux Foundation. The authors of this package license their work under the terms of the MIT License.

0 commit comments

Comments
 (0)