3 examples of 'license should be a valid spdx license expression' in JavaScript

Every line of 'license should be a valid spdx license expression' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
65function _getSpdxLicenseInformation(license) {
66 var licenses = [];
67 try {
68 var tree;
69 if (typeof license === "string") {
70 tree = spdxParse(license);
71 } else {
72 tree = license;
73 }
74 if (tree.license) {
75 licenses.push(tree.license);
76 }
77 if (tree.left) {
78 licenses = licenses.concat(_getSpdxLicenseInformation(tree.left));
79 }
80 if (tree.right) {
81 licenses = licenses.concat(_getSpdxLicenseInformation(tree.right));
82 }
83 } catch(e) {
84 console.warn(`WARNING: Unable to parse license "${license}"`);
85 }
86 return licenses;
87}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

140function passesSpdx(license, accepted) {
141 try {
142 return spdxSatisfies(license, `(${accepted.join(' OR ')})`)
143 } catch (_) {
144 return false;
145 }
146}
48function normalizeLicense(name, license) {
49 // Handle { type: 'MIT', url: 'http://..' }
50 if (license && license.type) {
51 license = license.type;
52 }
53
54 // Ensure that the license is a non-empty string
55 // Note that `spdx-correct` throws on strings with empty chars, so we must use trim()
56 // e.g.: webjs-cli
57 if (typeof license !== 'string' || !license.trim()) {
58 log.warn({ license }, `Invalid license for package ${name} was found`);
59
60 return null;
61 }
62
63 // Try to correct licenses that are not valid SPDX identifiers
64 if (!spdx.valid(license)) {
65 const correctedLicense = spdxCorrect(license);
66
67 if (correctedLicense) {
68 log.debug(`Package ${name} license was corrected from ${license} to ${correctedLicense}`);
69 license = correctedLicense;
70 } else {
71 log.warn({ license }, `License for package ${name} is not a valid SPDX indentifier`);
72 license = null;
73 }
74 }
75
76 return license;
77}

Related snippets