Files: 4030fd72088498cc22acca950c4a1bb121937cc0 / throughs / map.js
455 bytesRaw
1 | |
2 | |
3 | var prop = require('../util/prop') |
4 | |
5 | module.exports = function map (mapper) { |
6 | if(!mapper) return id |
7 | mapper = prop(mapper) |
8 | return function (read) { |
9 | return function (abort, cb) { |
10 | read(abort, function (end, data) { |
11 | try { |
12 | data = !end ? mapper(data) : null |
13 | } catch (err) { |
14 | return read(err, function () { |
15 | return cb(err) |
16 | }) |
17 | } |
18 | cb(end, data) |
19 | }) |
20 | } |
21 | } |
22 | } |
23 |
Built with git-ssb-web