Skip to content

Commit

Permalink
added tests and refactored the code a little
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Jul 7, 2014
1 parent 275f276 commit b8c5815
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
38 changes: 13 additions & 25 deletions lib/index.js
Expand Up @@ -22,6 +22,7 @@ var flatten = function(json) {
if (json.repository) {
if (typeof json.repository === 'object' && typeof json.repository.url === 'string') {
moduleInfo.repository = json.repository.url.replace('git://github.com', 'https://github.com').replace('.git', '');
moduleInfo.repository = json.repository.url.replace('git@github.com:', 'https://github.com/').replace('.git', '');
}
}
if (json.url) {
Expand Down Expand Up @@ -103,29 +104,16 @@ exports.print = function(sorted) {
};

exports.asCSV = function(sorted) {
var text = '"module name","license","repository"\n',
key, module;

for(key in sorted) {
if (sorted.hasOwnProperty(key)) {
module = sorted[key];
text += '"' + key + '",';
if (module.hasOwnProperty('licenses')) {
text += '"' + module.licenses + '"';
}
else {
text += '""';
}
text += ',';
if (module.hasOwnProperty('repository')) {
text += '"' + module.repository + '"';
}
else {
text += '""';
}
text += '\n';
}
}
var text = [['"module name"','"license"','"repository"'].join(',')];
Object.keys(sorted).forEach(function(key) {
var module = sorted[key],
line = [
'"' + key + '"',
'"' + (module.licenses || '') + '"',
'"' + (module.repository || '') + '"'
].join(',');
text.push(line);
});

return text;
};
return text.join('\n');
};
5 changes: 5 additions & 0 deletions tests/test.js
Expand Up @@ -29,6 +29,11 @@ var tests = {
assert.isTrue(Object.keys(d).length > 70);
assert.equal(d['abbrev@1.0.5'].licenses, 'MIT');
},
'and convert to CSV': function(d) {
var str = checker.asCSV(d);
assert.equal('"module name","license","repository"', str.split('\n')[0]);
assert.equal('"abbrev@1.0.5","MIT","http://github.com/isaacs/abbrev-js"', str.split('\n')[1]);
},
'should parse local without unknown': {
topic: function () {
var self = this;
Expand Down

0 comments on commit b8c5815

Please sign in to comment.