diff --git a/lib/file-ext.js b/lib/file-ext.js index dbda660..3f1bda3 100644 --- a/lib/file-ext.js +++ b/lib/file-ext.js @@ -19,18 +19,21 @@ exports.extend = function(obj) { var FileExt = exports.FileExt = { - eachLine: function(f, options) { - if (typeof options === 'function') options = {line: options, end: arguments[2]}; - var lineType = typeof options.line - , endType = typeof options.end - ; - if (lineType !== 'function' && endType !== 'function') - throw new Error('bad arguments'); + eachLine: function(f, optionsOrLineFn, endFn) { + var lineFn, hasLineFn, hasEndFn; + if (typeof optionsOrLineFn === 'object') { + lineFn = optionsOrLineFn.line; + endFn = optionsOrLineFn.end; + } + else if (typeof optionsOrLineFn === 'function') { + lineFn = optionsOrLineFn; + } + hasLineFn = typeof lineFn == 'function'; + hasEndFn = typeof endFn == 'function'; + if (!hasLineFn && !hasEndFn) throw new Error('bad arguments'); var le = new LineEmitter(f); - if (typeof options.line === 'function') - le.on('line', function(line) { options.line(line); }); - if (typeof options.end === 'function') - le.on('end', function() { options.end(); }); + if (hasLineFn) le.on('line', lineFn); + if (hasEndFn) le.on('end', endFn); } , exists: function(f) {