"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/validate-npm-package-license/index.js" (8 Mar 2017, 1863 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var parse = require('spdx-expression-parse');
    2 var correct = require('spdx-correct');
    3 
    4 var genericWarning = (
    5   'license should be ' +
    6   'a valid SPDX license expression (without "LicenseRef"), ' +
    7   '"UNLICENSED", or ' +
    8   '"SEE LICENSE IN <filename>"'
    9 );
   10 
   11 var fileReferenceRE = /^SEE LICEN[CS]E IN (.+)$/;
   12 
   13 function startsWith(prefix, string) {
   14   return string.slice(0, prefix.length) === prefix;
   15 }
   16 
   17 function usesLicenseRef(ast) {
   18   if (ast.hasOwnProperty('license')) {
   19     var license = ast.license;
   20     return (
   21       startsWith('LicenseRef', license) ||
   22       startsWith('DocumentRef', license)
   23     );
   24   } else {
   25     return (
   26       usesLicenseRef(ast.left) ||
   27       usesLicenseRef(ast.right)
   28     );
   29   }
   30 }
   31 
   32 module.exports = function(argument) {
   33   var ast;
   34 
   35   try {
   36     ast = parse(argument);
   37   } catch (e) {
   38     var match
   39     if (
   40       argument === 'UNLICENSED' ||
   41       argument === 'UNLICENCED'
   42     ) {
   43       return {
   44         validForOldPackages: true,
   45         validForNewPackages: true,
   46         unlicensed: true
   47       };
   48     } else if (match = fileReferenceRE.exec(argument)) {
   49       return {
   50         validForOldPackages: true,
   51         validForNewPackages: true,
   52         inFile: match[1]
   53       };
   54     } else {
   55       var result = {
   56         validForOldPackages: false,
   57         validForNewPackages: false,
   58         warnings: [genericWarning]
   59       };
   60       var corrected = correct(argument);
   61       if (corrected) {
   62         result.warnings.push(
   63           'license is similar to the valid expression "' + corrected + '"'
   64         );
   65       }
   66       return result;
   67     }
   68   }
   69 
   70   if (usesLicenseRef(ast)) {
   71     return {
   72       validForNewPackages: false,
   73       validForOldPackages: false,
   74       spdx: true,
   75       warnings: [genericWarning]
   76     };
   77   } else {
   78     return {
   79       validForNewPackages: true,
   80       validForOldPackages: true,
   81       spdx: true
   82     };
   83   }
   84 };