You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
"use strict"; |
|
|
|
module.exports = make |
|
module.exports.ctor = ctor |
|
module.exports.objCtor = objCtor |
|
module.exports.obj = obj |
|
|
|
var through2 = require("through2") |
|
var xtend = require("xtend") |
|
|
|
function ctor(options, fn) { |
|
if (typeof options == "function") { |
|
fn = options |
|
options = {} |
|
} |
|
|
|
var Filter = through2.ctor(options, function (chunk, encoding, callback) { |
|
if (this.options.wantStrings) chunk = chunk.toString() |
|
try { |
|
if (fn.call(this, chunk, this._index++)) this.push(chunk) |
|
return callback() |
|
} catch (e) { |
|
return callback(e) |
|
} |
|
}) |
|
Filter.prototype._index = 0 |
|
return Filter |
|
} |
|
|
|
function objCtor(options, fn) { |
|
if (typeof options === "function") { |
|
fn = options |
|
options = {} |
|
} |
|
options = xtend({objectMode: true, highWaterMark: 16}, options) |
|
return ctor(options, fn) |
|
} |
|
|
|
function make(options, fn) { |
|
return ctor(options, fn)() |
|
} |
|
|
|
function obj(options, fn) { |
|
if (typeof options === "function") { |
|
fn = options |
|
options = {} |
|
} |
|
options = xtend({objectMode: true, highWaterMark: 16}, options) |
|
return make(options, fn) |
|
}
|
|
|