The `spdx-satisfies` library provides a robust utility for programmatically validating whether a given SPDX license expression is satisfied by a predefined list of approved licenses. Currently at version 6.0.0, this package is a direct successor to the deprecated `spdx.js` and focuses specifically on accurate satisfaction checks against the SPDX specification. It supports complex license expressions involving `OR` and `WITH` operators for the license expression being checked, but strictly requires that the 'approved licenses' list contains only simple identifiers, plus-ranges (e.g., `GPL-2.0+`), or licenses with exceptions (e.g., `Apache-2.0 WITH LLVM`), prohibiting compound expressions in the approved list. This strictness makes it a critical tool for open-source license compliance, software supply chain security, and automated dependency scanning, offering precise and machine-readable license verification.
npm install spdx-satisfiesVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use the `satisfies` function with various SPDX expressions and an array of approved licenses, including basic, OR, AND, plus-ranges, and WITH clauses.
Ensure your `approvedLicenses` array contains only simple, atomic license identifiers, not compound SPDX expressions. If you need to check for a compound approved license, you might need to split it or handle it externally.
Refer to the official SPDX specification (currently 3.0) for updated syntax and best practices. Use tools like `spdx-correct` for validating expression syntax if parsing issues arise.
Always use `import satisfies from 'spdx-satisfies';` for ESM contexts and `const satisfies = require('spdx-satisfies');` for CommonJS. Avoid named imports `{ satisfies }` as it is a default export.Change `import { satisfies } from 'spdx-satisfies';` to `import satisfies from 'spdx-satisfies';`Run `npm install spdx-satisfies` or `yarn add spdx-satisfies`. If using ESM, ensure your `package.json` has `"type": "module"` or that import paths are correctly specified (e.g., with `.js` extension if explicit).
Review the `approvedLicenses` array; it should only contain simple license identifiers (e.g., `['MIT', 'GPL-2.0']`). Also, validate the `spdxExpression` string for correct SPDX syntax.
No dependency data recorded yet.