mirror of
https://github.com/samsonjs/batteries.git
synced 2026-04-27 15:07:42 +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 = {
|
var FileExt = exports.FileExt = {
|
||||||
|
|
||||||
eachLine: function(f, options) {
|
eachLine: function(f, optionsOrLineFn, endFn) {
|
||||||
if (typeof options === 'function') options = {line: options, end: arguments[2]};
|
var lineFn, hasLineFn, hasEndFn;
|
||||||
var lineType = typeof options.line
|
if (typeof optionsOrLineFn === 'object') {
|
||||||
, endType = typeof options.end
|
lineFn = optionsOrLineFn.line;
|
||||||
;
|
endFn = optionsOrLineFn.end;
|
||||||
if (lineType !== 'function' && endType !== 'function')
|
}
|
||||||
throw new Error('bad arguments');
|
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);
|
var le = new LineEmitter(f);
|
||||||
if (typeof options.line === 'function')
|
if (hasLineFn) le.on('line', lineFn);
|
||||||
le.on('line', function(line) { options.line(line); });
|
if (hasEndFn) le.on('end', endFn);
|
||||||
if (typeof options.end === 'function')
|
|
||||||
le.on('end', function() { options.end(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
, exists: function(f) {
|
, exists: function(f) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue