UNPKG

484 BJavaScriptView Raw
1'use strict'
2
3function id (e) { return e }
4var prop = require('../util/prop')
5
6module.exports = function map (mapper) {
7 if(!mapper) return id
8 mapper = prop(mapper)
9 return function (read) {
10 return function (abort, cb) {
11 read(abort, function (end, data) {
12 try {
13 data = !end ? mapper(data) : null
14 } catch (err) {
15 return read(err, function () {
16 return cb(err)
17 })
18 }
19 cb(end, data)
20 })
21 }
22 }
23}