Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
license.js28 linesDownload Raw Back to lib
1// This is an implementation of the validForNewPackage flag in validate-npm-package-license, which is no longer maintained
2
3const parse = require('spdx-expression-parse')
4
5function usesLicenseRef (ast) {
6  if (Object.hasOwn(ast, 'license')) {
7    return ast.license.startsWith('LicenseRef') || ast.license.startsWith('DocumentRef')
8  } else {
9    return usesLicenseRef(ast.left) || usesLicenseRef(ast.right)
10  }
11}
12
13// license should be a valid SPDX license expression (without "LicenseRef"), "UNLICENSED", or "SEE LICENSE IN <filename>"
14module.exports = function licenseValidForNewPackage (argument) {
15  if (argument === 'UNLICENSED' || argument === 'UNLICENCED') {
16    return true
17  }
18  if (/^SEE LICEN[CS]E IN ./.test(argument)) {
19    return true
20  }
21  try {
22    const ast = parse(argument)
23    return !usesLicenseRef(ast)
24  } catch {
25    return false
26  }
27}
28 
codekingpro/portable-devtools · Team Ai