Skip to content

Commit

Permalink
Finalize the customFormat (markdown)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Tusch committed Jul 28, 2015
1 parent 8102091 commit 911fc1c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bin/license-checker
Expand Up @@ -30,7 +30,7 @@ console.log(args.customFormat);
} else if (args.csv) {
formattedOutput = checker.asCSV(json, args.customFormat);
} else if (args.markdown){
formattedOutput = checker.asMarkDown(json);
formattedOutput = checker.asMarkDown(json, args.customFormat);
} else {
formattedOutput = checker.asTree(json);
}
Expand Down
39 changes: 33 additions & 6 deletions lib/index.js
Expand Up @@ -209,13 +209,40 @@ exports.asCSV = function(sorted, customFormat) {
return text.join('\n');
};

exports.asMarkDown = function(sorted) {
/**
* Exports data as markdown (*.md) file which has it's own syntax.
* @method
* @param {JSON} sorted The sorted JSON data from all packages.
* @param {JSON} customFormat The custom format with information about the needed keys.
* @return {String} The returning plain text.
*/
exports.asMarkDown = function(sorted, customFormat) {

var text = [];
Object.keys(sorted).forEach(function(key) {
var module = sorted[key];
text.push('[' + key + '](' + module.repository + ') - ' + module.licenses);
});
return text.join('\n');
if (Object.keys(customFormat).length > 0) {

Object.keys(sorted).forEach(function sortedCallback(sortedItem) {

text.push(' - **[' + sortedItem + '](' + sorted[sortedItem].repository + ')**');
Object.keys(customFormat).forEach(function customCallback(customItem) {

text.push(' - ' + customItem + ': ' + sorted[sortedItem][customItem]);
});
});

text = text.join('\n');
} else {

Object.keys(sorted).forEach(function(key) {

var module = sorted[key];
text.push('[' + key + '](' + module.repository + ') - ' + module.licenses);
});

text = text.join('\n');
}

return text;
};

exports.parseJson = function(jsonPath) {
Expand Down

0 comments on commit 911fc1c

Please sign in to comment.