Skip to content

Commit 9760a09

Browse files
committed
always return arrays when fed arrays
1 parent 2d26324 commit 9760a09

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ var backslash = code('\\');
3131
*/
3232

3333
function extract(buf, keys){
34-
if (!Array.isArray(keys)) keys = [keys];
34+
var multi = Array.isArray(keys);
35+
if (!multi) keys = [keys];
3536

3637
var values = [];
3738
var matched = {};
@@ -86,9 +87,9 @@ function extract(buf, keys){
8687
if (values.length == keys.length) break;
8788
}
8889

89-
return keys.length == 1
90-
? values[0]
91-
: values;
90+
return multi
91+
? values
92+
: values[0];
9293
}
9394

9495
/**

test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ describe('extract(buf, key)', function(){
1212
var buf = toBuf({ a: '0', b: '1', c: '2' });
1313
equal(extract(buf, ['a', 'c']), ['0', '2']);
1414
})
15+
it('should always return arrays when fed arrays', function(){
16+
var buf = toBuf({ foo: 'bar' });
17+
equal(extract(buf, ['foo']), ['bar']);
18+
})
1519
it('should end on ,', function(){
1620
var buf = toBuf({ foo: 'bar', bar: 'baz' });
1721
equal(extract(buf, 'foo'), 'bar');

0 commit comments

Comments
 (0)