Skip to content

Commit

Permalink
refactor: Make code a bit safer
Browse files Browse the repository at this point in the history
  • Loading branch information
RSeidelsohn committed Apr 12, 2023
1 parent 369f1d4 commit 13c7656
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,21 @@ const recursivelyCollectAllDependencies = (options) => {
if (Array.isArray(licenseData) && licenseData.length > 0) {
moduleInfo.licenses = licenseData.map((moduleLicense) => {
/*istanbul ignore else*/
if (typeof moduleLicense === 'object') {
if (
typeof helpers.getFirstNotUndefinedOrUndefined(moduleLicense.type, moduleLicense.name) === 'string'
) {
/*istanbul ignore next*/
return moduleLicense.type || moduleLicense.name;
return helpers.getFirstNotUndefinedOrUndefined(moduleLicense.type, moduleLicense.name);
}

if (typeof moduleLicense === 'string') {
return moduleLicense;
}
});
} else if (typeof licenseData === 'object' && (licenseData.type || licenseData.name)) {
moduleInfo.licenses = getLicenseTitle(licenseData.type || licenseData.name);
} else if (typeof helpers.getFirstNotUndefinedOrUndefined(licenseData.type, licenseData.name) === 'string') {
moduleInfo.licenses = getLicenseTitle(
helpers.getFirstNotUndefinedOrUndefined(licenseData.type, licenseData.name),
);
} else if (typeof licenseData === 'string') {
moduleInfo.licenses = getLicenseTitle(licenseData);
}
Expand Down

0 comments on commit 13c7656

Please sign in to comment.