Skip to content

Commit

Permalink
rename and export parse_dep_string (#9)
Browse files Browse the repository at this point in the history
rename and export parse_dep_string
  • Loading branch information
gaborcsardi authored Nov 25, 2019
2 parents 4a3967e + f10007b commit 10cc9e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function parse_desc_stream(descstream, callback) {
return callback('Invalid record: ' + rec.value);
}
if (deps.indexOf(rec.key) > -1) {
rec.value = parse_dep(rec.value);
rec.value = parse_dep_string(rec.value);
}
if (rec.key == 'Remotes') {
rec.value = parse_remotes(rec.value);
Expand All @@ -62,7 +62,7 @@ function parse_desc_stream(descstream, callback) {
descstream.on('end', finisher);
}

function parse_dep(str) {
function parse_dep_string(str) {
return str.split(/,[\s]*/s).filter(function(str){
return str.trim(); //filter out empty strings
}).map(function(str){
Expand Down Expand Up @@ -187,5 +187,6 @@ parse_desc_stream.parse_tar_file = parse_tar_file;
parse_desc_stream.parse_tar_stream = parse_tar_stream;
parse_desc_stream.parse_zip_file = parse_zip_file;
parse_desc_stream.parse_zip_stream = parse_zip_stream;
parse_desc_stream.parse_dep_string = parse_dep_string;

module.exports = parse_desc_stream;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rdesc-parser",
"version": "3.0.0",
"version": "3.0.1",
"description": "Parser for R package DESCRIPTION files.",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,10 @@ test.cb('parse_file, zip file', function(t) {
t.end();
});
});

test.cb('parse dependency string', function(t){
var deps = desc.parse_dep_string("foo (>= 1.2.3), bar");
t.deepEqual(deps[0], {package:'foo', version: '>= 1.2.3'});
t.deepEqual(deps[1], {package:'bar'});
t.end();
});

0 comments on commit 10cc9e6

Please sign in to comment.