pax_global_header00006660000000000000000000000064127752572660014535gustar00rootroot0000000000000052 comment=326b222ed9e89e9ef472656e9970649b9ee4e8f3 spdx-expression-parse.js-1.0.4/000077500000000000000000000000001277525726600164355ustar00rootroot00000000000000spdx-expression-parse.js-1.0.4/.gitignore000066400000000000000000000000121277525726600204160ustar00rootroot00000000000000parser.js spdx-expression-parse.js-1.0.4/.travis.yml000066400000000000000000000002111277525726600205400ustar00rootroot00000000000000--- language: "node_js" node_js: - "0.10" - "0.11" - "0.12" - "4" - "5" - "6" - "node" script: - "npm test" - "npm run lint" sudo: false spdx-expression-parse.js-1.0.4/AUTHORS000066400000000000000000000002431277525726600175040ustar00rootroot00000000000000C. Scott Ananian (http://cscott.net) Kyle E. Mitchell (https://kemitchell.com) Shinnosuke Watanabe spdx-expression-parse.js-1.0.4/CONTRIBUTING.md000066400000000000000000000005461277525726600206730ustar00rootroot00000000000000Pull requests are most welcome! Please: 1. Use [JavaScript Standard Style](https://www.npmjs.com/packages/standard). 2. Add tests to the code blocks in `README.md`, using Node.js' built-in `assert` module. Travis CI runs those examples as a test suite. 3. Add yourself to `AUTHORS`. 4. License your contributions under the existing, MIT-style terms. spdx-expression-parse.js-1.0.4/LICENSE000066400000000000000000000021271277525726600174440ustar00rootroot00000000000000The MIT License Copyright (c) 2015 Kyle E. Mitchell & other authors listed in AUTHORS 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. spdx-expression-parse.js-1.0.4/README.md000066400000000000000000000070301277525726600177140ustar00rootroot00000000000000This 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. In a nutshell: ```javascript var parse = require('spdx-expression-parse') var assert = require('assert') assert.deepEqual( // Licensed under the terms of the Two-Clause BSD License. parse('BSD-2-Clause'), {license: 'BSD-2-Clause'} ) assert.throws(function () { // An invalid SPDX license expression. // Should be `Apache-2.0`. parse('Apache 2') }) assert.deepEqual( // Dual licensed under LGPL 2.1 or a combination of the Three-Clause // BSD License and the MIT License. parse('(LGPL-2.1 OR BSD-3-Clause AND MIT)'), { left: {license: 'LGPL-2.1'}, conjunction: 'or', right: { left: {license: 'BSD-3-Clause'}, conjunction: 'and', right: {license: 'MIT'} } } ) ``` 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. 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: 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. Any license identifier from the license list is a valid license expression: ```javascript require('spdx-license-ids').forEach(function (id) { assert.deepEqual(parse(id), {license: id}) }) ``` So is any license identifier `WITH` a standardized license exception: ```javascript require('spdx-license-ids').forEach(function (id) { require('spdx-exceptions').forEach(function (e) { assert.deepEqual( parse(id + ' WITH ' + e), {license: id, exception: e} ) }) }) ``` 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. ```javascript assert.deepEqual( // Licensed under a combination of the MIT License and a combination // of LGPL 2.1 (or a later version) and the Three-Clause BSD License. parse('(MIT AND (LGPL-2.1+ AND BSD-3-Clause))'), { left: {license: 'MIT'}, conjunction: 'and', right: { left: {license: 'LGPL-2.1', plus: true}, conjunction: 'and', right: {license: 'BSD-3-Clause'} } } ) ``` 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. spdx-expression-parse.js-1.0.4/generate-parser.js000066400000000000000000000050441277525726600220620ustar00rootroot00000000000000var Generator = require('jison').Generator var options = { type: 'slr', moduleType: 'commonjs', moduleName: 'spdxparse' } var words = ['AND', 'OR', 'WITH'] var quote = function (argument) { return '\'' + argument + '\'' } var regexEscape = function (s) { return s.replace(/[\^\\$*+?.()|{}\[\]\/]/g, '\\$&') } var handleLicensesAndExceptions = function () { var ids = require('spdx-license-ids') var exceptions = require('spdx-exceptions') // Sort tokens longest-first (both license ids and exception strings) var tokens = ids.concat(exceptions) tokens.sort(function (a, b) { return b.length - a.length }) return tokens.map(function (t) { var type = (ids.indexOf(t) >= 0) ? 'LICENSE' : 'EXCEPTION' return [regexEscape(t), 'return ' + quote(type)] }) } var grammar = { lex: { macros: {}, rules: [ ['$', 'return ' + quote('EOS')], ['\\s+', '/* skip whitespace */'], ['\\+', 'return ' + quote('PLUS')], ['\\(', 'return ' + quote('OPEN')], ['\\)', 'return ' + quote('CLOSE')], [':', 'return ' + quote('COLON')], [ 'DocumentRef-([0-9A-Za-z-+.]+)', 'return ' + quote('DOCUMENTREF') ], [ 'LicenseRef-([0-9A-Za-z-+.]+)', 'return ' + quote('LICENSEREF') ] ] .concat(words.map(function (word) { return [word, 'return ' + quote(word)] })) .concat(handleLicensesAndExceptions()) }, operators: [ ['left', 'OR'], ['left', 'AND'], ['right', 'PLUS', 'WITH'] ], tokens: [ 'CLOSE', 'COLON', 'EXCEPTION', 'LICENSE', 'LICENSEREF', 'OPEN', 'PLUS' ].concat(words).join(' '), start: 'start', bnf: { start: [['expression EOS', 'return $$ = $1']], simpleExpression: [ ['LICENSE', '$$ = {license: yytext}'], ['LICENSE PLUS', '$$ = {license: $1, plus: true}'], ['LICENSEREF', '$$ = {license: yytext}'], ['DOCUMENTREF COLON LICENSEREF', '$$ = {license: yytext}'] ], expression: [ ['simpleExpression', '$$ = $1'], ['simpleExpression WITH EXCEPTION', [ '$$ = {exception: $3}', '$$.license = $1.license', 'if ($1.hasOwnProperty(\'plus\')) {', ' $$.plus = $1.plus', '}'].join('\n')], [ 'expression AND expression', '$$ = {conjunction: \'and\', left: $1, right: $3}' ], [ 'expression OR expression', '$$ = {conjunction: \'or\', left: $1, right: $3}' ], ['OPEN expression CLOSE', '$$ = $2'] ] } } console.log(new Generator(grammar, options).generate()) spdx-expression-parse.js-1.0.4/index.js000066400000000000000000000001621277525726600201010ustar00rootroot00000000000000var parser = require('./parser').parser module.exports = function (argument) { return parser.parse(argument) } spdx-expression-parse.js-1.0.4/package.json000066400000000000000000000016151277525726600207260ustar00rootroot00000000000000{ "name": "spdx-expression-parse", "description": "parse SPDX license expressions", "version": "1.0.4", "author": "Kyle E. Mitchell (http://kemitchell.com)", "files": [ "AUTHORS", "index.js", "parser.js" ], "devDependencies": { "defence-cli": "^1.0.1", "jison": "^0.4.15", "replace-require-self": "^1.0.0", "spdx-exceptions": "^1.0.4", "spdx-license-ids": "^1.0.0", "standard": "^8.0.0" }, "keywords": [ "SPDX", "law", "legal", "license", "metadata", "package", "package.json", "standards" ], "license": "(MIT AND CC-BY-3.0)", "repository": "kemitchell/spdx-expression-parse.js", "scripts": { "lint": "standard", "prepublish": "node generate-parser.js > parser.js", "pretest": "npm run prepublish", "test": "defence -i javascript README.md | replace-require-self | node" } }