Socket
Socket
Sign inDemoInstall

spdx-expression-parse

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    spdx-expression-parse

parse SPDX license expressions


Version published
Maintainers
1
Install size
42.8 kB
Created

Package description

What is spdx-expression-parse?

The spdx-expression-parse npm package is designed to parse SPDX license expressions. SPDX (Software Package Data Exchange) is a standard format for communicating the licensing information of software packages. This package helps in parsing and validating the syntax of SPDX expressions, making it easier to handle complex licensing scenarios programmatically.

What are spdx-expression-parse's main functionalities?

Parsing SPDX expressions

This feature allows the parsing of SPDX license expressions into a structured format. The code sample demonstrates how to parse a simple SPDX expression that includes an OR operator, indicating dual licensing options.

const parse = require('spdx-expression-parse');
const expression = 'MIT OR Apache-2.0';
const parsedExpression = parse(expression);
console.log(parsedExpression);

Handling complex SPDX expressions

This feature supports the parsing of more complex SPDX expressions, including nested groups and exceptions. The code sample shows how to parse an expression that combines multiple licenses with logical AND and an exception clause.

const parse = require('spdx-expression-parse');
const complexExpression = '(MIT OR Apache-2.0) AND (GPL-2.0+ WITH Classpath-exception-2.0)';
const parsedComplexExpression = parse(complexExpression);
console.log(parsedComplexExpression);

Other packages similar to spdx-expression-parse

Readme

Source
var parse = require('spdx-expression-parse')
var assert = require('assert')

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

// We handle all the bare SPDX license and exception ids as well.
require('spdx-license-ids').forEach(function (id) {
  assert.deepEqual(parse(id), {license: id})
  require('spdx-exceptions').forEach(function (e) {
    assert.deepEqual(
      parse(id + ' WITH ' + e),
      {license: id, exception: e}
    )
  })
})

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.

Keywords

FAQs

Last updated on 26 Aug 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc