diff --git a/index.js b/index.js index 610a4a3..773ff9c 100644 --- a/index.js +++ b/index.js @@ -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); @@ -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){ @@ -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; diff --git a/package.json b/package.json index 1d4d0e0..16f69f3 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test.js b/test.js index 8275c7b..e8e783e 100644 --- a/test.js +++ b/test.js @@ -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(); +});