Skip to content

Commit

Permalink
refactor: Extract a small functionality into a helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Seidelsohn committed May 12, 2023
1 parent 806bc46 commit 713f680
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,7 @@ exports.asMarkDown = (sorted, customFormat) => {
exports.asPlainVertical = (sorted) =>
Object.entries(sorted)
.map(([moduleName, moduleData]) => {
let licenseText =
moduleName.substring(0, moduleName.lastIndexOf('@')) +
' ' +
moduleName.substring(moduleName.lastIndexOf('@') + 1) +
'\n';
let licenseText = helpers.getModuleNameForLicenseTextHeader(moduleName);

if (Array.isArray(moduleData.licenses) && moduleData.licenses.length > 0) {
licenseText += moduleData.licenses.map((moduleLicense) => {
Expand Down
7 changes: 7 additions & 0 deletions lib/indexHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,20 @@ const getCsvHeaders = (customFormat, csvComponentPrefix) => {
return entriesArr.join(',');
};

const getModuleNameForLicenseTextHeader = (moduleName = '') => {
const lastIndexOfAtCharacter = moduleName.lastIndexOf('@');

return `${moduleName.substring(0, lastIndexOfAtCharacter)} ${moduleName.substring(lastIndexOfAtCharacter + 1)}\n`;
};

module.exports = {
deleteNonDirectDependenciesFromAllDependencies,
getAuthorDetails,
getCsvData,
getCsvHeaders,
getFirstNotUndefinedOrUndefined,
getLinesWithCopyright,
getModuleNameForLicenseTextHeader,
getOptionArray,
getRepositoryUrl,
};

0 comments on commit 713f680

Please sign in to comment.