Files
strom/src/functions/map.ts
Jerry Kurian a11aa10d16 Clean up
2019-09-26 09:23:09 -04:00

14 lines
381 B
TypeScript

import { Transform, TransformOptions } from "stream";
export function map<T, R>(
mapper: (chunk: T, encoding: string) => R,
options: TransformOptions = { objectMode: true },
): Transform {
return new Transform({
...options,
async transform(chunk: T, encoding, callback) {
callback(null, await mapper(chunk, encoding));
},
});
}