mirror of
https://github.com/samsonjs/batteries.git
synced 2026-03-31 10:15:45 +00:00
clean up eachLine
This commit is contained in:
parent
b0b9f0ba56
commit
2f825bf1fd
1 changed files with 14 additions and 11 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue