function hasValidLicense()

in src/check-license.js [181:203]


function hasValidLicense (pkg) {
    let isValid = false;

    if (pkg.licenses.length === 0) { return isValid; } else {
        // go through each license of the package
        for (let x = 0; x < pkg.licenses.length; ++x) {
            isValid = false;

            // go through valid licenses and try to match with package license
            for (let y = 0; y < validLicenses.length; ++y) {
                const pattern = new RegExp(validLicenses[y], 'gi'); // construct regular expression from valid license
                if ((pkg.licenses[x].license).match(pattern)) { // match it against the package license
                    isValid = true;
                }
            }

            // shortcut - if one license isn't valid then go ahead and flag it
            if (isValid === false) { break; }
        }
    }

    return isValid;
}