-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
49 lines (42 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"use strict";
module.exports = make
module.exports.ctor = ctor
module.exports.objCtor = objCtor
module.exports.obj = obj
const through2 = require("through2")
function ctor(options, fn) {
if (typeof options == "function") {
fn = options
options = {}
}
var Map = through2.ctor(options, function (chunk, encoding, callback) {
if (this.options.wantStrings) chunk = chunk.toString()
try {
this.push(fn.call(this, chunk, this._index++))
return callback()
} catch (e) {
return callback(e)
}
})
Map.prototype._index = 0
return Map
}
function make(options, fn) {
return ctor(options, fn)()
}
function objCtor(options, fn) {
if (typeof options === "function") {
fn = options
options = {}
}
options = Object.assign({objectMode: true, highWaterMark: 16}, options)
return ctor(options, fn)
}
function obj(options, fn) {
if (typeof options === "function") {
fn = options
options = {}
}
options = Object.assign({objectMode: true, highWaterMark: 16}, options)
return make(options, fn)
}