UNPKG

@naturalcycles/nodejs-lib

Version:
26 lines 746 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const stream_1 = require("stream"); /** * Like `transformMap`, but lightweight, no concurrency, etc. * Inspired by `through2` */ function transformThrough(mapper, opt = {}) { let index = 0; return new stream_1.Transform({ objectMode: true, ...opt, async transform(chunk, _encoding, cb) { try { const res = await mapper(chunk, index++); cb(null, res); } catch (err) { console.error(err); // to be sure cb(err); } }, }); } exports.transformThrough = transformThrough; //# sourceMappingURL=transformThrough.js.map