[Pkg-javascript-commits] [node-spdx-expression-parse] 01/05: Import Upstream version 1.0.4

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Wed Oct 26 18:49:02 UTC 2016


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository node-spdx-expression-parse.

commit 7014c8826641c941304aea6169e3a20352dc87e3
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date:   Wed Oct 26 22:51:44 2016 +0530

    Import Upstream version 1.0.4
---
 .gitignore         |  1 +
 .travis.yml        | 14 ++++++++
 AUTHORS            |  3 ++
 CONTRIBUTING.md    | 12 +++++++
 LICENSE            | 22 ++++++++++++
 README.md          | 83 +++++++++++++++++++++++++++++++++++++++++++++
 generate-parser.js | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 index.js           |  5 +++
 package.json       | 37 ++++++++++++++++++++
 9 files changed, 276 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8a5fb0a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+parser.js
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..918bd36
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,14 @@
+---
+language: "node_js"
+node_js:
+- "0.10"
+- "0.11"
+- "0.12"
+- "4"
+- "5"
+- "6"
+- "node"
+script:
+- "npm test"
+- "npm run lint"
+sudo: false
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..155f0f6
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,3 @@
+C. Scott Ananian <cscott at cscott.net> (http://cscott.net)
+Kyle E. Mitchell <kyle at kemitchell.com> (https://kemitchell.com)
+Shinnosuke Watanabe <snnskwtnb at gmail.com>
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..298e84e
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,12 @@
+Pull 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.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..831618e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+The 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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..9928cdc
--- /dev/null
+++ b/README.md
@@ -0,0 +1,83 @@
+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.
+
+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.
diff --git a/generate-parser.js b/generate-parser.js
new file mode 100644
index 0000000..d20bd0e
--- /dev/null
+++ b/generate-parser.js
@@ -0,0 +1,99 @@
+var 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())
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..56a9b50
--- /dev/null
+++ b/index.js
@@ -0,0 +1,5 @@
+var parser = require('./parser').parser
+
+module.exports = function (argument) {
+  return parser.parse(argument)
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..231eb1c
--- /dev/null
+++ b/package.json
@@ -0,0 +1,37 @@
+{
+  "name": "spdx-expression-parse",
+  "description": "parse SPDX license expressions",
+  "version": "1.0.4",
+  "author": "Kyle E. Mitchell <kyle at kemitchell.com> (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"
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-spdx-expression-parse.git



More information about the Pkg-javascript-commits mailing list