clean up eachLine

This commit is contained in:
Sami Samhuri 2011-05-13 21:26:18 -07:00
parent b0b9f0ba56
commit 2f825bf1fd

View file

@ -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) {