spdx-vir
v1.0.0
Published
Easy SPDX parsing.
Readme
spdx-vir
Parses and validates license strings strictly according to the SPDX grammar: https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions.
License ids have been extracted from https://spdx.org/licenses/licenses.json and exceptions from https://spdx.org/licenses/exceptions.json.
Based on https://www.npmjs.com/package/spdx-expression-parse but more strict to the grammar and written in modern ESM syntax.
Test it out here: https://codepen.io/electrovir/pen/yyVjVQR
Install
npm i spdx-virUsage
Validating expressions:
import {isValidSpdxExpression} from 'spdx-vir';
// returns true
isValidSpdxExpression('(MIT OR CC0-1.0)');
// returns false
isValidSpdxExpression('(MIT or CC0 1.0)');Parsing expressions:
import {parseSpdxExpression, SpdxConjunction} from 'spdx-vir';
parseSpdxExpression('(MIT OR CC0-1.0)');
// outputs the following:
const output = {
conjunction: SpdxConjunction.OR,
left: {
license: 'MIT',
},
right: {
license: 'CC0-1.0',
},
};
// throws a SpdxParseError
parseSpdxExpression('(MIT or CC0 1.0)');