GithubHelp home page GithubHelp logo

christopher302014 / spdx.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kemitchell/spdx.js

0.0 1.0 0.0 495 KB

SPDX License Expression Syntax parser

Home Page: https://npmjs.com/packages/spdx

License: MIT License

JavaScript 100.00%

spdx.js's Introduction

Use Other Packages

Development on spdx.js has moved to separate, smaller packages.

spdx-expression-parse and spdx-satisfies are direct successors to spdx.js.

You may also be interested in spdx-compare, spdx-correct, and other packages on the npm public registry. kemitchell writes a lot of them.


var spdx = require('spdx')

Simple License Expressions

var assert = require('assert')
assert(spdx.valid('Invalid-Identifier') === null)
assert(spdx.valid('GPL-2.0'))
assert(spdx.valid('GPL-2.0+'))
assert(spdx.valid('LicenseRef-23'))
assert(spdx.valid('LicenseRef-MIT-Style-1'))
assert(spdx.valid('DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2'))

Composite License Expressions

Disjunctive OR Operator

assert(spdx.valid('(LGPL-2.1 OR MIT)'))
assert(spdx.valid('(LGPL-2.1 OR MIT OR BSD-3-Clause)'))

Conjunctive AND Operator

assert(spdx.valid('(LGPL-2.1 AND MIT)'))
assert(spdx.valid('(LGPL-2.1 AND MIT AND BSD-2-Clause)'))

Exception WITH Operator

assert(spdx.valid('(GPL-2.0+ WITH Bison-exception-2.2)'))

Order of Precedence and Parentheses

assert.deepEqual(
  spdx.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' } } })

assert.deepEqual(
  spdx.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' } } })

Strict Whitespace Rules

assert(!spdx.valid('MIT '))
assert(!spdx.valid(' MIT'))
assert(!spdx.valid('MIT  AND  BSD-3-Clause'))

Identifier Lists

assert(Array.isArray(spdx.licenses))
assert(spdx.licenses.indexOf('ISC') > -1)
assert(spdx.licenses.indexOf('Apache-1.7') < 0)
assert(spdx.licenses.every(function(element) {
  return typeof element === 'string' }))

assert(Array.isArray(spdx.exceptions))
assert(spdx.exceptions.indexOf('GCC-exception-3.1') > -1)
assert(spdx.exceptions.every(function(element) {
  return typeof element === 'string' }))

The Specification

assert.equal(spdx.specificationVersion, '2.0')

The Software Package Data Exchange (SPDX) specification is the work of the Linux Foundation and its contributors, and is licensed under the terms of the Creative Commons Attribution License 3.0 Unported (SPDX: "CC-BY-3.0"). "SPDX" is a United States federally registered trademark of the Linux Foundation.

spdx.js's People

Contributors

kemitchell avatar shinnn avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.